Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add badge in spaces button (PSG-944) #7088

Merged
merged 8 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions Riot/Modules/Home/AllChats/AllChatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class AllChatsViewController: HomeViewController {
private var isOnboardingCoordinatorPreparing: Bool = false

private var allChatsOnboardingCoordinatorBridgePresenter: AllChatsOnboardingCoordinatorBridgePresenter?

private var theme: Theme {
ThemeService.shared().theme
}

@IBOutlet private var toolbar: UIToolbar!
private var isToolbarHidden: Bool = false {
Expand Down Expand Up @@ -137,12 +141,13 @@ class AllChatsViewController: HomeViewController {
searchController.delegate = self

NotificationCenter.default.addObserver(self, selector: #selector(self.setupEditOptions), name: AllChatsLayoutSettingsManager.didUpdateSettings, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.updateBadgeButton), name: MXSpaceNotificationCounter.didUpdateNotificationCount, object: nil)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.toolbar.tintColor = ThemeService.shared().theme.colors.accent
self.toolbar.tintColor = theme.colors.accent
if self.navigationItem.searchController == nil {
self.navigationItem.searchController = searchController
}
Expand Down Expand Up @@ -460,7 +465,7 @@ class AllChatsViewController: HomeViewController {
return
}

self.update(with: ThemeService.shared().theme)
self.update(with: theme)
}

private func update(with theme: Theme) {
Expand Down Expand Up @@ -500,22 +505,40 @@ class AllChatsViewController: HomeViewController {
self?.updateToolbar(with: menu)
}))
updateEmptyView()
updateBadgeButton()
}

private func updateRightNavigationItem(with menu: UIMenu) {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "ellipsis.circle"), menu: menu)
}

private lazy var spacesButton: BadgedBarButtonItem = {
let innerButton = UIButton(type: .system)
innerButton.accessibilityLabel = VectorL10n.spaceSelectorTitle
innerButton.addTarget(self, action: #selector(self.showSpaceSelectorAction(sender:)), for: .touchUpInside)
innerButton.setImage(Asset.Images.allChatsSpacesIcon.image, for: .normal)
return BadgedBarButtonItem(withBaseButton: innerButton, theme: theme)
}()

@objc private func updateBadgeButton() {
guard isViewLoaded else {
return
}

let notificationState = mainSession?.spaceService.notificationCounter.notificationState(forAllSpacesExcept: nil)
spacesButton.badgeText = notificationState.map { "\($0.allCount)" }
spacesButton.badgeBackgroundColor = notificationState.map {
$0.allHighlightCount > 0 ? theme.noticeColor : theme.noticeSecondaryColor
} ?? .clear
}

private func updateToolbar(with menu: UIMenu) {
guard isViewLoaded else {
return
}

self.isToolbarHidden = false
self.update(with: ThemeService.shared().theme)

let spacesButton = UIBarButtonItem(image: Asset.Images.allChatsSpacesIcon.image, style: .done, target: self, action: #selector(self.showSpaceSelectorAction(sender: )))
spacesButton.accessibilityLabel = VectorL10n.spaceSelectorTitle
self.update(with: theme)

self.toolbar.items = [
spacesButton,
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7088.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add badge for messages in spaces button.