summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/DiscoverViewController.m10
-rw-r--r--Juick/ViewControllers/MessagesViewController.m37
2 files changed, 32 insertions, 15 deletions
diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m
index 67036c6..b09e1df 100644
--- a/Juick/ViewControllers/DiscoverViewController.m
+++ b/Juick/ViewControllers/DiscoverViewController.m
@@ -56,9 +56,13 @@
[self performSegueWithIdentifier:@"threadViewSegue" sender:cell];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath];
- cell.delegate = self;
- return cell;
+ if (!self.dataLoading) {
+ MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath];
+ cell.delegate = self;
+ return cell;
+ } else {
+ return [super tableView:tableView cellForRowAtIndexPath:indexPath];
+ }
}
-(void)avatarClicked:(NSString *)uname {
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index 957fce5..3fa6642 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -29,6 +29,9 @@
-(void) refreshData:(BOOL)scrollToBottom {
self.dataLoading = YES;
+ if (self.messages.count == 0) {
+ [self.tableView reloadData];
+ }
[[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) {
NSArray *newMsgs = next;
if ([self isAtTop:self.params]) {
@@ -47,16 +50,19 @@
}
}
}
+ self.dataLoading = NO;
+ if (self.messages.count == 0) {
+ [self.tableView reloadData];
+ }
[self.messages addObjectsFromArray:newMsgs];
NSMutableArray *indexPaths = [NSMutableArray new];
for (NSUInteger index = oldCount; index <= oldCount + [newMsgs count] - 1; index++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]];
}
[self.tableView beginUpdates];
- [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];
+ [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:NO];
[self.tableView endUpdates];
[self.refreshControl endRefreshing];
- self.dataLoading = NO;
if (scrollToBottom) {
NSIndexPath *lastRow = [NSIndexPath indexPathForRow:self.messages.count - 1 inSection:0];
[self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO];
@@ -75,16 +81,15 @@
- (void)viewDidLoad
{
- [super viewDidLoad];
-
- self.dataLoading = NO;
+ self.dataLoading = YES;
[self.view setBackgroundColor:[ColorScheme mainBackground]];
[self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"messageCell"];
+ [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 500.0f;
self.messages = [NSMutableArray array];
self.refreshControl = [UIRefreshControl new];
- [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
+ [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
}
- (void) composePressed {
@@ -96,15 +101,23 @@
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.messages.count;
+ return self.dataLoading && self.messages.count == 0 ? 4 : self.messages.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- Message *msg = [self.messages objectAtIndex:indexPath.row];
- NSString * cellIdentifier = @"messageCell";
- MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
- [cell configureWithMessage:msg];
- return cell;
+ if (self.dataLoading && self.messages.count == 0) {
+ return [tableView dequeueReusableCellWithIdentifier:@"contentLoadingCell"];
+ } else {
+ Message *msg = [self.messages objectAtIndex:indexPath.row];
+ NSString * cellIdentifier = @"messageCell";
+ MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
+ [cell configureWithMessage:msg];
+ return cell;
+ }
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+ return self.dataLoading && self.messages.count == 0 ? 200.0f : [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView_ {