diff options
author | Vitaly Takmazov | 2019-03-21 23:39:03 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-21 23:39:03 +0300 |
commit | 6e49fc5c4273e7597925c133c3a6985b6ad85ecc (patch) | |
tree | ca5c8bac8e6bbe73d28db597be38840a4e88deca /Juick | |
parent | 31cee12a4f5c2733965e99e2fa9add28fee266c2 (diff) |
First RC
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.h | 2 | ||||
-rw-r--r-- | Juick/APIClient.m | 2 | ||||
-rw-r--r-- | Juick/AppDelegate.h | 3 | ||||
-rw-r--r-- | Juick/AppDelegate.m | 12 | ||||
-rw-r--r-- | Juick/Main.storyboard | 23 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.h | 17 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.m | 34 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscussionsController.h | 17 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscussionsController.m | 35 | ||||
-rw-r--r-- | Juick/ViewControllers/FeedViewController.m | 35 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.h | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 56 | ||||
-rw-r--r-- | Juick/ViewControllers/ThreadViewController.h | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/ThreadViewController.m | 10 |
14 files changed, 171 insertions, 79 deletions
diff --git a/Juick/APIClient.h b/Juick/APIClient.h index 1329868..f2b2a7c 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -15,7 +15,7 @@ +(APIClient *) sharedClient; --(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback; +-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray<Message *>*, NSError *))callback; -(void) postMessage:(NSString *)text result:(void(^)(Message *, NSError *))callback; -(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback; -(void) postPMToUser:(NSString *)uname text:(NSString *)text result:(void(^)(NSError *))callback; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 44e7537..869e944 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -52,7 +52,7 @@ return _manager; } --(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback { +-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray<Message *> *, NSError *))callback { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.backgroundQueue addOperationWithBlock:^{ [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h index 931cf0b..59dd7f5 100644 --- a/Juick/AppDelegate.h +++ b/Juick/AppDelegate.h @@ -7,6 +7,7 @@ // @import UIKit; +#import "ThreadViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate> @@ -16,6 +17,8 @@ +(AppDelegate *) shared; ++(ThreadViewController *) threadViewController; + @property (strong, nonatomic) NSNumber *pushedThread; @property (strong, nonatomic) NSString *pushedUname; diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index cf2afa8..802bbab 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -95,10 +95,11 @@ [main setSelectedIndex:0]; UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; [discover popToRootViewControllerAnimated:NO]; - [[discover.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"threadViewSegue" sender:discover]; + MessagesViewController *msgVC = (MessagesViewController *)[discover.viewControllers objectAtIndex:0]; + [msgVC viewThreadForMessage:nil mid:self.pushedThread]; } else { - [main setSelectedIndex:1]; - UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; + [main setSelectedIndex:2]; + UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:2]; [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; } }]; @@ -128,4 +129,9 @@ return (AppDelegate *)[UIApplication sharedApplication].delegate; } ++ (id)threadViewController { + UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; + return [mainStoryboard instantiateViewControllerWithIdentifier:@"threadViewControllerIdentifier"]; +} + @end diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index 532d492..c2c1717 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -13,7 +13,7 @@ <!--Thread View Controller--> <scene sceneID="hRe-9n-wGd"> <objects> - <tableViewController hidesBottomBarWhenPushed="YES" id="egN-ti-sbh" customClass="ThreadViewController" sceneMemberID="viewController"> + <tableViewController storyboardIdentifier="threadViewControllerIdentifier" hidesBottomBarWhenPushed="YES" id="egN-ti-sbh" customClass="ThreadViewController" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="R7I-ps-E4b"> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> @@ -40,7 +40,7 @@ </tableViewController> <placeholder placeholderIdentifier="IBFirstResponder" id="woP-g5-FaQ" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="1520.8" y="-964.76761619190415"/> + <point key="canvasLocation" x="76" y="-889"/> </scene> <!--Today--> <scene sceneID="NkO-CZ-YSO"> @@ -77,9 +77,6 @@ <rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/> <autoresizingMask key="autoresizingMask"/> </tableViewCellContentView> - <connections> - <segue destination="egN-ti-sbh" kind="push" identifier="threadViewSegue" id="Z1t-ZV-yVS"/> - </connections> </tableViewCell> </prototypes> <connections> @@ -289,7 +286,7 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="XYj-Y4-lfM"> - <rect key="frame" x="4" y="60" width="367" height="603"/> + <rect key="frame" x="4" y="16" width="367" height="647"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> @@ -328,7 +325,7 @@ </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="Pm0-3R-NV9" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="583.20000000000005" y="-169.56521739130437"/> + <point key="canvasLocation" x="1148" y="-889"/> </scene> <!--Chat View Controller--> <scene sceneID="pvH-EU-EhQ"> @@ -359,10 +356,10 @@ </objects> <point key="canvasLocation" x="1408.8" y="-162.3688155922039"/> </scene> - <!--Table View Controller--> + <!--Discover View Controller--> <scene sceneID="g01-td-y6A"> <objects> - <tableViewController id="q23-tm-nTI" sceneMemberID="viewController"> + <tableViewController id="q23-tm-nTI" customClass="DiscoverViewController" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="kjj-SM-22v"> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> @@ -401,18 +398,18 @@ <connections> <segue destination="k3X-uv-0IF" kind="relationship" relationship="viewControllers" id="5rb-rf-WgC"/> <segue destination="YkB-dq-pv4" kind="relationship" relationship="viewControllers" id="uQw-Xa-hwe"/> - <segue destination="wJv-nS-OaN" kind="relationship" relationship="viewControllers" id="5Pl-1T-DRQ"/> <segue destination="bqF-EV-jyA" kind="relationship" relationship="viewControllers" id="L49-RF-BJa"/> + <segue destination="wJv-nS-OaN" kind="relationship" relationship="viewControllers" id="5Pl-1T-DRQ"/> </connections> </tabBarController> <placeholder placeholderIdentifier="IBFirstResponder" id="AnM-ht-zf8" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="-1886" y="-170"/> </scene> - <!--Table View Controller--> + <!--Discussions Controller--> <scene sceneID="m4V-XQ-WRo"> <objects> - <tableViewController id="irg-YA-Ovi" sceneMemberID="viewController"> + <tableViewController id="irg-YA-Ovi" customClass="DiscussionsController" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="txa-ky-5bK"> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> @@ -486,6 +483,6 @@ <image name="ei-search" width="32" height="32"/> </resources> <inferredMetricsTieBreakers> - <segue reference="vj1-M0-h6U"/> + <segue reference="gw8-QZ-Hrt"/> </inferredMetricsTieBreakers> </document> diff --git a/Juick/ViewControllers/DiscoverViewController.h b/Juick/ViewControllers/DiscoverViewController.h new file mode 100644 index 0000000..8325008 --- /dev/null +++ b/Juick/ViewControllers/DiscoverViewController.h @@ -0,0 +1,17 @@ +// +// DiscoverViewController.h +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "MessagesViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DiscoverViewController : MessagesViewController<MessagesDelegate> + +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m new file mode 100644 index 0000000..cba3ca2 --- /dev/null +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -0,0 +1,34 @@ +// +// DiscoverViewController.m +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "DiscoverViewController.h" +#import "APIClient.h" + +@interface DiscoverViewController () + +@end + +@implementation DiscoverViewController +- (void)viewDidLoad { + self.messagesDelegate = self; + self.title = @"Discover"; + self.path = [APIClient messagesUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; + [super viewDidLoad]; +} + +- (void)loadMore { + Message *lastMsg = [self.messages lastObject]; + if (lastMsg != nil) { + NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; + self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; + [self setShouldScrollToBottomOnRefresh:NO]; + } +} + +@end diff --git a/Juick/ViewControllers/DiscussionsController.h b/Juick/ViewControllers/DiscussionsController.h new file mode 100644 index 0000000..93b2ad5 --- /dev/null +++ b/Juick/ViewControllers/DiscussionsController.h @@ -0,0 +1,17 @@ +// +// DiscussionsController.h +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "MessagesViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DiscussionsController : MessagesViewController<MessagesDelegate> + +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/ViewControllers/DiscussionsController.m b/Juick/ViewControllers/DiscussionsController.m new file mode 100644 index 0000000..b8abd3d --- /dev/null +++ b/Juick/ViewControllers/DiscussionsController.m @@ -0,0 +1,35 @@ +// +// DiscussionsController.m +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "DiscussionsController.h" +#import "APIClient.h" + +@interface DiscussionsController () + +@end + +@implementation DiscussionsController + +- (void)viewDidLoad { + self.messagesDelegate = self; + self.title = @"Discussions"; + self.path = [APIClient discussionsUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; + [super viewDidLoad]; +} + +- (void)loadMore { + Message *lastMsg = [self.messages lastObject]; + if (lastMsg != nil) { + NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; + self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; + [self setShouldScrollToBottomOnRefresh:NO]; + } +} + +@end diff --git a/Juick/ViewControllers/FeedViewController.m b/Juick/ViewControllers/FeedViewController.m index d7b51a8..b6b578f 100644 --- a/Juick/ViewControllers/FeedViewController.m +++ b/Juick/ViewControllers/FeedViewController.m @@ -22,41 +22,12 @@ -(void) viewDidLoad { self.messagesDelegate = self; - if ([[APIClient sharedClient] isAuthenticated]) { - [[APIClient sharedClient] authenticate:^(User *user, NSError *error) { - if (user) { - if ([self.path length] == 0) { - self.path = [APIClient feedUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"My feed"; - } - [self setShouldScrollToBottomOnRefresh:NO]; - [self refreshData]; - } else { - [User throwUnableToLogin:self error:error]; - } - }]; - - } else { - if ([self.path length] == 0) { - self.path = [APIClient messagesUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"Discover"; - } - [self setShouldScrollToBottomOnRefresh:NO]; - [self refreshData]; - } + self.title = @"Today"; + self.path = [APIClient feedUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; [super viewDidLoad]; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - if (!self.dataLoading) { - MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; - cell.delegate = self; - return cell; - } else { - return [super tableView:tableView cellForRowAtIndexPath:indexPath]; - } -} - -(void)avatarClicked:(NSString *)uname { self.selectedUser = uname; [self performSegueWithIdentifier:@"profileSegue" sender:self]; diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index 48a9f6b..c8eb4cf 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -22,6 +22,8 @@ extern NSString* const messageCellIdentifier; -(void) refreshData; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid; + @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, assign) Boolean dataLoading; @property(nonatomic, weak) id<MessagesDelegate> messagesDelegate; diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 8a1d072..7029beb 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -95,14 +95,12 @@ NSString* const messageCellIdentifier = @"messageCell"; [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; - if (![self.path isEqualToString:[APIClient threadUrl]]) { + if (!self.messages) { self.messages = [NSMutableArray array]; } self.refreshControl = [UIRefreshControl new]; [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; [self refreshData]; - [self addObserver:self forKeyPath:@"path" options:0 context:nil]; - [self addObserver:self forKeyPath:@"params" options:0 context:nil]; } - (void) composePressed { @@ -133,32 +131,30 @@ NSString* const messageCellIdentifier = @"messageCell"; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier forIndexPath:indexPath]; - [self performSegueWithIdentifier:@"threadViewSegue" sender:cell]; + Message *msg = [self.messages objectAtIndex:indexPath.row]; + [self viewThreadForMessage:msg mid:msg.mid]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - if ([segue.identifier isEqual: @"threadViewSegue"]) { - NSNumber *mid; - Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; - BOOL scrollToEnd = NO; - if ([AppDelegate shared].pushedThread != nil) { - mid = [[AppDelegate shared].pushedThread copy]; - [AppDelegate shared].pushedThread = nil; - [AppDelegate shared].pushedUname = nil; - scrollToEnd = YES; - } else { - mid = msg.mid; - } - if ([mid integerValue] > 0) { - ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; - [threadVC setMessages:[@[msg] mutableCopy]]; - [threadVC setPath:[APIClient threadUrl]]; - [threadVC setParams:@{@"mid": mid }]; - [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; - } - } /* + NSNumber *mid; + Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; + BOOL scrollToEnd = NO; + if ([AppDelegate shared].pushedThread != nil) { + mid = [[AppDelegate shared].pushedThread copy]; + [AppDelegate shared].pushedThread = nil; + [AppDelegate shared].pushedUname = nil; + scrollToEnd = YES; + } else { + mid = msg.mid; + } + if ([mid integerValue] > 0) { + ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; + [threadVC setMessages:[@[msg] mutableCopy]]; + [threadVC setPath:[APIClient threadUrl]]; + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; + } if ([segue.identifier isEqual: @"profileSegue"]) { BlogViewController *blogVC = (BlogViewController *)segue.destinationViewController; [blogVC setUname:self.selectedUser]; @@ -176,8 +172,14 @@ NSString* const messageCellIdentifier = @"messageCell"; } } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { - [self refreshData]; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid { + ThreadViewController *threadVC = [AppDelegate threadViewController]; + if (msg) { + [threadVC setMessages:[@[msg] mutableCopy]]; + } + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:NO]; + [self.navigationController pushViewController:threadVC animated:YES]; } @end diff --git a/Juick/ViewControllers/ThreadViewController.h b/Juick/ViewControllers/ThreadViewController.h index a9c5259..5a4324e 100644 --- a/Juick/ViewControllers/ThreadViewController.h +++ b/Juick/ViewControllers/ThreadViewController.h @@ -9,5 +9,5 @@ #import <UIKit/UIKit.h> #include "MessagesViewController.h" -@interface ThreadViewController : MessagesViewController +@interface ThreadViewController : MessagesViewController<MessagesDelegate> @end diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m index ead94fe..44f9e8a 100644 --- a/Juick/ViewControllers/ThreadViewController.m +++ b/Juick/ViewControllers/ThreadViewController.m @@ -9,13 +9,16 @@ #import "ThreadViewController.h" #import "NewPostViewController.h" #import "MessageCell.h" +#import "APIClient.h" @implementation ThreadViewController -(void) viewDidLoad { - [super viewDidLoad]; [self setTitle:@"Thread"]; + [self setPath:[APIClient threadUrl]]; + [super viewDidLoad]; + self.messagesDelegate = self; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -31,4 +34,9 @@ } } +-(void) loadMore { + Message *lastMsg = [self.messages lastObject]; + [self setShouldScrollToBottomOnRefresh:lastMsg.rid > 0]; +} + @end |