ResultMultiSelectionTableViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "ResultMultiSelectionTableViewController.h"
  6. #import "NCAppBranding.h"
  7. #import "NCUser.h"
  8. #import "NCAPIController.h"
  9. #import "NCDatabaseManager.h"
  10. #import "PlaceholderView.h"
  11. #import "NextcloudTalk-Swift.h"
  12. @interface ResultMultiSelectionTableViewController ()
  13. {
  14. PlaceholderView *_contactsBackgroundView;
  15. }
  16. @end
  17. @implementation ResultMultiSelectionTableViewController
  18. - (void)viewDidLoad
  19. {
  20. [super viewDidLoad];
  21. [self.tableView registerNib:[UINib nibWithNibName:kContactsTableCellNibName bundle:nil] forCellReuseIdentifier:kContactCellIdentifier];
  22. // Align header's title to ContactsTableViewCell's label
  23. self.tableView.separatorInset = UIEdgeInsetsMake(0, 72, 0, 0);
  24. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  25. // Contacts placeholder view
  26. _contactsBackgroundView = [[PlaceholderView alloc] init];
  27. [_contactsBackgroundView setImage:[UIImage imageNamed:@"contacts-placeholder"]];
  28. [_contactsBackgroundView.placeholderTextView setText:NSLocalizedString(@"No results found", nil)];
  29. [self showSearchingUI];
  30. self.tableView.backgroundView = _contactsBackgroundView;
  31. }
  32. - (void)didReceiveMemoryWarning
  33. {
  34. [super didReceiveMemoryWarning];
  35. }
  36. - (void)showSearchingUI
  37. {
  38. [self setContacts:nil withIndexes:nil];
  39. [_contactsBackgroundView.placeholderView setHidden:YES];
  40. [_contactsBackgroundView.loadingView startAnimating];
  41. [_contactsBackgroundView.loadingView setHidden:NO];
  42. }
  43. - (void)hideSearchingUI
  44. {
  45. [_contactsBackgroundView.loadingView stopAnimating];
  46. [_contactsBackgroundView.loadingView setHidden:YES];
  47. }
  48. - (void)setContacts:(NSMutableDictionary *)contacts withIndexes:(NSArray *)indexes
  49. {
  50. _contacts = contacts;
  51. _indexes = indexes;
  52. [self.tableView reloadData];
  53. }
  54. - (void)setSearchResultContacts:(NSMutableDictionary *)contacts withIndexes:(NSArray *)indexes
  55. {
  56. [self hideSearchingUI];
  57. [_contactsBackgroundView.placeholderView setHidden:(contacts.count > 0)];
  58. [self setContacts:contacts withIndexes:indexes];
  59. }
  60. #pragma mark - Table view data source
  61. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  62. return _indexes.count;
  63. }
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  65. NSString *index = [_indexes objectAtIndex:section];
  66. NSArray *contacts = [_contacts objectForKey:index];
  67. return contacts.count;
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  70. {
  71. return kContactsTableCellHeight;
  72. }
  73. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  74. {
  75. return [_indexes objectAtIndex:section];
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. NSString *index = [_indexes objectAtIndex:indexPath.section];
  80. NSArray *contacts = [_contacts objectForKey:index];
  81. NCUser *contact = [contacts objectAtIndex:indexPath.row];
  82. ContactsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kContactCellIdentifier forIndexPath:indexPath];
  83. if (!cell) {
  84. cell = [[ContactsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kContactCellIdentifier];
  85. }
  86. cell.labelTitle.text = contact.name;
  87. [cell.contactImage setActorAvatarForId:contact.userId withType:contact.source withDisplayName:contact.name withRoomToken:_room.token];
  88. UIImage *selectionImage = [UIImage systemImageNamed:@"circle"];
  89. UIColor *selectionImageColor = [UIColor tertiaryLabelColor];
  90. for (NCUser *user in _selectedParticipants) {
  91. if ([user.userId isEqualToString:contact.userId] && [user.source isEqualToString:contact.source]) {
  92. selectionImage = [UIImage systemImageNamed:@"checkmark.circle.fill"];
  93. selectionImageColor = [NCAppBranding elementColor];
  94. }
  95. }
  96. UIImageView *selectionImageView = [[UIImageView alloc] initWithImage:selectionImage];
  97. selectionImageView.tintColor = selectionImageColor;
  98. cell.accessoryView = selectionImageView;
  99. return cell;
  100. }
  101. @end