From ebbf2dda2715144d6ce800b5bd927d863ea6db02 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 8 Mar 2016 14:26:12 +0100 Subject: [PATCH] tables: highlight current selected row on ipad --- Classes/ChatConversationTableView.m | 1 + Classes/ChatsListTableView.m | 13 ++++------ Classes/ContactsListTableView.m | 30 ++++++++++++++++-------- Classes/HistoryListTableView.m | 12 +++------- Classes/HistoryListView.m | 2 +- Classes/LinphoneUI/UICheckBoxTableView.h | 2 ++ Classes/LinphoneUI/UICheckBoxTableView.m | 16 +++++++++++-- 7 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 487cfd733..a252c9f1b 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -177,6 +177,7 @@ } [cell setChatRoomDelegate:_chatRoomDelegate]; [super accessoryForCell:cell atPath:indexPath]; + cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 9af1904af..7d9e1f019 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -119,15 +119,12 @@ static void chatTable_free_chatrooms(void *data) { [super loadData]; if (IPAD) { + int idx = ms_list_index(data, VIEW(ChatConversationView).chatRoom); // if conversation view is using a chatroom that does not exist anymore, update it - if (data != NULL) { - ChatConversationView *view = VIEW(ChatConversationView); - LinphoneChatRoom *current = [view chatRoom]; - // cannot find it anymore: replace it with the first one - if (ms_list_find(data, current) == NULL) { - [view setChatRoom:(LinphoneChatRoom *)ms_list_nth_data(data, 0)]; - } - } else { + if (idx != -1) { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; + [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; + } else if (![self selectFirstRow]) { [PhoneMainView.instance changeCurrentView:ChatConversationCreateView.compositeViewDescription]; } } diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index f55c0cb93..a05139847 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -38,6 +38,16 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info ABAddressBookRegisterExternalChangeCallback(addressBook, sync_address_book, (__bridge void *)(self)); } +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + if (IPAD) { + if (![self selectFirstRow]) { + ContactDetailsView *view = VIEW(ContactDetailsView); + [view setContact:nil]; + } + } +} + - (id)init { self = [super init]; if (self) { @@ -102,7 +112,6 @@ static int ms_strcmpfuz(const char *fuzzy_word, const char *sentence) { - (void)loadData { LOGI(@"Load contact list"); @synchronized(addressBookMap) { - // Reset Address book [addressBookMap removeAllObjects]; @@ -142,16 +151,17 @@ static int ms_strcmpfuz(const char *fuzzy_word, const char *sentence) { [subDic insertObject:lPerson forKey:name selector:@selector(caseInsensitiveCompare:)]; } } - } - [super loadData]; + [super loadData]; - if (IPAD) { - // if contact details view is using a contact that does not exist anymore, update it - ContactDetailsView *view = VIEW(ContactDetailsView); - ABRecordRef contact = ([self totalNumberOfItems] > 0) - ? [self contactForIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] - : nil; - [view setContact:contact]; + // since we refresh the tableview, we must perform this on main thread + dispatch_async(dispatch_get_main_queue(), ^(void) { + if (IPAD) { + if (![self selectFirstRow]) { + ContactDetailsView *view = VIEW(ContactDetailsView); + [view setContact:nil]; + } + } + }); } } diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index 0ba85acd0..071abd4b1 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -145,16 +145,10 @@ [super loadData]; if (IPAD) { - // reset details view since in fragment mode, details are relative to current data - // select first log if any - NSString *callId = nil; - if ([self totalNumberOfItems] > 0) { - id logId = [_sections objectForKey:_sortedDays[0]][0]; - LinphoneCallLog *log = [logId pointerValue]; - callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(log) ?: ""]; + if (![self selectFirstRow]) { + HistoryDetailsView *view = VIEW(HistoryDetailsView); + [view setCallLogId:nil]; } - HistoryDetailsView *view = VIEW(HistoryDetailsView); - [view setCallLogId:callId]; } } diff --git a/Classes/HistoryListView.m b/Classes/HistoryListView.m index 06bb528be..5d924a4ee 100644 --- a/Classes/HistoryListView.m +++ b/Classes/HistoryListView.m @@ -81,7 +81,7 @@ static UICompositeViewDescription *compositeDescription = nil; _selectedButtonImage.frame = frame; } -#pragma mark - Action Functions +#pragma m ~ark - Action Functions - (IBAction)onAllClick:(id)event { [self changeView:History_All]; diff --git a/Classes/LinphoneUI/UICheckBoxTableView.h b/Classes/LinphoneUI/UICheckBoxTableView.h index d8d114375..a524ce1ba 100644 --- a/Classes/LinphoneUI/UICheckBoxTableView.h +++ b/Classes/LinphoneUI/UICheckBoxTableView.h @@ -23,6 +23,8 @@ - (void)accessoryForCell:(UITableViewCell *)cell atPath:(NSIndexPath *)indexPath; - (void)removeSelectionUsing:(void (^)(NSIndexPath *indexPath))remover; +- (BOOL)selectFirstRow; + - (IBAction)onSelectionToggle:(id)sender; - (IBAction)onEditClick:(id)sender; - (IBAction)onCancelClick:(id)sender; diff --git a/Classes/LinphoneUI/UICheckBoxTableView.m b/Classes/LinphoneUI/UICheckBoxTableView.m index 506fd901d..9d961108d 100644 --- a/Classes/LinphoneUI/UICheckBoxTableView.m +++ b/Classes/LinphoneUI/UICheckBoxTableView.m @@ -36,6 +36,19 @@ #pragma mark - UITableViewDelegate Functions +- (BOOL)selectFirstRow { + // reset details view in fragment mode + if ([self totalNumberOfItems] > 0) { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; + [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; + [self tableView:self.tableView didSelectRowAtIndexPath:indexPath]; + _emptyView.hidden = YES; + } else { + _emptyView.hidden = NO; + } + return _emptyView.hidden; +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; _emptyView.hidden = _editButton.enabled = ([self totalNumberOfItems] != 0); @@ -43,7 +56,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; - [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO]; if ([_selectedItems containsObject:indexPath]) { [_selectedItems removeObject:indexPath]; } else { @@ -64,7 +76,7 @@ #pragma mark - - (void)accessoryForCell:(UITableViewCell *)cell atPath:(NSIndexPath *)indexPath { - cell.selectionStyle = UITableViewCellSelectionStyleNone; + cell.selectionStyle = UITableViewCellSelectionStyleGray; if ([self isEditing]) { UIButton *checkBoxButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = nil;