mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-04 06:58:20 +02:00
Add the badge value for Home tab bar item.
TODO: Fix the missed discussions count, it is broken FTM.
This commit is contained in:
@@ -44,6 +44,9 @@
|
||||
|
||||
// Current alert (if any).
|
||||
MXKAlert *currentAlert;
|
||||
|
||||
// Observer kMXKRoomDataSourceMetaDataChanged to keep updated the missed discussion count
|
||||
id kMXKRoomDataSourceMetaDataChangedObserver;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -66,6 +69,13 @@
|
||||
|
||||
self.tabBar.tintColor = kRiotColorGreen;
|
||||
|
||||
// Adjust the display of the icons in the tabbar.
|
||||
for (UITabBarItem *tabBarItem in self.tabBar.items)
|
||||
{
|
||||
tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
|
||||
tabBarItem.badgeColor = kRiotColorPinkRed;
|
||||
}
|
||||
|
||||
// Initialize here the data sources if a matrix session has been already set.
|
||||
[self initializeDataSources];
|
||||
}
|
||||
@@ -87,6 +97,14 @@
|
||||
{
|
||||
[self promptUserBeforeUsingGoogleAnalytics];
|
||||
}
|
||||
|
||||
// Observe missed notifications
|
||||
kMXKRoomDataSourceMetaDataChangedObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKRoomDataSourceMetaDataChanged object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
||||
|
||||
[self refreshHomeTabBadge];
|
||||
|
||||
}];
|
||||
[self refreshHomeTabBadge];
|
||||
}
|
||||
|
||||
if (unifiedSearchViewController)
|
||||
@@ -96,6 +114,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
|
||||
if (kMXKRoomDataSourceMetaDataChangedObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:kMXKRoomDataSourceMetaDataChangedObserver];
|
||||
kMXKRoomDataSourceMetaDataChangedObserver = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mxSessionArray = nil;
|
||||
@@ -116,6 +145,12 @@
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
|
||||
authViewControllerObserver = nil;
|
||||
}
|
||||
|
||||
if (kMXKRoomDataSourceMetaDataChangedObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:kMXKRoomDataSourceMetaDataChangedObserver];
|
||||
kMXKRoomDataSourceMetaDataChangedObserver = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
@@ -484,6 +519,33 @@
|
||||
[(id)selectedViewController refreshCurrentSelectedCell:forceVisible];
|
||||
}}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)refreshHomeTabBadge
|
||||
{
|
||||
NSUInteger count = [MXKRoomDataSourceManager missedDiscussionsCount];
|
||||
if (count)
|
||||
{
|
||||
NSString *badgeValue;
|
||||
|
||||
if (count > 1000)
|
||||
{
|
||||
CGFloat value = count / 1000.0;
|
||||
badgeValue = [NSString stringWithFormat:@"%.1f k", value];
|
||||
}
|
||||
else
|
||||
{
|
||||
badgeValue = [NSString stringWithFormat:@"%tu", count];
|
||||
}
|
||||
|
||||
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = badgeValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)promptUserBeforeUsingGoogleAnalytics
|
||||
|
||||
Reference in New Issue
Block a user