DetailedOptionsSelectorTableViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "DetailedOptionsSelectorTableViewController.h"
  6. #import "NCAppBranding.h"
  7. #import "NextcloudTalk-Swift.h"
  8. @interface DetailedOptionsSelectorTableViewController ()
  9. @end
  10. @implementation DetailedOption
  11. @end
  12. @implementation DetailedOptionsSelectorTableViewController
  13. - (instancetype)initWithOptions:(NSArray *)options forSenderIdentifier:(NSString *)senderId andStyle:(UITableViewStyle)style
  14. {
  15. self = [super initWithStyle:style];
  16. self.options = options;
  17. self.senderId = senderId;
  18. self.type = DetailedOptionsSelectorTypeDefault;
  19. return self;
  20. }
  21. - (instancetype)initWithAccounts:(NSArray *)accounts andStyle:(UITableViewStyle)style
  22. {
  23. self = [super initWithStyle:style];
  24. self.options = accounts;
  25. self.type = DetailedOptionsSelectorTypeAccounts;
  26. return self;
  27. }
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. [self.navigationController.navigationBar setTitleTextAttributes:
  32. @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
  33. self.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
  34. self.navigationController.navigationBar.barTintColor = [NCAppBranding themeColor];
  35. self.tabBarController.tabBar.tintColor = [NCAppBranding themeColor];
  36. self.navigationController.navigationBar.translucent = NO;
  37. UIColor *themeColor = [NCAppBranding themeColor];
  38. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  39. [appearance configureWithOpaqueBackground];
  40. appearance.backgroundColor = themeColor;
  41. appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]};
  42. self.navigationItem.standardAppearance = appearance;
  43. self.navigationItem.compactAppearance = appearance;
  44. self.navigationItem.scrollEdgeAppearance = appearance;
  45. UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
  46. target:self action:@selector(cancelButtonPressed)];
  47. self.navigationController.navigationBar.topItem.leftBarButtonItem = cancelButton;
  48. }
  49. #pragma mark - Table view data source
  50. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  51. {
  52. return 1;
  53. }
  54. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  55. {
  56. return self.options.count;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. DetailedOption *option = [_options objectAtIndex:indexPath.row];
  61. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"DetailOptionIdentifier"];
  62. if (_type == DetailedOptionsSelectorTypeAccounts) {
  63. [cell.imageView setImage:[NCUtils renderAspectImageWithImage:option.image ofSize:CGSizeMake(20, 20) centerImage:YES]];
  64. [cell.detailTextLabel setText:[option.subtitle stringByReplacingOccurrencesOfString:@"https://" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [option.subtitle length])]];
  65. [cell.detailTextLabel setTextColor:[UIColor secondaryLabelColor]];
  66. } else {
  67. [cell.imageView setImage:option.image];
  68. cell.detailTextLabel.text = option.subtitle;
  69. }
  70. cell.textLabel.text = option.title;
  71. cell.detailTextLabel.numberOfLines = 0;
  72. [cell.detailTextLabel sizeToFit];
  73. cell.accessoryType = option.selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  74. return cell;
  75. }
  76. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  77. {
  78. DetailedOption *option = [_options objectAtIndex:indexPath.row];
  79. [self.delegate detailedOptionsSelector:self didSelectOptionWithIdentifier:option];
  80. }
  81. - (void)cancelButtonPressed
  82. {
  83. [self.delegate detailedOptionsSelectorWasCancelled:self];
  84. }
  85. @end