summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2014-02-03 16:51:47 +0400
committerGravatar Vitaly Takmazov2014-02-03 16:51:47 +0400
commit57c8c45a4730fe7c980b8b7eadf94ca60b97db43 (patch)
tree162041af6bd2f3d8f383cf9842a356c07068f04c /Juick
parent4fd723c665a2b828447fcc9476c752803f76ea35 (diff)
Still fighting with scroll :(
Diffstat (limited to 'Juick')
-rw-r--r--Juick/LoginViewController.m2
-rw-r--r--Juick/MessageCell.h2
-rw-r--r--Juick/MessageCell.m23
-rw-r--r--Juick/MessagesViewController.h3
-rw-r--r--Juick/MessagesViewController.m94
-rw-r--r--Juick/RevealPanelViewController.m6
-rw-r--r--Juick/User.m3
7 files changed, 68 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];
}