mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Bug Fix - Repeatedly tapping on tab jumps through rooms in wrong order
#1306
This commit is contained in:
parent
5d24b5b400
commit
65ea460587
9 changed files with 131 additions and 55 deletions
|
@ -21,4 +21,9 @@
|
|||
*/
|
||||
@interface FavouritesViewController : RecentsViewController
|
||||
|
||||
/**
|
||||
Scroll the next room with missed notifications to the top.
|
||||
*/
|
||||
- (void)scrollToNextRoomWithMissedNotifications;
|
||||
|
||||
@end
|
||||
|
|
|
@ -20,6 +20,13 @@
|
|||
|
||||
#import "RecentsDataSource.h"
|
||||
|
||||
@interface FavouritesViewController ()
|
||||
{
|
||||
RecentsDataSource *recentsDataSource;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FavouritesViewController
|
||||
|
||||
- (void)finalizeInit
|
||||
|
@ -51,10 +58,9 @@
|
|||
[AppDelegate theDelegate].masterTabBarController.navigationController.navigationBar.tintColor = kRiotColorIndigo;
|
||||
[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor = kRiotColorIndigo;
|
||||
|
||||
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
if (recentsDataSource)
|
||||
{
|
||||
// Take the lead on the shared data source.
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
recentsDataSource.areSectionsShrinkable = NO;
|
||||
[recentsDataSource setDelegate:self andRecentsDataSourceMode:RecentsDataSourceModeFavourites];
|
||||
}
|
||||
|
@ -82,23 +88,43 @@
|
|||
[super destroy];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)displayList:(MXKRecentsDataSource *)listDataSource
|
||||
{
|
||||
[super displayList:listDataSource];
|
||||
|
||||
// Keep a ref on the recents data source
|
||||
if ([listDataSource isKindOfClass:RecentsDataSource.class])
|
||||
{
|
||||
recentsDataSource = (RecentsDataSource*)listDataSource;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Override RecentsViewController
|
||||
|
||||
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
||||
{
|
||||
// Check whether the recents data source is correctly configured.
|
||||
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModeFavourites)
|
||||
{
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModeFavourites)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
[super refreshCurrentSelectedCell:forceVisible];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)scrollToNextRoomWithMissedNotifications
|
||||
{
|
||||
// Check whether the recents data source is correctly configured.
|
||||
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModeFavourites)
|
||||
{
|
||||
[self scrollToTheTopTheNextRoomWithMissedNotificationsInSection:recentsDataSource.favoritesSection];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UITableView delegate
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
|
|
|
@ -725,10 +725,22 @@
|
|||
|
||||
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
|
||||
{
|
||||
if (item.tag == TABBAR_ROOMS_INDEX && self.selectedIndex == TABBAR_ROOMS_INDEX)
|
||||
// Detect multi-tap on the current selected tab.
|
||||
if (item.tag == self.selectedIndex)
|
||||
{
|
||||
// Scroll to the next room with missed notifications.
|
||||
[self.roomsViewController scrollToNextRoomWithMissedNotifications];
|
||||
if (item.tag == TABBAR_ROOMS_INDEX)
|
||||
{
|
||||
[self.roomsViewController scrollToNextRoomWithMissedNotifications];
|
||||
}
|
||||
else if (item.tag == TABBAR_PEOPLE_INDEX)
|
||||
{
|
||||
[self.peopleViewController scrollToNextRoomWithMissedNotifications];
|
||||
}
|
||||
else if (item.tag == TABBAR_FAVOURITES_INDEX)
|
||||
{
|
||||
[self.favouritesViewController scrollToNextRoomWithMissedNotifications];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,5 +22,10 @@
|
|||
*/
|
||||
@interface PeopleViewController : RecentsViewController <UITableViewDataSource, MXKDataSourceDelegate>
|
||||
|
||||
/**
|
||||
Scroll the next room with missed notifications to the top.
|
||||
*/
|
||||
- (void)scrollToNextRoomWithMissedNotifications;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
ContactsDataSource *contactsDataSource;
|
||||
NSInteger contactsSectionNumber;
|
||||
|
||||
RecentsDataSource *recentsDataSource;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -114,10 +116,9 @@
|
|||
[AppDelegate theDelegate].masterTabBarController.navigationController.navigationBar.tintColor = kRiotColorOrange;
|
||||
[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor = kRiotColorOrange;
|
||||
|
||||
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
if (recentsDataSource)
|
||||
{
|
||||
// Take the lead on the shared data source.
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
recentsDataSource.areSectionsShrinkable = NO;
|
||||
[recentsDataSource setDelegate:self andRecentsDataSourceMode:RecentsDataSourceModePeople];
|
||||
}
|
||||
|
@ -143,6 +144,13 @@
|
|||
|
||||
// Change the table data source. It must be the people view controller itself.
|
||||
self.recentsTableView.dataSource = self;
|
||||
|
||||
// Keep a ref on the recents data source
|
||||
if ([listDataSource isKindOfClass:RecentsDataSource.class])
|
||||
{
|
||||
recentsDataSource = (RecentsDataSource*)listDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - MXKDataSourceDelegate
|
||||
|
@ -164,13 +172,10 @@
|
|||
// Retrieve the current number of sections related to the direct rooms.
|
||||
// Sanity check: check whether the recents data source is correctly configured.
|
||||
directRoomsSectionNumber = 0;
|
||||
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
|
||||
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModePeople)
|
||||
{
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModePeople)
|
||||
{
|
||||
directRoomsSectionNumber = [self.dataSource numberOfSectionsInTableView:self.recentsTableView];
|
||||
}
|
||||
directRoomsSectionNumber = [self.dataSource numberOfSectionsInTableView:self.recentsTableView];
|
||||
}
|
||||
|
||||
// Retrieve the current number of sections related to the contacts
|
||||
|
@ -367,9 +372,8 @@
|
|||
return [contactsDataSource viewForStickyHeaderInSection:section withFrame:frame];
|
||||
}
|
||||
}
|
||||
else if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
else if (recentsDataSource)
|
||||
{
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
return [recentsDataSource viewForStickyHeaderInSection:section withFrame:frame];
|
||||
}
|
||||
|
||||
|
@ -379,15 +383,11 @@
|
|||
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
||||
{
|
||||
// Check whether the recents data source is correctly configured.
|
||||
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
|
||||
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModePeople)
|
||||
{
|
||||
RecentsDataSource *recentsDataSource = (RecentsDataSource*)self.dataSource;
|
||||
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModePeople)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Update here the index of the current selected cell (if any) - Useful in landscape mode with split view controller.
|
||||
NSIndexPath *currentSelectedCellIndexPath = nil;
|
||||
MasterTabBarController *masterTabBarController = [AppDelegate theDelegate].masterTabBarController;
|
||||
|
@ -425,6 +425,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)scrollToNextRoomWithMissedNotifications
|
||||
{
|
||||
// Check whether the recents data source is correctly configured.
|
||||
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModePeople)
|
||||
{
|
||||
[self scrollToTheTopTheNextRoomWithMissedNotificationsInSection:recentsDataSource.conversationSection];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UISearchBarDelegate
|
||||
|
||||
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
||||
|
|
|
@ -129,6 +129,13 @@
|
|||
*/
|
||||
- (void)joinARoom;
|
||||
|
||||
/**
|
||||
Scroll the next room with missed notifications to the top.
|
||||
|
||||
@param section the table section in which the operation must be applied.
|
||||
*/
|
||||
- (void)scrollToTheTopTheNextRoomWithMissedNotificationsInSection:(NSInteger)section;
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)didTapOnSectionHeader:(UIGestureRecognizer*)gestureRecognizer;
|
||||
|
|
|
@ -1658,6 +1658,41 @@
|
|||
[currentAlert showInViewController:self];
|
||||
}
|
||||
|
||||
#pragma mark - Table view scroll handling
|
||||
|
||||
- (void)scrollToTheTopTheNextRoomWithMissedNotificationsInSection:(NSInteger)section
|
||||
{
|
||||
UITableViewCell *firstVisibleCell = self.recentsTableView.visibleCells.firstObject;
|
||||
if (firstVisibleCell)
|
||||
{
|
||||
NSIndexPath *firstVisibleCellIndexPath = [self.recentsTableView indexPathForCell:firstVisibleCell];
|
||||
NSInteger nextCellRow = (firstVisibleCellIndexPath.section == section) ? firstVisibleCellIndexPath.row + 1 : 0;
|
||||
|
||||
// Look for the next room with missed notifications.
|
||||
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:nextCellRow inSection:section];
|
||||
nextCellRow++;
|
||||
id<MXKRecentCellDataStoring> cellData = [self.dataSource cellDataAtIndexPath:nextIndexPath];
|
||||
|
||||
while (cellData)
|
||||
{
|
||||
if (cellData.notificationCount)
|
||||
{
|
||||
[self.recentsTableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
||||
break;
|
||||
}
|
||||
nextIndexPath = [NSIndexPath indexPathForRow:nextCellRow inSection:section];
|
||||
nextCellRow++;
|
||||
cellData = [self.dataSource cellDataAtIndexPath:nextIndexPath];
|
||||
}
|
||||
|
||||
if (!cellData && [self.recentsTableView numberOfRowsInSection:section] > 0)
|
||||
{
|
||||
// Scroll back to the top.
|
||||
[self.recentsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MXKRecentListViewControllerDelegate
|
||||
|
||||
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectRoom:(NSString *)roomId inMatrixSession:(MXSession *)matrixSession
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
@interface RoomsViewController : RecentsViewController
|
||||
|
||||
/**
|
||||
Scroll to the potential room with missed notifications which is not visible yet.
|
||||
Scroll the next room with missed notifications to the top.
|
||||
*/
|
||||
- (void)scrollToNextRoomWithMissedNotifications;
|
||||
|
||||
|
|
|
@ -130,34 +130,9 @@
|
|||
- (void)scrollToNextRoomWithMissedNotifications
|
||||
{
|
||||
// Check whether the recents data source is correctly configured.
|
||||
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModeRooms)
|
||||
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModeRooms)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NSIndexPath *lastVisibleIndexPath = self.recentsTableView.indexPathsForVisibleRows.lastObject;
|
||||
if (lastVisibleIndexPath.section == recentsDataSource.conversationSection)
|
||||
{
|
||||
// Look for the next room with missed notifications.
|
||||
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:lastVisibleIndexPath.row + 1 inSection:recentsDataSource.conversationSection];
|
||||
id<MXKRecentCellDataStoring> cellData = [recentsDataSource cellDataAtIndexPath:nextIndexPath];
|
||||
|
||||
while (cellData)
|
||||
{
|
||||
if (cellData.notificationCount)
|
||||
{
|
||||
[self.recentsTableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
||||
break;
|
||||
}
|
||||
nextIndexPath = [NSIndexPath indexPathForRow:nextIndexPath.row + 1 inSection:recentsDataSource.conversationSection];
|
||||
cellData = [recentsDataSource cellDataAtIndexPath:nextIndexPath];
|
||||
}
|
||||
|
||||
if (!cellData)
|
||||
{
|
||||
// Scroll back to the top.
|
||||
[self.recentsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:recentsDataSource.conversationSection] atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
||||
}
|
||||
[self scrollToTheTopTheNextRoomWithMissedNotificationsInSection:recentsDataSource.conversationSection];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue