Prepare UX rework:

- Handle the missed conversation badges for each tabBar icon.
This commit is contained in:
Giom Foret 2017-04-28 14:06:58 +02:00
parent dc3de05a57
commit a319f47057
5 changed files with 139 additions and 74 deletions

View file

@ -128,4 +128,34 @@ extern NSString *const kRecentsDataSourceTapOnDirectoryServerChange;
*/
- (void)moveRoomCell:(MXRoom*)room from:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath success:(void (^)())moveSuccess failure:(void (^)(NSError *error))moveFailure;
/**
The current number of the favourite rooms with missed notifications.
*/
@property (nonatomic, readonly) NSUInteger missedFavouriteDiscussionsCount;
/**
The current number of the favourite rooms with unread highlighted messages.
*/
@property (nonatomic, readonly) NSUInteger missedHighlightFavouriteDiscussionsCount;
/**
The current number of the direct chats with missed notifications, including the invites.
*/
@property (nonatomic, readonly) NSUInteger missedDirectDiscussionsCount;
/**
The current number of the direct chats with unread highlighted messages.
*/
@property (nonatomic, readonly) NSUInteger missedHighlightDirectDiscussionsCount;
/**
The current number of the group chats with missed notifications, including the invites.
*/
@property (nonatomic, readonly) NSUInteger missedGroupDiscussionsCount;
/**
The current number of the group chats with unread highlighted messages.
*/
@property (nonatomic, readonly) NSUInteger missedHighlightGroupDiscussionsCount;
@end

View file

