tables: highlight current selected row on ipad

This commit is contained in:
Gautier Pelloux-Prayer 2016-03-08 14:26:12 +01:00
parent 10e3c16613
commit ebbf2dda27
7 changed files with 46 additions and 30 deletions

View file

@ -177,6 +177,7 @@
}
[cell setChatRoomDelegate:_chatRoomDelegate];
[super accessoryForCell:cell atPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

View file

@ -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];
}
}

View file

@ -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];
}
}
});
}
}

View file

@ -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];
}
}

View file

@ -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];

View file

@ -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;

View file

@ -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;