This repository was archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBMRepackTableViewController.xm
More file actions
112 lines (97 loc) · 5.27 KB
/
BMRepackTableViewController.xm
File metadata and controls
112 lines (97 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#import "Headers/Batchomatic.h"
#import "Headers/BMRepackTableViewController.h"
@implementation BMRepackTableViewController //The Repack deb screen
- (void)viewDidLoad {
[super viewDidLoad];
Batchomatic *bm = [Batchomatic sharedInstance];
bm.bm_BMRepackTableViewController = self;
self.navigationItem.title = @"Batchomatic";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(didTapBackButton)];
if (bm.currentlyInstalledTweaks) {
[self createTableView];
}
else {
[self placeActivityIndicator];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[Batchomatic sharedInstance].bm_currentBMController = self;
}
- (void)placeActivityIndicator {
UIActivityIndicatorView *spinner;
if (@available(iOS 13, *)) {
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
}
else {
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
}
Batchomatic *bm = [Batchomatic sharedInstance];
if (bm.packageManager == 2 && [%c(ZBDevice) darkModeEnabled]) {
spinner.color = [UIColor colorWithRed:0.557 green:0.557 blue:0.576 alpha:1];
}
spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); //center the UIActivityIndicator
CGFloat height = (CGRectGetHeight(self.view.bounds) / 2) - self.navigationController.navigationBar.frame.size.height;
spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2, height);
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
self.spinner = spinner;
}
- (void)createTableView {
[self.spinner stopAnimating];
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height);
UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
[tableView registerClass:[UITableViewCell self] forCellReuseIdentifier:@"Cell"];
tableView.dataSource = self;
tableView.delegate = self;
self.tableView = tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[Batchomatic sharedInstance].currentlyInstalledTweaks count];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { //Hide the cell separator lines of extraneous/unused cells
return [[UIView alloc] init];
}
//--------------------------------------------------------------------------------------------------------------------------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell || !cell.detailTextLabel) { //in order to make detailTextLabel work, you must check if cell is nil or if cell.detailTextLabel is nil
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
Batchomatic *bm = [Batchomatic sharedInstance];
NSDictionary *tweakInfo = [bm.currentlyInstalledTweaks objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:18];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
cell.detailTextLabel.textColor = [UIColor systemGrayColor]; //make the package ID text a light gray
if (bm.packageManager == 2 && [%c(ZBDevice) darkModeEnabled]) {
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.textColor = [UIColor colorWithRed:0.557 green:0.557 blue:0.576 alpha:1];
}
cell.textLabel.text = [tweakInfo objectForKey:@"name"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"\t%@", [tweakInfo objectForKey:@"packageID"]];
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Batchomatic *bm = [Batchomatic sharedInstance];
NSDictionary *tweakInfo = [bm.currentlyInstalledTweaks objectAtIndex:indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self didTapRepackTweakWithIdentifier:[tweakInfo objectForKey:@"packageID"]];
}
//--------------------------------------------------------------------------------------------------------------------------
- (void)didTapRepackTweakWithIdentifier:(NSString *)packageID {
Batchomatic *bm = [Batchomatic sharedInstance];
bm.maxSteps = 1;
NSString *msg = [NSString stringWithFormat:@"Repacking tweak to .deb....\n%@", packageID];
[bm showProcessingDialog:msg includeStage:true startingStep:1 autoPresent:false];
[self presentViewController:bm.processingDialog animated:YES completion:^{
[bm repackTweakWithIdentifier:packageID];
}];
}
- (void)didTapBackButton {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end