another.im-ios/Monal/shareSheet-iOS/MLSelectionController.m
2024-11-18 15:53:52 +01:00

73 lines
2.1 KiB
Objective-C

//
// MLSelectionController.m
// Monal
//
// Created by Anurodh Pokharel on 10/26/18.
// Copyright © 2018 Monal.im. All rights reserved.
//
#import "MLSelectionController.h"
#import "MLContact.h"
@interface MLSelectionController ()
@end
@implementation MLSelectionController
-(void) viewDidLoad
{
[super viewDidLoad];
}
#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
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"option" forIndexPath:indexPath];
NSDictionary* row = self.options[indexPath.row];
MLContact* contact = (MLContact*)[row objectForKey:@"contact"];
if(contact)
{
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", contact.contactDisplayName, contact.contactJid];
MLContact* selectedContact = (MLContact*)[self.selection objectForKey:@"contact"];
if([selectedContact isEqualToContact:contact])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.textLabel.text = [NSString stringWithFormat:@"%@@%@",[row objectForKey:@"username"],[row objectForKey:@"domain"]];
if([[self.selection objectForKey:@"account_id"] integerValue]==[[row objectForKey:@"account_id"] integerValue])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
-(void) tableView:(UITableView*) tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
self.selection = self.options[indexPath.row];
[tableView reloadData];
if(self.completion)
self.completion(self.selection);
}
@end