summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-03 21:33:11 +0300
committerGravatar Vitaly Takmazov2018-03-03 21:33:11 +0300
commit5d0e97b3c1a1910a036f455b67205bc5eece1c29 (patch)
tree5878f990e43ac5b2f163764bfa7f9226a962b8f3
parent3e0b7455926477ee5cce1233bf1bf1d6f2bd63f8 (diff)
discussions
-rw-r--r--Juick/APIClient.h3
-rw-r--r--Juick/APIClient.m7
-rw-r--r--Juick/Helpers/ColorScheme.m4
-rw-r--r--Juick/Supporting Files/Juick-Info.plist2
-rw-r--r--Juick/ViewControllers/DiscoverViewController.h2
-rw-r--r--Juick/ViewControllers/DiscoverViewController.m23
-rw-r--r--Juick/ViewControllers/MessagesViewController.h7
-rw-r--r--Juick/ViewControllers/MessagesViewController.m9
-rw-r--r--Juick/Views/MessageCell.m6
9 files changed, 47 insertions, 16 deletions
diff --git a/Juick/APIClient.h b/Juick/APIClient.h
index a20998a..b336c8c 100644
--- a/Juick/APIClient.h
+++ b/Juick/APIClient.h
@@ -12,6 +12,8 @@
@interface APIClient : NSObject
@property (nonatomic, retain) AFHTTPSessionManager *manager;
+@property (nonatomic, strong) NSDateFormatter *dateFormatter;
+
+(APIClient *) sharedClient;
-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback;
@@ -21,5 +23,6 @@
+(NSString *) messagesUrl;
+(NSString *) threadUrl;
+(NSString *) feedUrl;
++(NSString *) discussionsUrl;
@end
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index ecaf536..3190659 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -29,6 +29,9 @@
self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.juick.com"]];
self.manager.requestSerializer = [AFJSONRequestSerializer new];
self.backgroundQueue = [NSOperationQueue new];
+ self.dateFormatter = [[NSDateFormatter alloc] init];
+ self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
+ [self.dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
}
return self;
}
@@ -104,6 +107,10 @@
return @"/messages";
}
++(NSString *) discussionsUrl {
+ return @"/messages/discussions";
+}
+
+(NSString *) threadUrl {
return @"/thread";
}
diff --git a/Juick/Helpers/ColorScheme.m b/Juick/Helpers/ColorScheme.m
index 39e3971..69fe98f 100644
--- a/Juick/Helpers/ColorScheme.m
+++ b/Juick/Helpers/ColorScheme.m
@@ -25,11 +25,11 @@
}
+ (UIColor *) headerBackground {
- return [self colorWithHex:0xf2f2ec];
+ return [self colorWithHex:0xffffff];
}
+ (UIColor *) mainBackground {
- return [self colorWithHex:0xeaeadf];
+ return [self colorWithHex:0xf8f8f8];
}
+ (UIColor *) textColor {
return [self colorWithHex:0x222222];
diff --git a/Juick/Supporting Files/Juick-Info.plist b/Juick/Supporting Files/Juick-Info.plist
index 0ef24a1..f04104f 100644
--- a/Juick/Supporting Files/Juick-Info.plist
+++ b/Juick/Supporting Files/Juick-Info.plist
@@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.0.45</string>
+ <string>46</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
diff --git a/Juick/ViewControllers/DiscoverViewController.h b/Juick/ViewControllers/DiscoverViewController.h
index 6bec23d..9f96b98 100644
--- a/Juick/ViewControllers/DiscoverViewController.h
+++ b/Juick/ViewControllers/DiscoverViewController.h
@@ -9,6 +9,6 @@
#import <UIKit/UIKit.h>
#import "MessagesViewController.h"
-@interface DiscoverViewController : MessagesViewController
+@interface DiscoverViewController : MessagesViewController<MessagesDelegate>
@end
diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m
index c027ea7..1b1a0a1 100644
--- a/Juick/ViewControllers/DiscoverViewController.m
+++ b/Juick/ViewControllers/DiscoverViewController.m
@@ -22,6 +22,7 @@ AppDelegate *appDelegate;
-(void) viewDidLoad {
[super viewDidLoad];
+ self.messagesDelegate = self;
if ([User isAuthenticated]) {
[User checkIsValid:^(BOOL success) {
if (success) {
@@ -91,7 +92,29 @@ AppDelegate *appDelegate;
[self.tableView reloadData];
[self refreshData:NO];
}]];
+ [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discussions" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+ [self setTitle:@"Discussions"];
+ self.path = [APIClient discussionsUrl];
+ self.params = nil;
+ [self.messages removeAllObjects];
+ [self.tableView reloadData];
+ [self refreshData:NO];
+ }]];
[self presentViewController:filterAlert animated:YES completion:nil];
}
+-(void) loadMore {
+ Message *lastMsg = [self.messages lastObject];
+ if (lastMsg != nil) {
+ if ([self.path isEqualToString:[APIClient discussionsUrl]]) {
+ NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp];
+ self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy];
+ } else if (![self.path isEqualToString:[APIClient threadUrl]]) {
+ NSNumber *lastMid = lastMsg.mid;
+ self.params = [@{@"before_mid":lastMid} mutableCopy];
+ }
+ [self refreshData:NO];
+ }
+}
+
@end
diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h
index 9f47b57..2259b91 100644
--- a/Juick/ViewControllers/MessagesViewController.h
+++ b/Juick/ViewControllers/MessagesViewController.h
@@ -8,6 +8,10 @@
#import <UIKit/UIKit.h>
+@protocol MessagesDelegate
+-(void) loadMore;
+@end
+
@interface MessagesViewController : UITableViewController
@property(nonatomic, strong) NSString *path;
@property(nonatomic, strong) NSDictionary *params;
@@ -16,4 +20,7 @@
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, assign) Boolean dataLoading;
+@property(nonatomic, weak) id<MessagesDelegate> messagesDelegate;
@end
+
+
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index de79164..c718336 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -103,14 +103,7 @@
CGFloat actualPosition = scrollView_.contentOffset.y;
CGFloat contentHeight = scrollView_.contentSize.height - scrollView_.contentSize.height / 2;
if (actualPosition >= contentHeight && !self.dataLoading && ![self.tableView isTracking]) {
- Message *lastMsg = [self.messages lastObject];
- if (lastMsg != nil) {
- NSNumber *lastMid = lastMsg.mid;
- if (![self.path isEqualToString:[APIClient threadUrl]]) {
- self.params = [@{@"before_mid":lastMid} mutableCopy];
- }
- [self refreshData:NO];
- }
+ [_messagesDelegate loadMore];
}
}
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index ca84053..2f00d7e 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -9,6 +9,7 @@
#import "MessageCell.h"
#import "ColorScheme.h"
#import "UIImage+Utils.h"
+#import "APIClient.h"
@import DateTools;
@import MWFeedParser;
@@ -40,11 +41,8 @@
self.attach.image = nil;
}
self.title.text = msg.user.uname;
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
- [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
- self.timestamp.text = [[formatter dateFromString:msg.timestamp] timeAgoSinceNow];
+ self.timestamp.text = [[[APIClient sharedClient].dateFormatter dateFromString:msg.timestamp] timeAgoSinceNow];
NSUInteger count = [msg.repliesCount unsignedIntegerValue];
if (count > 0) {
if ([msg.repliesBy length] > 0) {