diff options
author | Vitaly Takmazov | 2014-02-03 16:51:47 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2014-02-03 16:51:47 +0400 |
commit | 57c8c45a4730fe7c980b8b7eadf94ca60b97db43 (patch) | |
tree | 162041af6bd2f3d8f383cf9842a356c07068f04c | |
parent | 4fd723c665a2b828447fcc9476c752803f76ea35 (diff) |
Still fighting with scroll :(
-rw-r--r-- | Juick/LoginViewController.m | 2 | ||||
-rw-r--r-- | Juick/MessageCell.h | 2 | ||||
-rw-r--r-- | Juick/MessageCell.m | 23 | ||||
-rw-r--r-- | Juick/MessagesViewController.h | 3 | ||||
-rw-r--r-- | Juick/MessagesViewController.m | 94 | ||||
-rw-r--r-- | Juick/RevealPanelViewController.m | 6 | ||||
-rw-r--r-- | Juick/User.m | 3 | ||||
-rw-r--r-- | Podfile | 1 | ||||
-rw-r--r-- | Podfile.lock | 3 |
9 files changed, 72 insertions, 65 deletions
diff --git a/Juick/LoginViewController.m b/Juick/LoginViewController.m index f6859a7..38082a3 100644 --- a/Juick/LoginViewController.m +++ b/Juick/LoginViewController.m @@ -22,6 +22,8 @@ static NSString *CellIdentifier = @"CellIdentifier"; target:self action:@selector(cancelSignIn)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(doneSignIn)]; + [self.usernameField setText:nil]; + [self.passwordField setText:nil]; } diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h index 75d46cf..6140e2d 100644 --- a/Juick/MessageCell.h +++ b/Juick/MessageCell.h @@ -39,4 +39,6 @@ - (CGFloat) heightForCell; +- (UITableView *) getTable; + @end diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m index d2b2983..d47c3d2 100644 --- a/Juick/MessageCell.m +++ b/Juick/MessageCell.m @@ -57,7 +57,7 @@ [self.summaryLabel setTextAlignment:NSTextAlignmentLeft]; [self.summaryLabel setTextColor:[UIColor grayColor]]; [self.summaryLabel setBackgroundColor:[UIColor clearColor]]; - self.attach = [[UIImageView alloc]initWithImage:[UIImage imageWithImage:[UIImage imageNamed:@"AttachPlaceholder.png"] convertToWidth:300.0f]]; + self.attach = [[UIImageView alloc] initWithFrame:CGRectZero]; [self.attach setBackgroundColor:[UIColor clearColor]]; self.attach.contentMode = UIViewContentModeTopLeft; @@ -152,7 +152,6 @@ - (void) setMessage:(Message *)msg { _message = msg; [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%d.png", [msg.userID intValue]]] placeholderImage:[UIImage imageNamed:@"0.png"] options:SDWebImageContinueInBackground]; - __weak MessageCell *weakSelf = self; self.titleLabel.text = msg.user; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; @@ -173,21 +172,17 @@ self.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], [msg.text stringByDecodingHTMLEntities]]; } - if ([msg.attach length] > 0) { - SDWebImageManager * manager = [SDWebImageManager sharedManager]; - [manager downloadWithURL:[NSURL URLWithString:msg.attach] options:SDWebImageContinueInBackground progress:^(NSUInteger receivedSize, long long expectedSize) { - // <#code#> - } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { - self.attach.image = [UIImage imageWithImage:image convertToWidth:300.0f]; - [self setNeedsLayout]; - [self layoutIfNeeded]; - }]; - } else { - self.attach.image = nil; - } [self setNeedsLayout]; } +- (UITableView *) getTable { + id view = [self superview]; + while ([view isKindOfClass:[UITableView class]] == NO) { + view = [view superview]; + } + return (UITableView *)view; +} + - (void) attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { [[UIApplication sharedApplication] openURL:url]; } diff --git a/Juick/MessagesViewController.h b/Juick/MessagesViewController.h index bbf4a7e..b0c6a7f 100644 --- a/Juick/MessagesViewController.h +++ b/Juick/MessagesViewController.h @@ -7,9 +7,10 @@ // #import <UIKit/UIKit.h> +#import "SVPullToRefresh.h" @interface MessagesViewController : UITableViewController<UISplitViewControllerDelegate> - (void)loadFromPath:(NSString *)messagesPath withParams:(NSDictionary *)params withTitle:(NSString *)title; -- (void) refreshData:(UIRefreshControl *)refresh; +- (void) refreshData; - (void) composePressed; @end diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index e8e02e1..7e3f01a 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -21,6 +21,10 @@ static NSString *CellIdentifier = @"MessageCell"; +static NSMutableDictionary *heightsCache; + + + @interface MessagesViewController (); @property(nonatomic, strong) NSMutableArray *messages; @@ -37,20 +41,24 @@ static NSString *CellIdentifier = @"MessageCell"; [self setPath:messagesPath]; [self setParams:[[NSMutableDictionary alloc] initWithDictionary:params]]; self.title = title; - [self refreshData:nil]; -} - -- (void) refreshData:(UIRefreshControl *)refresh { - [self.messages removeAllObjects]; - [self.tableView reloadData]; + __weak MessagesViewController * weakSelf = self; + [self.tableView addPullToRefreshWithActionHandler:^{ + [weakSelf.messages removeAllObjects]; + [weakSelf refreshData]; + }]; + [self.tableView addInfiniteScrollingWithActionHandler:^{ + [weakSelf refreshData]; + }]; + [self.tableView triggerPullToRefresh]; +} + +- (void) refreshData { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.dataLoading = YES; [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) { - [self.messages addObjectsFromArray:next]; - [self.tableView reloadData]; - [refresh endRefreshing]; - self.dataLoading = NO; - + [self.messages addObjectsFromArray:next]; + [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + self.dataLoading = NO; }]; }); } @@ -60,43 +68,13 @@ static NSString *CellIdentifier = @"MessageCell"; return UIStatusBarStyleLightContent; } -- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - if ([self.path isEqualToString:[Message threadUrl]]) { - return; - } - CGPoint pos = scrollView.contentOffset; - CGFloat contentHeight = scrollView.contentSize.height - scrollView.contentSize.height / 3; - if (pos.y >= contentHeight && !self.dataLoading) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - self.dataLoading = YES; - if (self.params == nil) { - self.params = [[NSMutableDictionary alloc] init]; - } - - Message * lastMessage = [self.messages lastObject]; - if (lastMessage != nil) { - [self.params setObject:lastMessage.MID forKey:@"before_mid"]; - } - [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) { - [self.messages addObjectsFromArray:next]; - [self.tableView reloadData]; - self.dataLoading = NO; - - }]; - }); - - } -} - - (void)viewDidLoad { [super viewDidLoad]; self.dataLoading = NO; [self.view setBackgroundColor:[ColorScheme mainBackground]]; self.messages = [NSMutableArray array]; - UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; - [refresh addTarget:self action:@selector(refreshData:) forControlEvents:UIControlEventValueChanged]; - self.refreshControl = refresh; + SWRevealViewController *revealController = [self revealViewController]; if (revealController) { // TODO: add to thread view too @@ -106,7 +84,8 @@ static NSString *CellIdentifier = @"MessageCell"; self.navigationController.navigationBar.tintColor = [ColorScheme navbarBackground]; } - [self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier]; + [self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier]; + heightsCache = [[NSMutableDictionary alloc] init]; } - (void) composePressed { @@ -164,16 +143,37 @@ static NSString *CellIdentifier = @"MessageCell"; [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; [cell setMessage:msg]; + if ([msg.attach length] > 0) { + SDWebImageManager * manager = [SDWebImageManager sharedManager]; + [manager downloadWithURL:[NSURL URLWithString:msg.attach] options:SDWebImageContinueInBackground progress:^(NSUInteger receivedSize, long long expectedSize) { + // <#code#> + } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + [cell.attach setImage:[UIImage imageWithImage:image convertToWidth:300.0f]]; + [heightsCache setObject:[NSNumber numberWithFloat:[cell heightForCell]] forKey:[NSString stringWithFormat:@"%@#%@", msg.MID, msg.RID]]; + [tableView beginUpdates]; + [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; + [tableView endUpdates]; + + }]; + } else { + cell.attach.image = nil; + } + return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; - [cell setMessage:msg]; - return [cell heightForCell]; + float height = [[heightsCache objectForKey:[NSString stringWithFormat:@"%@#%@", msg.MID, msg.RID]] floatValue]; + if (height > 0) { + return height; + } else { + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + [cell updateFonts]; + [cell setMessage:msg]; + return [cell heightForCell]; + } } - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath diff --git a/Juick/RevealPanelViewController.m b/Juick/RevealPanelViewController.m index 3b6a446..fe44509 100644 --- a/Juick/RevealPanelViewController.m +++ b/Juick/RevealPanelViewController.m @@ -69,8 +69,10 @@ static NSString *CellIdentifier = @"NavCell"; color = [UIColor redColor]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ [User get:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] callback:^(User *user) { - [self.titleView.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/as/%@.png", user.uid]]]; - [self.titleView.title setText:user.uname]; + if (user != nil) { + [self.titleView.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/as/%@.png", user.uid]]]; + [self.titleView.title setText:user.uname]; + } }]; }); } else { diff --git a/Juick/User.m b/Juick/User.m index 6f1678a..e1bef3a 100644 --- a/Juick/User.m +++ b/Juick/User.m @@ -36,6 +36,7 @@ if (operation.HTTPRequestOperation.response.statusCode == 400) { callback(YES); } else { + [manager.HTTPClient setAuthorizationHeaderWithUsername:nil password:nil]; callback(NO); } }]; @@ -59,7 +60,7 @@ [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { callback([[mappingResult array] firstObject]); } failure:^(RKObjectRequestOperation *operation, NSError *error) { - NSLog(@"REST Error: %@", error); + callback(nil); }]; [operation start]; } @@ -12,6 +12,7 @@ pod 'SDWebImage' pod 'FontAwesome+iOS' pod 'NSDate+TimeAgo' pod 'JVFloatLabeledTextField' +pod 'SVPullToRefresh' end target "JuickTests" do diff --git a/Podfile.lock b/Podfile.lock index 2aae0af..8237113 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -39,6 +39,7 @@ PODS: - SDWebImage/Core - SDWebImage/Core (3.5.1) - SOCKit (1.1) + - SVPullToRefresh (0.4.1) - SWRevealViewController (1.0.8) - TransitionKit (1.1.1) - TTTAttributedLabel (1.7.1) @@ -52,6 +53,7 @@ DEPENDENCIES: - PDKeychainBindingsController - RestKit - SDWebImage + - SVPullToRefresh - SWRevealViewController - TTTAttributedLabel @@ -68,6 +70,7 @@ SPEC CHECKSUMS: RKValueTransformers: 1562d458b9c9d59ce777bfc5982f2e1aef2e9182 SDWebImage: a408b548a634b792372e07e753fc1079aff5032a SOCKit: 2f3bc4d07910de12dcc202815e07db68a3802581 + SVPullToRefresh: 61a0e4bd12bd6f8e3465909810b0fbeb1a28d5f2 SWRevealViewController: 5688d9d017e228c9edd92db359f670d8c47ab8e6 TransitionKit: d0e3344aac92991395d4c2e72d9c5a8ceeb12910 TTTAttributedLabel: e504133915a9b11de63cb470ffa2790383a3eb23 |