mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-03 14:46:56 +02:00
UX Rework: Add home page
- Add edition mode support. https://github.com/vector-im/riot-meta/issues/75
This commit is contained in:
@@ -24,9 +24,17 @@
|
||||
#import "TableViewCellWithCollectionView.h"
|
||||
#import "RoomCollectionViewCell.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@interface HomeViewController ()
|
||||
{
|
||||
RecentsDataSource *recentsDataSource;
|
||||
|
||||
// Room edition
|
||||
NSInteger editedSection;
|
||||
NSString *selectedRoomId;
|
||||
UISwipeGestureRecognizer *horizontalSwipeGestureRecognizer;
|
||||
UISwipeGestureRecognizer *verticalSwipeGestureRecognizer;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -36,6 +44,9 @@
|
||||
{
|
||||
[super finalizeInit];
|
||||
|
||||
editedSection = -1;
|
||||
selectedRoomId = nil;
|
||||
|
||||
self.screenName = @"Home";
|
||||
}
|
||||
|
||||
@@ -156,6 +167,48 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollToTop:(BOOL)animated
|
||||
{
|
||||
if (selectedRoomId)
|
||||
{
|
||||
[self cancelEditionMode:YES];
|
||||
}
|
||||
|
||||
[super scrollToTop:animated];
|
||||
}
|
||||
|
||||
- (void)onPlusButtonPressed
|
||||
{
|
||||
if (selectedRoomId)
|
||||
{
|
||||
[self cancelEditionMode:YES];
|
||||
}
|
||||
|
||||
[super onPlusButtonPressed];
|
||||
}
|
||||
|
||||
- (void)cancelEditionMode:(BOOL)forceRefresh
|
||||
{
|
||||
if (selectedRoomId)
|
||||
{
|
||||
// Ignore forceRefresh, a table refresh is forced at the end.
|
||||
[super cancelEditionMode:NO];
|
||||
|
||||
editedRoomId = selectedRoomId = nil;
|
||||
editedSection = -1;
|
||||
|
||||
// Remove existing gesture recognizers
|
||||
[self.recentsTableView removeGestureRecognizer:horizontalSwipeGestureRecognizer];
|
||||
horizontalSwipeGestureRecognizer = nil;
|
||||
[self.recentsTableView removeGestureRecognizer:verticalSwipeGestureRecognizer];
|
||||
verticalSwipeGestureRecognizer = nil;
|
||||
|
||||
self.recentsTableView.scrollEnabled = YES;
|
||||
|
||||
[self refreshRecentsTable];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
@@ -166,6 +219,9 @@
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
// Edit the potential selected room (see `onCollectionViewCellLongPress`).
|
||||
editedRoomId = selectedRoomId;
|
||||
|
||||
// Each rooms section is represented by only one collection view.
|
||||
return 1;
|
||||
}
|
||||
@@ -185,6 +241,52 @@
|
||||
tableViewCell.collectionView.dataSource = self;
|
||||
tableViewCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
|
||||
if (editedSection != -1 && editedRoomId)
|
||||
{
|
||||
// Disable collection scrolling during edition
|
||||
tableViewCell.collectionView.scrollEnabled = NO;
|
||||
|
||||
if (indexPath.section == editedSection)
|
||||
{
|
||||
// Show edition menu
|
||||
tableViewCell.editionViewHeightConstraint.constant = 65;
|
||||
tableViewCell.editionView.hidden = NO;
|
||||
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
|
||||
// Update the edition menu content (Use the button tag to store the current value).
|
||||
tableViewCell.directChatButton.tag = room.isDirect;
|
||||
[tableViewCell.directChatButton addTarget:self action:@selector(onDirectChatButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
tableViewCell.directChatImageView.image = tableViewCell.directChatButton.tag ? [UIImage imageNamed:@"directChatOff"] : [UIImage imageNamed:@"directChatOn"];
|
||||
|
||||
tableViewCell.notificationsButton.tag = room.isMute || room.isMentionsOnly;
|
||||
[tableViewCell.notificationsButton addTarget:self action:@selector(onNotificationsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
tableViewCell.notificationsImageView.image = tableViewCell.notificationsButton.tag ? [UIImage imageNamed:@"notifications"] : [UIImage imageNamed:@"notificationsOff"];
|
||||
|
||||
// Get the room tag (use only the first one).
|
||||
MXRoomTag* currentTag = nil;
|
||||
if (room.accountData.tags)
|
||||
{
|
||||
NSArray<MXRoomTag*>* tags = room.accountData.tags.allValues;
|
||||
if (tags.count)
|
||||
{
|
||||
currentTag = [tags objectAtIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
tableViewCell.favouriteButton.tag = (currentTag && [kMXRoomTagFavourite isEqualToString:currentTag.name]);
|
||||
[tableViewCell.favouriteButton addTarget:self action:@selector(onFavouriteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
tableViewCell.favouriteImageView.image = tableViewCell.favouriteButton.tag ? [UIImage imageNamed:@"favouriteOff"] : [UIImage imageNamed:@"favourite"];
|
||||
|
||||
tableViewCell.priorityButton.tag = (currentTag && [kMXRoomTagLowPriority isEqualToString:currentTag.name]);
|
||||
[tableViewCell.priorityButton addTarget:self action:@selector(onPriorityButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
tableViewCell.priorityImageView.image = tableViewCell.priorityButton.tag ? [UIImage imageNamed:@"priorityHigh"] : [UIImage imageNamed:@"priorityLow"];
|
||||
|
||||
[tableViewCell.leaveButton addTarget:self action:@selector(onLeaveButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
tableViewCell.leaveImageView.image = [UIImage imageNamed:@"leave"];
|
||||
}
|
||||
}
|
||||
|
||||
return tableViewCell;
|
||||
}
|
||||
|
||||
@@ -203,8 +305,16 @@
|
||||
return [recentsDataSource cellHeightAtIndexPath:indexPath];
|
||||
}
|
||||
|
||||
// Return the fixed height of the collection view cell used to display a room.
|
||||
return [RoomCollectionViewCell defaultCellSize].height;
|
||||
if (indexPath.section != editedSection)
|
||||
{
|
||||
// Return the fixed height of the collection view cell used to display a room.
|
||||
return [RoomCollectionViewCell defaultCellSize].height;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add the edition view height
|
||||
return [RoomCollectionViewCell defaultCellSize].height + 65.0;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDataSource
|
||||
@@ -225,10 +335,25 @@
|
||||
{
|
||||
[cell render:cellData];
|
||||
cell.tag = indexPath.item;
|
||||
cell.collectionViewTag = collectionView.tag;
|
||||
|
||||
//TODO: add long tap gesture recognizer.
|
||||
// UILongPressGestureRecognizer *cellLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellLongPress:)];
|
||||
// [cell addGestureRecognizer:cellLongPressGesture];
|
||||
// Edition mode?
|
||||
if (editedRoomId)
|
||||
{
|
||||
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellTap:)];
|
||||
[cell addGestureRecognizer:tapGesture];
|
||||
|
||||
if ([cellData.roomSummary.roomId isEqualToString:editedRoomId])
|
||||
{
|
||||
cell.editionArrowView.hidden = NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add long tap gesture recognizer.
|
||||
UILongPressGestureRecognizer *cellLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellLongPress:)];
|
||||
[cell addGestureRecognizer:cellLongPressGesture];
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
@@ -260,4 +385,138 @@
|
||||
return [RoomCollectionViewCell defaultCellSize];
|
||||
}
|
||||
|
||||
#pragma mark - Gesture Recognizer
|
||||
|
||||
- (void)onCollectionViewCellLongPress:(UIGestureRecognizer*)gestureRecognizer
|
||||
{
|
||||
RoomCollectionViewCell *selectedCell;
|
||||
|
||||
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
|
||||
{
|
||||
UIView *view = gestureRecognizer.view;
|
||||
if ([view isKindOfClass:[RoomCollectionViewCell class]])
|
||||
{
|
||||
selectedCell = (RoomCollectionViewCell*)view;
|
||||
|
||||
MXRoom* room = [self.dataSource getRoomAtIndexPath:[NSIndexPath indexPathForRow:selectedCell.tag inSection:selectedCell.collectionViewTag]];
|
||||
|
||||
if (room)
|
||||
{
|
||||
// Display no action for the invited room
|
||||
if (room.state.membership == MXMembershipInvite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the identifier of the room related to the edited cell.
|
||||
selectedRoomId = room.state.roomId;
|
||||
// Store the concerned section
|
||||
editedSection = selectedCell.collectionViewTag;
|
||||
|
||||
[self refreshRecentsTable];
|
||||
|
||||
// Make visible the edited cell
|
||||
TableViewCellWithCollectionView *tableViewCellWithCollectionView = [self.recentsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:editedSection]];
|
||||
NSIndexPath *indexPath = [self.dataSource cellIndexPathWithRoomId:selectedRoomId andMatrixSession:room.mxSession];
|
||||
indexPath = [NSIndexPath indexPathForItem:indexPath.item inSection:0];
|
||||
UICollectionViewCell *roomCollectionViewCell = [tableViewCellWithCollectionView.collectionView cellForItemAtIndexPath:indexPath];
|
||||
[tableViewCellWithCollectionView.collectionView scrollRectToVisible:roomCollectionViewCell.frame animated:YES];
|
||||
[self.recentsTableView scrollRectToVisible:tableViewCellWithCollectionView.frame animated:YES];
|
||||
|
||||
// Disable table view scrolling, and defined the swipe gesture recognizers used to cancel the edition mode
|
||||
self.recentsTableView.scrollEnabled = NO;
|
||||
horizontalSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onTableViewSwipe:)];
|
||||
[horizontalSwipeGestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];
|
||||
[self.recentsTableView addGestureRecognizer:horizontalSwipeGestureRecognizer];
|
||||
verticalSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onTableViewSwipe:)];
|
||||
[verticalSwipeGestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown)];
|
||||
[self.recentsTableView addGestureRecognizer:verticalSwipeGestureRecognizer];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onCollectionViewCellTap:(UIGestureRecognizer*)gestureRecognizer
|
||||
{
|
||||
[self cancelEditionMode:YES];
|
||||
}
|
||||
|
||||
- (void)onTableViewSwipe:(UIGestureRecognizer*)gestureRecognizer
|
||||
{
|
||||
[self cancelEditionMode:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Action
|
||||
|
||||
- (IBAction)onDirectChatButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self makeDirectEditedRoom:!button.tag];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onNotificationsButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self muteEditedRoomNotifications:!button.tag];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onFavouriteButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagFavourite];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onPriorityButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagLowPriority];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onLeaveButtonPressed:(id)sender
|
||||
{
|
||||
[self leaveEditedRoom];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user