diff options
author | Vitaly Takmazov | 2013-11-07 14:06:59 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2013-11-07 14:06:59 +0400 |
commit | 508ba6b17f37e60af73fe5e5168b3d0b88ddd085 (patch) | |
tree | d4f8f269b95bf7232d09521c02e7920b238a9835 /Juick/MessagesViewController.m | |
parent | ff23c4eb5d382d25c2e4779e0ea8f4b724651105 (diff) |
using RestKit
Diffstat (limited to 'Juick/MessagesViewController.m')
-rw-r--r-- | Juick/MessagesViewController.m | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index 6c594ba..fa53875 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -42,11 +42,7 @@ static NSString *CellIdentifier = @"MessageCell"; - (void) refreshData:(UIRefreshControl *)refresh { [self.messages removeAllObjects]; [self.tableView reloadData]; - - NSArray *next = [Message pullNextFromURL:self.url]; - int64_t delayInSeconds = 1.0; - dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (delayInSeconds * NSEC_PER_SEC)); - dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + [Message pullNextFromURL:self.url callback:^(NSArray *next) { [self.tableView beginUpdates]; CGPoint offset = self.tableView.contentOffset; for (int i = 0; i < [next count]; i++) { @@ -56,7 +52,7 @@ static NSString *CellIdentifier = @"MessageCell"; [self.tableView setContentOffset:offset animated:NO]; [self.tableView endUpdates]; [refresh endRefreshing]; - }); + }]; } - (UIStatusBarStyle)preferredStatusBarStyle @@ -71,10 +67,8 @@ static NSString *CellIdentifier = @"MessageCell"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.dataLoading = YES; Message * lastMessage = [self.messages lastObject]; - NSArray *next = [Message pullNextFromURL:[self.url URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:lastMessage.MID, @"before_mid", nil]]]; - int64_t delayInSeconds = 1.0; - dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (delayInSeconds * NSEC_PER_SEC)); - dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + 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]]; @@ -83,7 +77,7 @@ static NSString *CellIdentifier = @"MessageCell"; [self.tableView setContentOffset:pos animated:NO]; [self.tableView endUpdates]; self.dataLoading = NO; - }); + }]; }); } @@ -167,7 +161,11 @@ static NSString *CellIdentifier = @"MessageCell"; }]; cell.titleLabel.text = msg.user; cell.titleLabel.textColor = [ColorsAndButtons linkColor]; - cell.bodyLabel.text = msg.text; + cell.bodyLabel.text = [msg.text stringByDecodingHTMLEntities]; + if ([msg.tags count] > 0) { + cell.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], + [msg.text stringByDecodingHTMLEntities]]; + } [cell setBackgroundColor:[UIColor whiteColor]]; [cell setNeedsUpdateConstraints]; return cell; @@ -187,8 +185,11 @@ static NSString *CellIdentifier = @"MessageCell"; }]; cell.titleLabel.text = msg.user; - cell.bodyLabel.text = msg.text; - + cell.bodyLabel.text = [msg.text stringByDecodingHTMLEntities]; + if ([msg.tags count] > 0) { + cell.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], + [msg.text stringByDecodingHTMLEntities]]; + } cell.bodyLabel.preferredMaxLayoutWidth = tableView.bounds.size.width - (kLabelHorizontalInsets * 2.0f); [cell setNeedsUpdateConstraints]; |