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.xcodeproj/project.pbxproj | 6 ++--- Juick/API.h | 1 + Juick/API.m | 6 +++++ Juick/ViewControllers/MessagesViewController.m | 17 ++++++++++++ Juick/Views/MessageCell.xib | 37 +++++++++++++------------- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 8e303b4..53c3d0a 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -798,7 +798,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -848,7 +848,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -1010,7 +1010,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; diff --git a/Juick/API.h b/Juick/API.h index ad1433b..282a43b 100644 --- a/Juick/API.h +++ b/Juick/API.h @@ -32,6 +32,7 @@ extern NSString * const JuickErrorDomain; -(void) getUserByName:(NSString *) name callback:(void(^)(User *))callback; -(void) getUserByUri:(NSString *) uri callback:(void(^)(User *))callback; -(void) fetchImageWithURL:(NSURL *) url callback:(void(^)(NSData *))callback; +-(void) likeMessageWithId:(NSNumber *) id callback:(void(^)(BOOL))callback; @property (nonatomic, strong) User * currentUser; +(NSString *) messagesUrl; diff --git a/Juick/API.m b/Juick/API.m index 9958d1c..7284029 100644 --- a/Juick/API.m +++ b/Juick/API.m @@ -318,6 +318,12 @@ NSString * const JuickErrorDomain = @"JuickErrorDomain"; }]; } +- (void)likeMessageWithId:(NSNumber *)messageId callback:(void (^)(BOOL))callback { + [self post:@"like" params:@{@"mid": messageId} callback:^(NSDictionary *response, NSError *err) { + callback((err != nil)); + }]; +} + +(NSString *) messagesUrl { return @"messages"; } 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]; diff --git a/Juick/Views/MessageCell.xib b/Juick/Views/MessageCell.xib index b04bf75..53a2408 100644 --- a/Juick/Views/MessageCell.xib +++ b/Juick/Views/MessageCell.xib @@ -1,10 +1,11 @@ - + - + + @@ -17,30 +18,30 @@ - - + + - - + + - + - - + + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - + - - - - + + + + -- cgit v1.2.3