From edfa752df766726c93bc5a1bd5c4a8bcb014f831 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 26 Apr 2023 19:49:01 +0300 Subject: Contextual actions and message recommendations * ellipsis image require iOS 13 --- Juick/ViewControllers/MessagesViewController.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Juick/ViewControllers') diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 804b47b..12f8176 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -16,6 +16,7 @@ #import "ThreadViewController.h" #import "BlogViewController.h" #import "User+UIView.h" +#import "API.h" NSString* const messageCellIdentifier = @"messageCell"; @@ -202,6 +203,22 @@ NSString* const messageCellIdentifier = @"messageCell"; } } +- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { + Message *msg = [self.messages objectAtIndex:indexPath.row]; + UIContextualAction *moreAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"More" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { + }]; + moreAction.image = [UIImage systemImageNamed:@"ellipsis.circle"]; + UIContextualAction *likeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Recommend" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { + [[AppDelegate shared].api likeMessageWithId:msg.mid callback:^(BOOL result) { + completionHandler(YES); + }]; + }]; + likeAction.backgroundColor = [UIColor colorNamed:@"Funny"]; + NSArray *actions = msg.rid == 0 ? @[likeAction, moreAction] : @[moreAction]; + UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:actions]; + return configuration; +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; -- cgit v1.2.3