mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-03 14:46:56 +02:00
Add context menu to HomeViewController cells.
This commit is contained in:
@@ -610,9 +610,16 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add long tap gesture recognizer.
|
||||
UILongPressGestureRecognizer *cellLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellLongPress:)];
|
||||
[cell addGestureRecognizer:cellLongPressGesture];
|
||||
if (@available(iOS 13.0, *))
|
||||
{
|
||||
// Use context menu instead
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add long tap gesture recognizer.
|
||||
UILongPressGestureRecognizer *cellLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellLongPress:)];
|
||||
[cell addGestureRecognizer:cellLongPressGesture];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,6 +671,97 @@
|
||||
[self.recentsSearchBar resignFirstResponder];
|
||||
}
|
||||
|
||||
- (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionView contextMenuConfigurationForItemAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point API_AVAILABLE(ios(13.0))
|
||||
{
|
||||
MXRoom *room = [self.dataSource getRoomAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:collectionView.tag]];
|
||||
NSString *roomId = room.roomId;
|
||||
|
||||
return [UIContextMenuConfiguration configurationWithIdentifier:roomId
|
||||
previewProvider:nil
|
||||
actionProvider:^UIMenu * _Nullable(NSArray<UIMenuElement *> * _Nonnull suggestedActions) {
|
||||
MXWeakify(self);
|
||||
|
||||
BOOL isDirect = room.isDirect;
|
||||
UIAction *directChatAction = [UIAction actionWithTitle:isDirect ? @"Room" : @"Direct Chat"
|
||||
image:[UIImage systemImageNamed:isDirect ? @"person.crop.circle.badge.xmark" : @"person.circle"]
|
||||
identifier:nil
|
||||
handler:^(__kindof UIAction * _Nonnull action) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self updateRoomWithId:roomId asDirect:!isDirect];
|
||||
}];
|
||||
|
||||
BOOL isMuted = room.isMute || room.isMentionsOnly;
|
||||
UIImage *notificationsImage;
|
||||
NSString *notificationsTitle;
|
||||
if ([BuildSettings showNotificationsV2])
|
||||
{
|
||||
notificationsTitle = @"Notifications";
|
||||
notificationsImage = [UIImage systemImageNamed:@"bell"];
|
||||
}
|
||||
else
|
||||
{
|
||||
notificationsTitle = isMuted ? @"Un-mute" : @"Mute";
|
||||
notificationsImage = [UIImage systemImageNamed:isMuted ? @"bell.slash": @"bell"];
|
||||
}
|
||||
|
||||
UIAction *notificationsAction = [UIAction actionWithTitle:notificationsTitle
|
||||
image:notificationsImage
|
||||
identifier:nil
|
||||
handler:^(__kindof UIAction * _Nonnull action) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self updateRoomWithId:roomId asMuted:!isMuted];
|
||||
}];
|
||||
|
||||
|
||||
// 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[0];
|
||||
}
|
||||
}
|
||||
|
||||
BOOL isFavourite = (currentTag && [kMXRoomTagFavourite isEqualToString:currentTag.name]);
|
||||
UIAction *favouriteAction = [UIAction actionWithTitle:isFavourite ? @"Un-favourite" : @"Favourite"
|
||||
image:[UIImage systemImageNamed:isFavourite ? @"star.slash" : @"star"]
|
||||
identifier:nil
|
||||
handler:^(__kindof UIAction * _Nonnull action) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self updateRoomWithId:roomId asFavourite:!isFavourite];
|
||||
}];
|
||||
|
||||
BOOL isLowPriority = (currentTag && [kMXRoomTagLowPriority isEqualToString:currentTag.name]);
|
||||
UIImage *lowPriorityImage = [UIImage systemImageNamed:isLowPriority ? @"arrow.up" : @"arrow.down"];
|
||||
UIAction *lowPriorityAction = [UIAction actionWithTitle:isLowPriority ? @"Normal Priority" : @"Low Priority"
|
||||
image:lowPriorityImage
|
||||
identifier:nil
|
||||
handler:^(__kindof UIAction * _Nonnull action) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self updateRoomWithId:roomId asLowPriority:!isLowPriority];
|
||||
}];
|
||||
|
||||
UIAction *leaveAction = [UIAction actionWithTitle:@"Leave"
|
||||
image:[UIImage systemImageNamed:@"rectangle.righthalf.inset.filled.arrow.right"]
|
||||
identifier:nil
|
||||
handler:^(__kindof UIAction * _Nonnull action) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self leaveRoomWithId:roomId];
|
||||
}];
|
||||
leaveAction.attributes = UIMenuElementAttributesDestructive;
|
||||
|
||||
return [UIMenu menuWithTitle:@"" children:@[
|
||||
directChatAction,
|
||||
notificationsAction,
|
||||
favouriteAction,
|
||||
lowPriorityAction,
|
||||
leaveAction
|
||||
]];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegateFlowLayout
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
@@ -703,7 +801,7 @@
|
||||
// Store the current content offset of the selected collection before refreshing.
|
||||
NSIndexPath *tableViewCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:selectedSection];
|
||||
TableViewCellWithCollectionView *tableViewCellWithCollectionView = [self.recentsTableView cellForRowAtIndexPath:tableViewCellIndexPath];
|
||||
CGFloat selectedCollectionViewContentOffsetCpy = tableViewCellWithCollectionView.collectionView.contentOffset.x;
|
||||
CGFloat selectedCollectionViewContentOffsetCopy = tableViewCellWithCollectionView.collectionView.contentOffset.x;
|
||||
|
||||
[self refreshRecentsTable];
|
||||
|
||||
@@ -720,8 +818,8 @@
|
||||
{
|
||||
// On iOS < 10, the collection view scrolls to the beginning during the table refresh.
|
||||
// We store here the actual content offset, used during the collection view loading.
|
||||
selectedCollectionViewContentOffset = selectedCollectionViewContentOffsetCpy;
|
||||
}
|
||||
selectedCollectionViewContentOffset = selectedCollectionViewContentOffsetCopy;
|
||||
}
|
||||
|
||||
[self.recentsTableView scrollRectToVisible:tableViewCellWithCollectionView.frame animated:YES];
|
||||
|
||||
@@ -752,74 +850,46 @@
|
||||
|
||||
- (IBAction)onDirectChatButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self makeDirectEditedRoom:!button.tag];
|
||||
}
|
||||
}
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self makeDirectEditedRoom:!button.tag];
|
||||
}
|
||||
|
||||
- (IBAction)onNotificationsButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
if ([BuildSettings showNotificationsV2])
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
if ([BuildSettings showNotificationsV2])
|
||||
{
|
||||
[self changeEditedRoomNotificationSettings];
|
||||
}
|
||||
else
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self muteEditedRoomNotifications:!button.tag];
|
||||
}
|
||||
}
|
||||
[self changeEditedRoomNotificationSettings];
|
||||
}
|
||||
else
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
[self muteEditedRoomNotifications:!button.tag];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onFavouriteButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagFavourite];
|
||||
}
|
||||
}
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagFavourite];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onPriorityButtonPressed:(id)sender
|
||||
{
|
||||
if (editedRoomId)
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId];
|
||||
if (room)
|
||||
{
|
||||
UIButton *button = (UIButton*)sender;
|
||||
if (button.tag)
|
||||
{
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagLowPriority];
|
||||
}
|
||||
}
|
||||
[self updateEditedRoomTag:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self updateEditedRoomTag:kMXRoomTagLowPriority];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -828,6 +898,50 @@
|
||||
[self leaveEditedRoom];
|
||||
}
|
||||
|
||||
// MARK: - Context Menu Actions
|
||||
|
||||
- (void)updateRoomWithId:(NSString *)roomId asDirect:(BOOL)direct
|
||||
{
|
||||
editedRoomId = roomId;
|
||||
[self makeDirectEditedRoom:direct];
|
||||
editedRoomId = nil;
|
||||
}
|
||||
|
||||
- (void)updateRoomWithId:(NSString *)roomId asMuted:(BOOL)muted
|
||||
{
|
||||
editedRoomId = roomId;
|
||||
if ([BuildSettings showNotificationsV2])
|
||||
{
|
||||
[self changeEditedRoomNotificationSettings];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self muteEditedRoomNotifications:muted];
|
||||
}
|
||||
editedRoomId = nil;
|
||||
}
|
||||
|
||||
- (void)updateRoomWithId:(NSString *)roomId asFavourite:(BOOL)favourite
|
||||
{
|
||||
editedRoomId = roomId;
|
||||
[self updateEditedRoomTag:favourite ? kMXRoomTagFavourite : nil];
|
||||
editedRoomId = nil;
|
||||
}
|
||||
|
||||
- (void)updateRoomWithId:(NSString *)roomId asLowPriority:(BOOL)lowPriority
|
||||
{
|
||||
editedRoomId = roomId;
|
||||
[self updateEditedRoomTag:lowPriority ? kMXRoomTagLowPriority : nil];
|
||||
editedRoomId = nil;
|
||||
}
|
||||
|
||||
- (void)leaveRoomWithId:(NSString *)roomId
|
||||
{
|
||||
editedRoomId = roomId;
|
||||
[self leaveEditedRoom];
|
||||
editedRoomId = nil;
|
||||
}
|
||||
|
||||
#pragma mark - SecureBackupSetupCoordinatorBridgePresenterDelegate
|
||||
|
||||
- (void)secureBackupSetupCoordinatorBridgePresenterDelegateDidComplete:(SecureBackupSetupCoordinatorBridgePresenter *)coordinatorBridgePresenter
|
||||
|
||||
Reference in New Issue
Block a user