diff options
author | Vitaly Takmazov | 2023-04-26 19:49:01 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-04-26 19:49:01 +0300 |
commit | edfa752df766726c93bc5a1bd5c4a8bcb014f831 (patch) | |
tree | 5872b53d6f7ba5f1e6144ff3ce4c84637b632d44 /Juick | |
parent | 9ca85a0132ed9d33dac586e05a048ffcff9b7843 (diff) |
Contextual actions and message recommendations
* ellipsis image require iOS 13
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/API.h | 1 | ||||
-rw-r--r-- | Juick/API.m | 6 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 17 | ||||
-rw-r--r-- | Juick/Views/MessageCell.xib | 37 |
4 files changed, 43 insertions, 18 deletions
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 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> <device id="retina4_7" orientation="portrait" appearance="light"/> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/> <capability name="Named colors" minToolsVersion="9.0"/> + <capability name="Stack View standard spacing" minToolsVersion="9.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <objects> @@ -17,30 +18,30 @@ <rect key="frame" x="0.0" y="0.0" width="572" height="604"/> <autoresizingMask key="autoresizingMask"/> <subviews> - <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="Azj-pa-GEC"> - <rect key="frame" x="6" y="6" width="560" height="592"/> + <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Azj-pa-GEC"> + <rect key="frame" x="20" y="20" width="532" height="564"/> <subviews> - <stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" distribution="fillProportionally" alignment="center" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="7FT-kJ-84d"> - <rect key="frame" x="0.0" y="0.0" width="560" height="136.5"/> + <stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" distribution="fillProportionally" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="7FT-kJ-84d"> + <rect key="frame" x="0.0" y="0.0" width="532" height="76"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="CZk-Q8-JqS"> - <rect key="frame" x="0.0" y="44.5" width="48" height="48"/> + <rect key="frame" x="0.0" y="14" width="48" height="48"/> <constraints> <constraint firstAttribute="height" priority="999" constant="48" id="ZnT-UD-xga"/> <constraint firstAttribute="width" constant="48" id="khZ-DB-qfq"/> </constraints> </imageView> - <stackView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="252" axis="vertical" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="o3h-ci-LWF"> - <rect key="frame" x="60" y="49.5" width="500" height="37.5"/> + <stackView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="252" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="o3h-ci-LWF"> + <rect key="frame" x="56" y="16" width="476" height="44.5"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CHd-h0-hPk"> - <rect key="frame" x="0.0" y="0.0" width="500" height="17"/> + <rect key="frame" x="0.0" y="0.0" width="476" height="20.5"/> <fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/> <nil key="textColor"/> <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AVu-qV-q84"> - <rect key="frame" x="0.0" y="23" width="500" height="14.5"/> + <rect key="frame" x="0.0" y="28.5" width="476" height="16"/> <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> <nil key="textColor"/> <nil key="highlightedColor"/> @@ -50,21 +51,21 @@ </subviews> </stackView> <textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" verticalHuggingPriority="1000" verticalCompressionResistancePriority="749" scrollEnabled="NO" editable="NO" textAlignment="natural" adjustsFontForContentSizeCategory="YES" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nZn-a4-oSt"> - <rect key="frame" x="0.0" y="148.5" width="560" height="149"/> + <rect key="frame" x="0.0" y="84" width="532" height="192"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <string key="text">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.</string> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> </textView> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Uha-ow-kFJ"> - <rect key="frame" x="0.0" y="309.5" width="560" height="256"/> + <rect key="frame" x="0.0" y="284" width="532" height="256"/> <constraints> <constraint firstAttribute="height" priority="999" constant="256" identifier="attachHeight" id="Cuq-dQ-VYU"/> <constraint firstAttribute="width" priority="999" constant="256" identifier="attachWidth" id="oJg-1R-jp3"/> </constraints> </imageView> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aJE-mZ-MCS"> - <rect key="frame" x="0.0" y="577.5" width="560" height="14.5"/> + <rect key="frame" x="0.0" y="548" width="532" height="16"/> <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> <nil key="textColor"/> <nil key="highlightedColor"/> @@ -75,10 +76,10 @@ </subviews> <color key="backgroundColor" name="Background"/> <constraints> - <constraint firstAttribute="bottom" secondItem="Azj-pa-GEC" secondAttribute="bottom" constant="6" id="OWY-DI-0dv"/> - <constraint firstItem="Azj-pa-GEC" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="6" id="Ohz-6B-bYr"/> - <constraint firstItem="Azj-pa-GEC" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="6" id="biD-O8-Mwb"/> - <constraint firstAttribute="trailing" secondItem="Azj-pa-GEC" secondAttribute="trailing" constant="6" id="ymN-qs-0pB"/> + <constraint firstAttribute="bottom" secondItem="Azj-pa-GEC" secondAttribute="bottom" constant="20" symbolic="YES" id="OWY-DI-0dv"/> + <constraint firstItem="Azj-pa-GEC" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="20" symbolic="YES" id="Ohz-6B-bYr"/> + <constraint firstItem="Azj-pa-GEC" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="20" symbolic="YES" id="biD-O8-Mwb"/> + <constraint firstAttribute="trailing" secondItem="Azj-pa-GEC" secondAttribute="trailing" constant="20" symbolic="YES" id="ymN-qs-0pB"/> </constraints> </tableViewCellContentView> <connections> |