mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Merge pull request #7088 from vector-im/alfogrillo/badges_spaces
Add badge in spaces button (PSG-966)
This commit is contained in:
commit
ef8a9be5ed
2 changed files with 51 additions and 6 deletions
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -460,7 +465,7 @@ class AllChatsViewController: HomeViewController {
|
|||
return
|
||||
}
|
||||
|
||||
self.update(with: ThemeService.shared().theme)
|
||||
self.update(with: theme)
|
||||
}
|
||||
|
||||
private func update(with theme: Theme) {
|
||||
|
@ -500,22 +505,42 @@ 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, let session = mainSession else {
|
||||
return
|
||||
}
|
||||
|
||||
let notificationCount = session.spaceService.missedNotificationsCount
|
||||
let hasSpaceInvite = session.spaceService.hasSpaceInvite
|
||||
let isBadgeHighlighed = session.spaceService.hasHighlightNotification || hasSpaceInvite
|
||||
let badgeValue = (notificationCount == 0 && hasSpaceInvite) ? "!" : String(notificationCount)
|
||||
|
||||
spacesButton.badgeText = badgeValue
|
||||
spacesButton.badgeBackgroundColor = isBadgeHighlighed ? theme.noticeColor : theme.noticeSecondaryColor
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -1076,3 +1101,22 @@ extension AllChatsViewController: SplitViewMasterViewControllerProtocol {
|
|||
self.refreshCurrentSelectedCell(false)
|
||||
}
|
||||
}
|
||||
|
||||
private extension MXSpaceService {
|
||||
var hasSpaceInvite: Bool {
|
||||
spaceSummaries.contains(where: { $0.isJoined == false })
|
||||
}
|
||||
|
||||
var missedNotificationsCount: UInt {
|
||||
let notificationState = notificationCounter.homeNotificationState
|
||||
let groupNotifications = notificationState.groupMissedDiscussionsCount
|
||||
let directNotifications = notificationState.directMissedDiscussionsCount
|
||||
|
||||
// `notificationState.allCount` returns twice the messages for favourite rooms. Fixing it here.
|
||||
return groupNotifications + directNotifications
|
||||
}
|
||||
|
||||
var hasHighlightNotification: Bool {
|
||||
notificationCounter.homeNotificationState.allHighlightCount > 0
|
||||
}
|
||||
}
|
||||
|
|
1
changelog.d/pr-7088.change
Normal file
1
changelog.d/pr-7088.change
Normal file
|
@ -0,0 +1 @@
|
|||
Add badge for messages in spaces button.
|
Loading…
Reference in a new issue