TrollStore/Store/TSAppTableViewController.m

70 lines
2.1 KiB
Mathematica
Raw Normal View History

2022-09-02 23:19:48 +08:00
#import "TSAppTableViewController.h"
#import "TSApplicationsManager.h"
@implementation TSAppTableViewController
- (void)reloadTable
{
2022-09-03 09:08:59 +08:00
dispatch_async(dispatch_get_main_queue(), ^
{
[self.tableView reloadData];
});
2022-09-02 23:19:48 +08:00
}
- (void)loadView
{
[super loadView];
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"ApplicationCell"];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable)
name:@"ApplicationsChanged"
object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.allowsMultipleSelectionDuringEditing = NO;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[TSApplicationsManager sharedInstance] installedAppPaths].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApplicationCell" forIndexPath:indexPath];
NSString* appPath = [[TSApplicationsManager sharedInstance] installedAppPaths][indexPath.row];
// Configure the cell...
cell.textLabel.text = [[TSApplicationsManager sharedInstance] displayNameForAppPath:appPath];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSString* appPath = [[TSApplicationsManager sharedInstance] installedAppPaths][indexPath.row];
NSString* appId = [[TSApplicationsManager sharedInstance] appIdForAppPath:appPath];
2022-09-04 21:37:49 +08:00
if(appId)
{
[[TSApplicationsManager sharedInstance] uninstallApp:appId];
}
else
{
[[TSApplicationsManager sharedInstance] uninstallAppByPath:appPath];
}
2022-09-02 23:19:48 +08:00
}
}
@end