123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
- #import "DetailedOptionsSelectorTableViewController.h"
- #import "NCAppBranding.h"
- #import "NextcloudTalk-Swift.h"
- @interface DetailedOptionsSelectorTableViewController ()
- @end
- @implementation DetailedOption
- @end
- @implementation DetailedOptionsSelectorTableViewController
- - (instancetype)initWithOptions:(NSArray *)options forSenderIdentifier:(NSString *)senderId andStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- self.options = options;
- self.senderId = senderId;
- self.type = DetailedOptionsSelectorTypeDefault;
- return self;
- }
- - (instancetype)initWithAccounts:(NSArray *)accounts andStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- self.options = accounts;
- self.type = DetailedOptionsSelectorTypeAccounts;
-
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- [self.navigationController.navigationBar setTitleTextAttributes:
- @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
- self.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
- self.navigationController.navigationBar.barTintColor = [NCAppBranding themeColor];
- self.tabBarController.tabBar.tintColor = [NCAppBranding themeColor];
- self.navigationController.navigationBar.translucent = NO;
- UIColor *themeColor = [NCAppBranding themeColor];
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- [appearance configureWithOpaqueBackground];
- appearance.backgroundColor = themeColor;
- appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]};
- self.navigationItem.standardAppearance = appearance;
- self.navigationItem.compactAppearance = appearance;
- self.navigationItem.scrollEdgeAppearance = appearance;
-
- UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
- target:self action:@selector(cancelButtonPressed)];
- self.navigationController.navigationBar.topItem.leftBarButtonItem = cancelButton;
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.options.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- DetailedOption *option = [_options objectAtIndex:indexPath.row];
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"DetailOptionIdentifier"];
- if (_type == DetailedOptionsSelectorTypeAccounts) {
- [cell.imageView setImage:[NCUtils renderAspectImageWithImage:option.image ofSize:CGSizeMake(20, 20) centerImage:YES]];
- [cell.detailTextLabel setText:[option.subtitle stringByReplacingOccurrencesOfString:@"https://" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [option.subtitle length])]];
- [cell.detailTextLabel setTextColor:[UIColor secondaryLabelColor]];
- } else {
- [cell.imageView setImage:option.image];
- cell.detailTextLabel.text = option.subtitle;
- }
- cell.textLabel.text = option.title;
- cell.detailTextLabel.numberOfLines = 0;
- [cell.detailTextLabel sizeToFit];
- cell.accessoryType = option.selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- DetailedOption *option = [_options objectAtIndex:indexPath.row];
- [self.delegate detailedOptionsSelector:self didSelectOptionWithIdentifier:option];
- }
- - (void)cancelButtonPressed
- {
- [self.delegate detailedOptionsSelectorWasCancelled:self];
- }
- @end
|