Disable the Play button until version list finished loading Disable ability to go back while a version is downloading Display loading alert while logging in
83 lines
2.8 KiB
Objective-C
83 lines
2.8 KiB
Objective-C
#import "FileListViewController.h"
|
|
|
|
@interface FileListViewController () {
|
|
}
|
|
|
|
@property(nonatomic, strong) NSMutableArray *fileList;
|
|
|
|
@end
|
|
|
|
@implementation FileListViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
if (self.fileList == nil) {
|
|
self.fileList = [NSMutableArray array];
|
|
} else {
|
|
[self.fileList removeAllObjects];
|
|
}
|
|
|
|
// List accounts
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
NSArray *files = [fm contentsOfDirectoryAtPath:self.listPath error:nil];
|
|
for(NSString *file in files) {
|
|
NSString *path = [self.listPath stringByAppendingPathComponent:file];
|
|
BOOL isDir = NO;
|
|
[fm fileExistsAtPath:path isDirectory:(&isDir)];
|
|
if(!isDir && [file hasSuffix:@".json"]) {
|
|
[self.fileList addObject:[file stringByDeletingPathExtension]];
|
|
}
|
|
}
|
|
|
|
CGRect screenBounds = [[UIScreen mainScreen] bounds];
|
|
|
|
int width = (int) roundf(screenBounds.size.width);
|
|
int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height;
|
|
|
|
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return [self.fileList count];
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
NSString *simpleTableIdentifier = @"cell";
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
|
|
|
|
if (cell == nil) {
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
|
|
}
|
|
|
|
cell.textLabel.text = [self.fileList objectAtIndex:indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
NSString *str = [self.fileList objectAtIndex:indexPath.row];
|
|
self.whenItemSelected(str);
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
// TODO: invalidate token
|
|
|
|
NSString *str = [self.fileList objectAtIndex:indexPath.row];
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
NSString *path = [NSString stringWithFormat:@"%@/%@.json", self.listPath, str];
|
|
if (self.whenDelete != nil) {
|
|
self.whenDelete(path);
|
|
}
|
|
[fm removeItemAtPath:path error:nil];
|
|
[self.fileList removeObjectAtIndex:indexPath.row];
|
|
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
|
}
|
|
}
|
|
|
|
@end
|