From 459a6a7148d8bd456b33b388ab3204b9e5cb8e22 Mon Sep 17 00:00:00 2001 From: gmc Date: Thu, 8 Aug 2024 01:59:31 +0200 Subject: [PATCH] [TF-1622] fix --- .../Badge.imageset/Contents.json | 2 +- .../{Ellipse 10.pdf => badge.pdf} | 12 ++-- .../Tokens/Presenter/TokensPresenter.swift | 4 +- ...ViewController+TokensViewControlling.swift | 62 ++++++++++++++----- .../Tokens/View/TokensViewController.swift | 7 ++- 5 files changed, 62 insertions(+), 25 deletions(-) rename TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/{Ellipse 10.pdf => badge.pdf} (70%) diff --git a/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Contents.json b/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Contents.json index b2f50124..9f308325 100644 --- a/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Contents.json +++ b/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "Ellipse 10.pdf", + "filename" : "badge.pdf", "idiom" : "universal" } ], diff --git a/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Ellipse 10.pdf b/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/badge.pdf similarity index 70% rename from TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Ellipse 10.pdf rename to TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/badge.pdf index 758b5af2..7ffd5b63 100644 --- a/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/Ellipse 10.pdf +++ b/TwoFAS/TwoFAS/Other/Assets.xcassets/Badge.imageset/badge.pdf @@ -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 diff --git a/TwoFAS/TwoFAS/Root/Modules/Tokens/Presenter/TokensPresenter.swift b/TwoFAS/TwoFAS/Root/Modules/Tokens/Presenter/TokensPresenter.swift index 6086eede..c3265396 100644 --- a/TwoFAS/TwoFAS/Root/Modules/Tokens/Presenter/TokensPresenter.swift +++ b/TwoFAS/TwoFAS/Root/Modules/Tokens/Presenter/TokensPresenter.swift @@ -597,11 +597,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), diff --git a/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController+TokensViewControlling.swift b/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController+TokensViewControlling.swift index 78df38ae..602ff085 100644 --- a/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController+TokensViewControlling.swift +++ b/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController+TokensViewControlling.swift @@ -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: diff --git a/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController.swift b/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController.swift index 02f4bc1f..a5216345 100644 --- a/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController.swift +++ b/TwoFAS/TwoFAS/Root/Modules/Tokens/View/TokensViewController.swift @@ -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!