diff --git a/Riot/Modules/People/PeopleViewController.m b/Riot/Modules/People/PeopleViewController.m index 0193efaec..d7a0a399c 100644 --- a/Riot/Modules/People/PeopleViewController.m +++ b/Riot/Modules/People/PeopleViewController.m @@ -461,4 +461,53 @@ [super searchBarCancelButtonClicked:searchBar]; } +#pragma mark - Empty view management + +- (void)updateEmptyView +{ + [self.emptyView fillWith:[UIImage imageNamed:@"people_empty_screen_artwork"] + title:NSLocalizedStringFromTable(@"people_empty_view_title", @"Vector", nil) + informationText:NSLocalizedStringFromTable(@"people_empty_view_information", @"Vector", nil)]; +} + +- (BOOL)shouldShowEmptyView +{ + return [self totalItemCounts] == 0; +} + +// Total items to display on the screen +- (NSUInteger)totalItemCounts +{ + return recentsDataSource.invitesCellDataArray.count + + recentsDataSource.conversationCellDataArray.count + + recentsDataSource.peopleCellDataArray.count + + [self numberOfContactsInContactsDataSource]; +} + +- (NSUInteger)numberOfContactsInContactsDataSource +{ + BOOL areLocalContactsAccessAuthorized = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized; + + NSInteger nbOfItemsInContactDataSource = 0; + + for (NSInteger i = 0; i < contactsSectionNumber; i++) + { + nbOfItemsInContactDataSource += [contactsDataSource tableView:self.recentsTableView numberOfRowsInSection:i]; + } + + NSInteger numberOfContactsInContactsDataSource; + + // No local contacts to show and no search in directory + if (!areLocalContactsAccessAuthorized && contactsSectionNumber == 1 && nbOfItemsInContactDataSource <= 1) + { + numberOfContactsInContactsDataSource = 0; + } + else + { + numberOfContactsInContactsDataSource = nbOfItemsInContactDataSource; + } + + return numberOfContactsInContactsDataSource; +} + @end