123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /**
- * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
- #import "ResultMultiSelectionTableViewController.h"
- #import "NCAppBranding.h"
- #import "NCUser.h"
- #import "NCAPIController.h"
- #import "NCDatabaseManager.h"
- #import "PlaceholderView.h"
- #import "NextcloudTalk-Swift.h"
- @interface ResultMultiSelectionTableViewController ()
- {
- PlaceholderView *_contactsBackgroundView;
- }
- @end
- @implementation ResultMultiSelectionTableViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self.tableView registerNib:[UINib nibWithNibName:kContactsTableCellNibName bundle:nil] forCellReuseIdentifier:kContactCellIdentifier];
- // Align header's title to ContactsTableViewCell's label
- self.tableView.separatorInset = UIEdgeInsetsMake(0, 72, 0, 0);
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- // Contacts placeholder view
- _contactsBackgroundView = [[PlaceholderView alloc] init];
- [_contactsBackgroundView setImage:[UIImage imageNamed:@"contacts-placeholder"]];
- [_contactsBackgroundView.placeholderTextView setText:NSLocalizedString(@"No results found", nil)];
- [self showSearchingUI];
- self.tableView.backgroundView = _contactsBackgroundView;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- - (void)showSearchingUI
- {
- [self setContacts:nil withIndexes:nil];
- [_contactsBackgroundView.placeholderView setHidden:YES];
- [_contactsBackgroundView.loadingView startAnimating];
- [_contactsBackgroundView.loadingView setHidden:NO];
- }
- - (void)hideSearchingUI
- {
- [_contactsBackgroundView.loadingView stopAnimating];
- [_contactsBackgroundView.loadingView setHidden:YES];
- }
- - (void)setContacts:(NSMutableDictionary *)contacts withIndexes:(NSArray *)indexes
- {
- _contacts = contacts;
- _indexes = indexes;
- [self.tableView reloadData];
- }
- - (void)setSearchResultContacts:(NSMutableDictionary *)contacts withIndexes:(NSArray *)indexes
- {
- [self hideSearchingUI];
- [_contactsBackgroundView.placeholderView setHidden:(contacts.count > 0)];
- [self setContacts:contacts withIndexes:indexes];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return _indexes.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSString *index = [_indexes objectAtIndex:section];
- NSArray *contacts = [_contacts objectForKey:index];
- return contacts.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return kContactsTableCellHeight;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- {
- return [_indexes objectAtIndex:section];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *index = [_indexes objectAtIndex:indexPath.section];
- NSArray *contacts = [_contacts objectForKey:index];
- NCUser *contact = [contacts objectAtIndex:indexPath.row];
- ContactsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kContactCellIdentifier forIndexPath:indexPath];
- if (!cell) {
- cell = [[ContactsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kContactCellIdentifier];
- }
-
- cell.labelTitle.text = contact.name;
-
- [cell.contactImage setActorAvatarForId:contact.userId withType:contact.source withDisplayName:contact.name withRoomToken:_room.token];
- UIImage *selectionImage = [UIImage systemImageNamed:@"circle"];
- UIColor *selectionImageColor = [UIColor tertiaryLabelColor];
- for (NCUser *user in _selectedParticipants) {
- if ([user.userId isEqualToString:contact.userId] && [user.source isEqualToString:contact.source]) {
- selectionImage = [UIImage systemImageNamed:@"checkmark.circle.fill"];
- selectionImageColor = [NCAppBranding elementColor];
- }
- }
- UIImageView *selectionImageView = [[UIImageView alloc] initWithImage:selectionImage];
- selectionImageView.tintColor = selectionImageColor;
- cell.accessoryView = selectionImageView;
-
- return cell;
- }
- @end
|