@ -852,6 +852,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
[conversationCellDataArray removeAllObjects];
[lowPriorityCellDataArray removeAllObjects];
_missedFavouriteDiscussionsCount = _missedHighlightFavouriteDiscussionsCount = 0;
_missedDirectDiscussionsCount = _missedHighlightDirectDiscussionsCount = 0;
_missedGroupDiscussionsCount = _missedHighlightGroupDiscussionsCount = 0;
directorySection = favoritesSection = conversationSection = lowPrioritySection = invitesSection = -1;
if (displayedRecentsDataSourceArray.count > 0)
@ -862,13 +866,13 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
NSInteger count = recentsDataSource.numberOfCells;
if (_recentsDataSourceMode == RecentsDataSourceModeHome)
for (int index = 0; index < count; index++)
{
for (int index = 0; index < count; index++)
id<MXKRecentCellDataStoring> recentCellDataStoring = [recentsDataSource cellDataAtIndex:index];
MXRoom* room = recentCellDataStoring.roomSummary.room;
if (_recentsDataSourceMode == RecentsDataSourceModeHome)
{
id<MXKRecentCellDataStoring> recentCellDataStoring = [recentsDataSource cellDataAtIndex:index];
MXRoom* room = recentCellDataStoring.roomSummary.room;
if (room.accountData.tags[kMXRoomTagFavourite])
{
[favoriteCellDataArray addObject:recentCellDataStoring];
@ -886,28 +890,16 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
[conversationCellDataArray addObject:recentCellDataStoring];
}
}
}
else if (_recentsDataSourceMode == RecentsDataSourceModeFavourites)
{
for (int index = 0; index < count; index++)
else if (_recentsDataSourceMode == RecentsDataSourceModeFavourites)
{
id<MXKRecentCellDataStoring> recentCellDataStoring = [recentsDataSource cellDataAtIndex:index];
MXRoom* room = recentCellDataStoring.roomSummary.room;
// Keep only the favourites rooms.
if (room.accountData.tags[kMXRoomTagFavourite])
{
[favoriteCellDataArray addObject:recentCellDataStoring];
}
}
}
else if (_recentsDataSourceMode == RecentsDataSourceModePeople)
{
for (int index = 0; index < count; index++)
else if (_recentsDataSourceMode == RecentsDataSourceModePeople)
{
id<MXKRecentCellDataStoring> recentCellDataStoring = [recentsDataSource cellDataAtIndex:index];
MXRoom* room = recentCellDataStoring.roomSummary.room;
// Keep only the direct rooms.
if (room.isDirect)
{
@ -921,14 +913,8 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
}
}
}
}
else if (_recentsDataSourceMode == RecentsDataSourceModeRooms)
{
for (int index = 0; index < count; index++)
else if (_recentsDataSourceMode == RecentsDataSourceModeRooms)
{
id<MXKRecentCellDataStoring> recentCellDataStoring = [recentsDataSource cellDataAtIndex:index];
MXRoom* room = recentCellDataStoring.roomSummary.room;
// Consider only non direct rooms.
if (!room.isDirect)
{
@ -943,8 +929,62 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
}
}
}
// Update missed conversations counts
NSUInteger notificationCount = recentCellDataStoring.roomSummary.notificationCount;
// Ignore the regular notification count if the room is in 'mentions only" mode at the Riot level.
if (room.isMentionsOnly)
{
// Only the highlighted missed messages must be considered here.
notificationCount = recentCellDataStoring.roomSummary.highlightCount;
}
if (notificationCount)
{
if (room.accountData.tags[kMXRoomTagFavourite])
{
_missedFavouriteDiscussionsCount ++;
if (recentCellDataStoring.roomSummary.highlightCount)
{
_missedHighlightFavouriteDiscussionsCount ++;
}
}
if (room.isDirect)
{
_missedDirectDiscussionsCount ++;
if (recentCellDataStoring.roomSummary.highlightCount)
{
_missedHighlightDirectDiscussionsCount ++;
}
}
else
{
_missedGroupDiscussionsCount ++;
if (recentCellDataStoring.roomSummary.highlightCount)
{
_missedHighlightGroupDiscussionsCount ++;
}
}
}
else if (room.state.membership == MXMembershipInvite)
{
if (room.isDirect)
{
_missedDirectDiscussionsCount ++;
}
else
{
_missedGroupDiscussionsCount ++;
}
}
}
if (favoriteCellDataArray.count > 0)
{
// Sort them according to their tag order

View file

@ -103,6 +103,11 @@
*/
- (NSUInteger)missedHighlightDiscussionsCount;
/**
Refresh the missed conversations badges on tab bar icon
*/
- (void)refreshTabBarBadges;
// Reference to the current auth VC. It is not nil only when the auth screen is displayed.
@property (nonatomic, readonly) AuthenticationViewController *authViewController;

View file

@ -46,9 +46,6 @@
// Current alert (if any).
MXKAlert *currentAlert;
// Observer kMXRoomSummaryDidChangeNotification to keep updated the missed discussion count
id mxRoomSummaryDidChangeObserver;
}
@property(nonatomic,getter=isHidden) BOOL hidden;
@ -109,13 +106,7 @@
[self promptUserBeforeUsingGoogleAnalytics];
}
// Observe missed notifications
mxRoomSummaryDidChangeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomSummaryDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self refreshHomeTabBadge];
}];
[self refreshHomeTabBadge];
[self refreshTabBarBadges];
}
if (unifiedSearchViewController)
@ -128,12 +119,6 @@
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
if (mxRoomSummaryDidChangeObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:mxRoomSummaryDidChangeObserver];
mxRoomSummaryDidChangeObserver = nil;
}
}
- (void)dealloc
@ -156,12 +141,6 @@
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
authViewControllerObserver = nil;
}
if (mxRoomSummaryDidChangeObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:mxRoomSummaryDidChangeObserver];
mxRoomSummaryDidChangeObserver = nil;
}
}
#pragma mark -
@ -258,7 +237,7 @@
- (void)onMatrixSessionStateDidChange:(NSNotification *)notif
{
[self refreshHomeTabBadge];
[self refreshTabBarBadges];
}
- (void)showAuthenticationScreen
@ -597,44 +576,52 @@
#pragma mark -
- (void)refreshHomeTabBadge
- (void)refreshTabBarBadges
{
[self setMissedDiscussionsCount:[self missedDiscussionsCount] onTabBarItem:TABBAR_HOME_INDEX withBadgeColor:(self.missedHighlightDiscussionsCount ? kRiotColorPinkRed : kRiotColorGreen)];
[self setMissedDiscussionsCount:recentsDataSource.missedFavouriteDiscussionsCount onTabBarItem:TABBAR_FAVOURITES_INDEX withBadgeColor:(recentsDataSource.missedHighlightFavouriteDiscussionsCount ? kRiotColorPinkRed : kRiotColorGreen)];
[self setMissedDiscussionsCount:recentsDataSource.missedDirectDiscussionsCount onTabBarItem:TABBAR_PEOPLE_INDEX withBadgeColor:(recentsDataSource.missedHighlightDirectDiscussionsCount ? kRiotColorPinkRed : kRiotColorGreen)];
[self setMissedDiscussionsCount:recentsDataSource.missedGroupDiscussionsCount onTabBarItem:TABBAR_ROOMS_INDEX withBadgeColor:(recentsDataSource.missedHighlightGroupDiscussionsCount ? kRiotColorPinkRed : kRiotColorGreen)];
}
- (void)setMissedDiscussionsCount:(NSUInteger)count onTabBarItem:(NSUInteger)index withBadgeColor:(UIColor*)badgeColor
{
NSUInteger count = [self missedDiscussionsCount];
if (count)
{
NSString *badgeValue;
NSString *badgeValue = [self tabBarBadgeStringValue:count];
if (count > 1000)
{
CGFloat value = count / 1000.0;
badgeValue = [NSString stringWithFormat:NSLocalizedStringFromTable(@"large_badge_value_k_format", @"Vector", nil), value];
}
else
{
badgeValue = [NSString stringWithFormat:@"%tu", count];
}
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = badgeValue;
self.tabBar.items[index].badgeValue = badgeValue;
if ([UITabBarItem instancesRespondToSelector:@selector(setBadgeColor:)])
{
if (self.missedHighlightDiscussionsCount)
{
self.tabBar.items[TABBAR_HOME_INDEX].badgeColor = kRiotColorPinkRed;
}
else
{
self.tabBar.items[TABBAR_HOME_INDEX].badgeColor = kRiotColorGreen;
}
self.tabBar.items[index].badgeColor = badgeColor;
}
}
else
{
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = nil;
self.tabBar.items[index].badgeValue = nil;
}
}
#pragma mark -
- (NSString*)tabBarBadgeStringValue:(NSUInteger)count
{
NSString *badgeValue;
if (count > 1000)
{
CGFloat value = count / 1000.0;
badgeValue = [NSString stringWithFormat:NSLocalizedStringFromTable(@"large_badge_value_k_format", @"Vector", nil), value];
}
else
{
badgeValue = [NSString stringWithFormat:@"%tu", count];
}
return badgeValue;
}
#pragma mark -
- (void)promptUserBeforeUsingGoogleAnalytics
{

View file

@ -282,6 +282,9 @@
- (void)refreshRecentsTable
{
// Refresh the tabBar icon badges
[[AppDelegate theDelegate].masterTabBarController refreshTabBarBadges];
// do not refresh if there is a pending recent drag and drop
if (movingCellPath)
{