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 pathBMInstallTableViewController.xm
More file actions
139 lines (123 loc) · 5.87 KB
/
BMInstallTableViewController.xm
File metadata and controls
139 lines (123 loc) · 5.87 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#import "Headers/Batchomatic.h"
#import "Headers/BMInstallTableViewController.h"
@implementation BMInstallTableViewController //The installation options screen
- (void)viewDidLoad {
[super viewDidLoad];
Batchomatic *bm = [Batchomatic sharedInstance];
bm.bm_BMInstallTableViewController = self;
self.navigationItem.title = @"Batchomatic";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(didTapBackButton)];
[self createTableView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[Batchomatic sharedInstance].bm_currentBMController = self;
}
- (void)createTableView {
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)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 6;
}
else {
return 1;
}
}
- (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 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Batchomatic *bm = [Batchomatic sharedInstance];
cell.textLabel.font = [UIFont boldSystemFontOfSize:22];
if (bm.packageManager == 2 && [%c(ZBDevice) darkModeEnabled]) {
cell.textLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == 0) { //put a UISwitch in each row of the top section
NSArray *cellTitles = @[@"Install preferences", @"Install hosts file", @"Install saved .debs", @"Add repos", @"Queue tweaks", @"Install offline tweaks"];
cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UISwitch *toggle = [[UISwitch alloc] initWithFrame:CGRectZero];
toggle.tag = indexPath.row;
[toggle setOn:YES animated:YES];
bm.prefsSwitchStatus = true;
bm.hostsSwitchStatus = true;
bm.savedDebsSwitchStatus = true;
if (bm.debIsOnline) { //if the .deb is online mode, the offline switch gets greyed out
if (indexPath.row == 3 || indexPath.row == 4) {
[toggle setOn:YES animated:YES];
bm.reposSwitchStatus = true;
bm.tweaksSwitchStatus = true;
}
if (indexPath.row == 5) {
[toggle setOn:NO animated:YES]; //turn the switch off
bm.offlineTweaksSwitchStatus = false;
toggle.enabled = NO; //grey out the switch
cell.textLabel.alpha = 0.439216f; //grey out the label
cell.userInteractionEnabled = NO;
}
}
else { //and vice versa if the .deb is offline mode
if (indexPath.row == 3 || indexPath.row == 4) {
[toggle setOn:NO animated:YES];
bm.reposSwitchStatus = false;
bm.tweaksSwitchStatus = false;
toggle.enabled = NO;
cell.textLabel.alpha = 0.439216f;
cell.userInteractionEnabled = NO;
}
if (indexPath.row == 5) {
[toggle setOn:YES animated:YES];
bm.offlineTweaksSwitchStatus = true;
}
}
[toggle addTarget:bm action:@selector(toggleTapped:) forControlEvents:UIControlEventValueChanged]; //"- (void)toggleTapped:" will update the corresponding boolean variable whenever the switch is tapped
cell.accessoryView = toggle;
}
else { //customizes the "Proceed" button/row
NSArray *cellTitles = @[@"Proceed"];
cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
if (indexPath.row == 0) {
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 1) {
if (indexPath.row == 0) {
[self didTapProceedButton];
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
- (void)didTapProceedButton {
Batchomatic *bm = [Batchomatic sharedInstance];
[bm calculateMaxStepsForInstalling]; //must do some prep work before actually installing the .deb
[bm showProcessingDialog:@"Preparing...." includeStage:true startingStep:0 autoPresent:false];
[self presentViewController:bm.processingDialog animated:YES completion:^{
[bm installDeb];
}];
}
- (void)didTapBackButton {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end