Merge pull request #133 from twofas/bugfix/TF-1622

[TF-1622] Unread button is still visible after read news
This commit is contained in:
gmachnio 2024-08-12 15:39:18 +02:00 committed by GitHub
commit efd7f232ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 25 deletions

View File

@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "Ellipse 10.pdf",
"filename" : "badge.pdf",
"idiom" : "universal"
}
],

View File

@ -12,11 +12,11 @@ stream
q
1.000000 0.000000 -0.000000 1.000000 0.000000 0.000000 cm
0.929412 0.109804 0.141176 scn
3.000000 1.500000 m
3.000000 0.671573 2.328427 0.000000 1.500000 0.000000 c
0.671573 0.000000 0.000000 0.671573 0.000000 1.500000 c
0.000000 2.328427 0.671573 3.000000 1.500000 3.000000 c
2.328427 3.000000 3.000000 2.328427 3.000000 1.500000 c
8.000000 4.000000 m
8.000000 1.790861 6.209139 0.000000 4.000000 0.000000 c
1.790861 0.000000 0.000000 1.790861 0.000000 4.000000 c
0.000000 6.209139 1.790861 8.000000 4.000000 8.000000 c
6.209139 8.000000 8.000000 6.209139 8.000000 4.000000 c
h
f
n
@ -32,7 +32,7 @@ endobj
4 0 obj
<< /Annots []
/Type /Page
/MediaBox [ 0.000000 0.000000 3.000000 3.000000 ]
/MediaBox [ 0.000000 0.000000 8.000000 8.000000 ]
/Resources 1 0 R
/Contents 2 0 R
/Parent 5 0 R

View File

@ -600,11 +600,11 @@ private extension TokensPresenter {
func updateNewsIcon() {
updateNaviIcons()
interactor.fetchNews { [weak self] in
self?.updateNaviIcons(hasUnreadNews: self?.hasUnreadNews ?? false)
self?.updateNaviIcons()
}
}
private func updateNaviIcons(hasUnreadNews: Bool = false) {
private func updateNaviIcons() {
if interactor.hasServices {
view?.updateNaviIcons(
using: mapButtonStateFor(currentState, isFirst: false),

View File

@ -129,20 +129,24 @@ extension TokensViewController: TokensViewControlling {
// MARK: - Navibar icons
func updateNaviIcons(using state: TokensViewControllerAddState, hasUnreadNews: Bool) {
func createNewsButton() -> UIBarButtonItem {
if presenter.hasUnreadNews {
if hasUnreadNews {
let naviButton = UnreadNewsNaviButton()
naviButton.translatesAutoresizingMaskIntoConstraints = false
naviButton.accessibilityLabel = T.Commons.notifications
naviButton.addTarget(self, action: #selector(showNotifications), for: .touchUpInside)
naviButton.animate()
return UIBarButtonItem(customView: naviButton)
let uiBarButtonItem = UIBarButtonItem(customView: naviButton)
newsButton = .unread(uiBarButtonItem)
return uiBarButtonItem
} else {
let naviButton = UIButton(type: .custom)
naviButton.setBackgroundImage(Asset.navibarNewsIcon.image, for: .normal)
naviButton.addTarget(self, action: #selector(showNotifications), for: .touchUpInside)
naviButton.translatesAutoresizingMaskIntoConstraints = false
naviButton.accessibilityLabel = T.Commons.notifications
return UIBarButtonItem(customView: naviButton)
let uiBarButtonItem = UIBarButtonItem(customView: naviButton)
newsButton = .read(uiBarButtonItem)
return uiBarButtonItem
}
}
@ -159,31 +163,59 @@ extension TokensViewController: TokensViewControlling {
switch state {
case .firstTime:
if let newsButton, hasUnreadNews {
switch (hasUnreadNews, newsButton) {
case (true, .unread(let unreadNewsButton)):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAddFirst.image),
newsButton
unreadNewsButton
]
} else {
let newsButton = createNewsButton()
self.newsButton = newsButton
case (false, .unread):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAddFirst.image),
newsButton
createNewsButton()
]
case (true, .read):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAddFirst.image),
createNewsButton()
]
case (false, .read(let readNewsButton)):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAddFirst.image),
readNewsButton
]
case (_, .none):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAddFirst.image),
createNewsButton()
]
}
case .normal:
if let newsButton, !hasUnreadNews {
switch (hasUnreadNews, newsButton) {
case (true, .unread(let unreadNewsButton)):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAdd.image),
newsButton
unreadNewsButton
]
} else {
let newsButton = createNewsButton()
self.newsButton = newsButton
case (false, .unread):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAdd.image),
newsButton
createNewsButton()
]
case (true, .read):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAdd.image),
createNewsButton()
]
case (false, .read(let readNewsButton)):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAdd.image),
readNewsButton
]
case (_, .none):
navigationItem.rightBarButtonItems = [
createAddButton(image: Asset.naviIconAdd.image),
createNewsButton()
]
}
case .none:

View File

@ -22,11 +22,16 @@ import Common
import Data
final class TokensViewController: UIViewController {
enum NewsButtonType {
case unread(UIBarButtonItem)
case read(UIBarButtonItem)
}
var presenter: TokensPresenter!
var addButton: UIBarButtonItem? {
navigationItem.rightBarButtonItem
}
var newsButton: UIBarButtonItem?
var newsButton: NewsButtonType?
private(set) var tokensView: TokensView!
private(set) var dataSource: UICollectionViewDiffableDataSource<TokensSection, TokenCell>!