From 78d6e25f674d083466e32051c26e8ee5ea840afe Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 7 Dec 2013 14:54:04 +0400 Subject: fix constraints --- Juick/AppDelegate.m | 2 ++ Juick/AttachPlaceholder.png | Bin 15565 -> 0 bytes Juick/AttachPlaceholder@2x.png | Bin 0 -> 15565 bytes Juick/MessageCell.m | 34 ++++++++++++++++------------------ Juick/MessagesViewController.m | 30 ++++++++++-------------------- 5 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 Juick/AttachPlaceholder.png create mode 100644 Juick/AttachPlaceholder@2x.png (limited to 'Juick') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 874ea94..a776b43 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -28,6 +28,8 @@ // make the status bar white [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; + AFNetworkActivityIndicatorManager.sharedManager.enabled = YES; + MessagesViewController *messages = [[MessagesViewController alloc] init]; RevealPanelViewController *rear = [[RevealPanelViewController alloc] init]; diff --git a/Juick/AttachPlaceholder.png b/Juick/AttachPlaceholder.png deleted file mode 100644 index 94e8c32..0000000 Binary files a/Juick/AttachPlaceholder.png and /dev/null differ diff --git a/Juick/AttachPlaceholder@2x.png b/Juick/AttachPlaceholder@2x.png new file mode 100644 index 0000000..94e8c32 Binary files /dev/null and b/Juick/AttachPlaceholder@2x.png differ diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m index 0777dfd..3f06436 100644 --- a/Juick/MessageCell.m +++ b/Juick/MessageCell.m @@ -9,6 +9,7 @@ #import "MessageCell.h" #import "ColorsAndButtons.h" #import "Masonry.h" +#import "JMImageCache.h" @interface MessageCell () @@ -23,12 +24,10 @@ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self setBackgroundColor:[UIColor whiteColor]]; - self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; [self.avatar setBackgroundColor:[UIColor clearColor]]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.titleLabel setNumberOfLines:1]; [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; @@ -36,7 +35,6 @@ [self.titleLabel setBackgroundColor:[UIColor clearColor]]; self.timestampLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.timestampLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.timestampLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.timestampLabel setNumberOfLines:1]; [self.timestampLabel setTextAlignment:NSTextAlignmentLeft]; @@ -46,7 +44,6 @@ self.bodyLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; self.bodyLabel.dataDetectorTypes = NSTextCheckingTypeLink; self.bodyLabel.delegate = self; - [self.bodyLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.bodyLabel setNumberOfLines:0]; @@ -94,41 +91,42 @@ [self.avatar makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.top).with.offset(padding.top); - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.width.equalTo(@32); make.height.equalTo(@32); }]; [self.titleLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.avatar.trailing).with.offset(padding.right); + make.left.equalTo(self.avatar.right).with.offset(padding.right); make.top.equalTo(self.contentView.top).with.offset(padding.top); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); }]; [self.timestampLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.avatar.trailing).with.offset(padding.left); + make.left.equalTo(self.avatar.right).with.offset(padding.left); make.top.equalTo(self.titleLabel.bottom).with.offset(padding.top /2); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); + make.bottom.equalTo(self.bodyLabel.top).with.offset(-padding.bottom); }]; - [self.bodyLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.top.equalTo(self.timestampLabel.bottom).with.offset(padding.top); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); make.bottom.equalTo(self.attach.top).with.offset(-padding.bottom); }]; [self.attach makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.bottom.equalTo(self.summaryLabel.top).with.offset(-padding.bottom); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); make.top.equalTo(self.bodyLabel.bottom).with.offset(padding.top); }]; [self.summaryLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.bottom.equalTo(self.contentView.bottom).with.offset(-padding.bottom); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); + make.top.equalTo(self.attach.bottom).with.offset(padding.top); }]; @@ -148,7 +146,7 @@ } - (void) bind:(Message *)msg { - [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]]]; + [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%d.png", [msg.userID intValue]]]]; self.titleLabel.text = msg.user; self.timestampLabel.text = msg.timestamp; @@ -167,7 +165,7 @@ [msg.text stringByDecodingHTMLEntities]]; } if ([msg.attach length] > 0) { - [self.attach setImageWithURL:[NSURL URLWithString:msg.attach]]; + [self.attach setImageWithURL:[NSURL URLWithString:msg.attach] key:[NSString stringWithFormat:@"%d", [msg.MID intValue]] placeholder:[UIImage imageNamed:@"AttachPlaceholder.png"]]; } else { self.attach.image = nil; } diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index 7369bd9..4beeb1c 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -18,7 +18,6 @@ #import "NSURL+PathParameters.h" -#import static NSString *CellIdentifier = @"MessageCell"; @@ -43,14 +42,8 @@ static NSString *CellIdentifier = @"MessageCell"; [self.messages removeAllObjects]; [self.tableView reloadData]; [Message pullNextFromURL:self.url callback:^(NSArray *next) { - [self.tableView beginUpdates]; - CGPoint offset = self.tableView.contentOffset; - for (int i = 0; i < [next count]; i++) { - [self.messages addObject:[next objectAtIndex:i]]; - [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.messages.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; - } - [self.tableView setContentOffset:offset animated:NO]; - [self.tableView endUpdates]; + [self.messages addObjectsFromArray:next]; + [self.tableView reloadData]; [refresh endRefreshing]; }]; } @@ -61,7 +54,7 @@ static NSString *CellIdentifier = @"MessageCell"; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - if (self.url.absoluteString == [Message threadUrl]) { + if ([self.url.absoluteString hasPrefix:[Message threadUrl]]) { return; } CGPoint pos = scrollView.contentOffset; @@ -72,14 +65,11 @@ static NSString *CellIdentifier = @"MessageCell"; Message * lastMessage = [self.messages lastObject]; NSURL *beforeUrl = [self.url URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:lastMessage.MID, @"before_mid", nil]]; [Message pullNextFromURL:beforeUrl callback:^(NSArray *next) { - [self.tableView beginUpdates]; - for (int i = 0; i < [next count]; i++) { - [self.messages addObject:[next objectAtIndex:i]]; - [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.messages.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; - } - [self.tableView setContentOffset:pos animated:NO]; - [self.tableView endUpdates]; - self.dataLoading = NO; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.messages addObjectsFromArray:next]; + [self.tableView reloadData]; + self.dataLoading = NO; + }); }]; }); @@ -184,7 +174,7 @@ static NSString *CellIdentifier = @"MessageCell"; - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 100.0f; + return 500.0f; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -192,7 +182,7 @@ static NSString *CellIdentifier = @"MessageCell"; return; Message *msg = [_messages objectAtIndex:indexPath.row]; MessagesViewController *threadViewController = [[MessagesViewController alloc] init]; - [threadViewController loadFromURL:[[NSURL URLWithString:[Message threadUrl]] URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:msg.MID, @"mid", nil]] withTitle:[NSString stringWithFormat:@"#%@", msg.MID]]; + [threadViewController loadFromURL:[[NSURL URLWithString:[Message threadUrl]] URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:msg.MID, @"mid", nil]] withTitle:@"Thread"]; [self.navigationController pushViewController:threadViewController animated:NO]; } -- cgit v1.2.3