shlist

share and manage lists between multiple people
Log | Files | Refs

commit 3cdd0ec015130c97c175e9382a91bca5cb143815
parent 6964f7f7dab7c07c2a2b35e0db01aa777147be66
Author: Kyle Milz <kyle@Kyles-MacBook-Pro.local>
Date:   Sun, 20 Sep 2015 00:53:12 -0600

ios: make new list message only update gui when network request returns

Diffstat:
Mios-ng/shlist/MainTableViewController.h | 1+
Mios-ng/shlist/MainTableViewController.m | 39+++++++++++++++++++++------------------
Mios-ng/shlist/Network.m | 18+++++++++++++++++-
3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/ios-ng/shlist/MainTableViewController.h b/ios-ng/shlist/MainTableViewController.h @@ -7,6 +7,7 @@ @property NSMutableArray *shared_lists; @property NSMutableArray *indirect_lists; +- (void) finished_new_list_request:(SharedList *) shlist; - (void) finished_join_list_request:(SharedList *) shlist; - (void) finished_leave_list_request:(SharedList *) shlist; diff --git a/ios-ng/shlist/MainTableViewController.m b/ios-ng/shlist/MainTableViewController.m @@ -13,24 +13,6 @@ @implementation MainTableViewController -- (IBAction) unwindToList:(UIStoryboardSegue *)segue -{ - NewListViewController *source = [segue sourceViewController]; - SharedList *list = source.shared_list; - - if (list == nil) { - return; - } - - [self.shared_lists addObject:list]; - [self.tableView reloadData]; - - // send new list message with new list name as payload - NSData *payload = [list.name dataUsingEncoding:NSUTF8StringEncoding]; - [_server send_message:1 contents:payload]; - - NSLog(@"unwindToList(): done"); -} - (void) viewDidLoad { @@ -76,6 +58,27 @@ return 0; } +// new list dialogue has been cancelled or saved +- (IBAction) unwindToList:(UIStoryboardSegue *)segue +{ + NewListViewController *source = [segue sourceViewController]; + SharedList *list = source.shared_list; + + if (list == nil) { + return; + } + + // good to save + NSData *payload = [list.name dataUsingEncoding:NSUTF8StringEncoding]; + [_server send_message:1 contents:payload]; +} + +- (void) finished_new_list_request:(SharedList *) shlist +{ + [self.shared_lists addObject:shlist]; + [self.tableView reloadData]; +} + // major thing here is join list requests - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath diff --git a/ios-ng/shlist/Network.m b/ios-ng/shlist/Network.m @@ -379,7 +379,23 @@ } if (msg_type == 1) { - NSLog(@"info: got new list response, not doing anything with it"); + NSArray *fields = [msg_string componentsSeparatedByString:@"\0"]; + + if ([fields count] != 2) { + NSLog(@"warn: network: new list response has invalid number of fields %i", + [fields count]); + return; + } + + SharedList *shlist = [[SharedList alloc] init]; + shlist.id = [[fields objectAtIndex:0] dataUsingEncoding:NSUTF8StringEncoding]; + shlist.name = [fields objectAtIndex:1]; + shlist.members = @"You"; + shlist.items_ready = 0; + shlist.items_total = 0; + + NSLog(@"info: network: new list response for '%@'", shlist.name); + [shlist_tvc finished_new_list_request:shlist]; } if (msg_type == 3) {