From 9d2b52bb9ee096c546028bd0257944cade21ab4e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 15 Aug 2016 01:24:24 +0300 Subject: DFImageManager --- Juick/Juick-Prefix.pch | 4 ++-- Juick/MessagesViewController.m | 38 +++++++++++++++++--------------------- Juick/RevealPanelViewController.h | 1 - Juick/Views/MessageCell.m | 2 +- 4 files changed, 20 insertions(+), 25 deletions(-) (limited to 'Juick') diff --git a/Juick/Juick-Prefix.pch b/Juick/Juick-Prefix.pch index 42ff0f3..7836550 100644 --- a/Juick/Juick-Prefix.pch +++ b/Juick/Juick-Prefix.pch @@ -15,10 +15,10 @@ #import #import #import - #import - #import + #import #import "NSString+HTML.h" #import "UIImage+Utils.h" #import "NSDate+TimeAgo.h" #import "TTTAttributedLabel.h" + #import #endif diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index fe2c14d..91833e1 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -6,8 +6,6 @@ // Copyright (c) 2013 com.juick. All rights reserved. // -#import "SWRevealViewController.h" - #import "MessagesViewController.h" #import "MessageCell.h" @@ -44,6 +42,9 @@ static NSString *CellIdentifier = @"MessageCell"; } - (void) refreshData { + if ([self.path isEqualToString:[Message threadUrl]]) { + [self.messages removeAllObjects]; + } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.dataLoading = YES; [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) { @@ -77,19 +78,7 @@ static NSString *CellIdentifier = @"MessageCell"; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; self.refreshControl = [UIRefreshControl new]; - [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; - __weak MessagesViewController * weakSelf = self; - [self.tableView addInfiniteScrollWithHandler:^(UITableView * _Nonnull tableView) { - if ([weakSelf.path isEqualToString:[Message threadUrl]]) { - [weakSelf.messages removeAllObjects]; - } else { - NSNumber *lastMid = ((Message *)[weakSelf.messages lastObject]).MID; - [weakSelf.params setValue:lastMid forKey:@"before_mid"]; - } - [weakSelf refreshData]; - [weakSelf.tableView finishInfiniteScroll]; - }]; -} + [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];} - (void) composePressed { CATransition* transition = [CATransition animation]; @@ -140,12 +129,7 @@ static NSString *CellIdentifier = @"MessageCell"; 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:^(NSInteger receivedSize, NSInteger expectedSize) { - // <#code#> - } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { - [cell.attach setImage:[UIImage imageWithImage:image convertToWidth:300.0f]]; - }]; + [cell.attach df_setImageWithResource:[NSURL URLWithString:msg.attach]]; } else { cell.attach.image = nil; } @@ -170,5 +154,17 @@ static NSString *CellIdentifier = @"MessageCell"; self.navigationItem.leftBarButtonItem = barButtonItem; } +-(void)scrollViewDidScroll:(UIScrollView *)scrollView_ { + CGFloat actualPosition = scrollView_.contentOffset.y; + CGFloat contentHeight = scrollView_.contentSize.height - scrollView_.contentSize.height / 2; + if (actualPosition >= contentHeight && !self.dataLoading) { + NSNumber *lastMid = ((Message *)[self.messages lastObject]).MID; + if (![self.path isEqualToString:[Message threadUrl]]) { + [self.params setValue:lastMid forKey:@"before_mid"]; + } + [self refreshData]; + } +} + @end diff --git a/Juick/RevealPanelViewController.h b/Juick/RevealPanelViewController.h index 0300274..ff5006c 100644 --- a/Juick/RevealPanelViewController.h +++ b/Juick/RevealPanelViewController.h @@ -9,7 +9,6 @@ #import #import #import "LoginViewController.h" -#import @interface RevealPanelViewController : UIViewController @property (nonatomic, strong) IBOutlet UITableView *tableView; diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index 8759e63..65565a8 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -23,7 +23,7 @@ - (void) setMessage:(Message *)msg { _message = msg; - [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.userID intValue]]] placeholderImage:[UIImage imageNamed:@"0.png"] options:SDWebImageContinueInBackground]; + [self.avatar df_setImageWithResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.userID intValue]]]]; self.title.text = msg.user; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; -- cgit v1.2.3