summaryrefslogtreecommitdiff
path: root/Juick/MessagesViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/MessagesViewController.m')
-rw-r--r--Juick/MessagesViewController.m38
1 files changed, 17 insertions, 21 deletions
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