@@ -5,7 +5,6 @@ import 'package:revanced_manager/models/patch.dart';
5
5
import 'package:revanced_manager/services/manager_api.dart' ;
6
6
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart' ;
7
7
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart' ;
8
- import 'package:revanced_manager/ui/widgets/shared/custom_card.dart' ;
9
8
import 'package:stacked/stacked.dart' ;
10
9
11
10
class PatchOptionsViewModel extends BaseViewModel {
@@ -14,7 +13,7 @@ class PatchOptionsViewModel extends BaseViewModel {
14
13
locator <PatcherViewModel >().selectedApp! .packageName;
15
14
List <Option > options = [];
16
15
List <Option > savedOptions = [];
17
- List <Option > visibleOptions = [];
16
+ List <Option > modifiedOptions = [];
18
17
19
18
Future <void > initialize () async {
20
19
options = getDefaultOptions ();
@@ -28,44 +27,26 @@ class PatchOptionsViewModel extends BaseViewModel {
28
27
savedOptions.add (savedOption);
29
28
}
30
29
}
31
- if (savedOptions.isNotEmpty) {
32
- visibleOptions = [
33
- ...savedOptions,
34
- ...options.where (
35
- (option) =>
36
- option.required &&
37
- ! savedOptions.any ((sOption) => sOption.key == option.key),
38
- ),
39
- ];
40
- } else {
41
- visibleOptions = [
42
- ...options.where ((option) => option.required ),
43
- ];
44
- }
45
- }
46
-
47
- void addOption (Option option) {
48
- visibleOptions.add (option);
49
- notifyListeners ();
50
- }
51
-
52
- void removeOption (Option option) {
53
- visibleOptions.removeWhere ((vOption) => vOption.key == option.key);
54
- notifyListeners ();
30
+ modifiedOptions = [
31
+ ...savedOptions,
32
+ ...options.where (
33
+ (option) => ! savedOptions.any ((sOption) => sOption.key == option.key),
34
+ ),
35
+ ];
55
36
}
56
37
57
38
bool saveOptions (BuildContext context) {
58
39
final List <Option > requiredNullOptions = [];
59
40
for (final Option option in options) {
60
- if (! visibleOptions .any ((vOption ) => vOption .key == option.key)) {
41
+ if (modifiedOptions .any ((mOption ) => mOption .key == option.key)) {
61
42
_managerAPI.clearPatchOption (
62
43
selectedApp,
63
44
_managerAPI.selectedPatch! .name,
64
45
option.key,
65
46
);
66
47
}
67
48
}
68
- for (final Option option in visibleOptions ) {
49
+ for (final Option option in modifiedOptions ) {
69
50
if (option.required && option.value == null ) {
70
51
requiredNullOptions.add (option);
71
52
} else {
@@ -98,11 +79,8 @@ class PatchOptionsViewModel extends BaseViewModel {
98
79
required : option.required ,
99
80
key: option.key,
100
81
);
101
- visibleOptions[visibleOptions
102
- .indexWhere ((vOption) => vOption.key == option.key)] = modifiedOption;
103
- _managerAPI.modifiedOptions
104
- .removeWhere ((mOption) => mOption.key == option.key);
105
- _managerAPI.modifiedOptions.add (modifiedOption);
82
+ modifiedOptions.removeWhere ((mOption) => mOption.key == option.key);
83
+ modifiedOptions.add (modifiedOption);
106
84
}
107
85
108
86
List <Option > getDefaultOptions () {
@@ -122,93 +100,11 @@ class PatchOptionsViewModel extends BaseViewModel {
122
100
return defaultOptions;
123
101
}
124
102
125
- void resetOptions () {
126
- _managerAPI.modifiedOptions.clear ();
127
- visibleOptions =
128
- getDefaultOptions ().where ((option) => option.required ).toList ();
129
- notifyListeners ();
130
- }
131
-
132
- Future <void > showAddOptionDialog (BuildContext context) async {
133
- await showDialog (
134
- context: context,
135
- builder: (context) => AlertDialog (
136
- title: Column (
137
- crossAxisAlignment: CrossAxisAlignment .start,
138
- mainAxisSize: MainAxisSize .min,
139
- children: [
140
- Text (
141
- t.patchOptionsView.addOptions,
142
- ),
143
- Text (
144
- '' ,
145
- style: TextStyle (
146
- fontSize: 16 ,
147
- color: Theme .of (context).colorScheme.onSecondaryContainer,
148
- ),
149
- ),
150
- ],
151
- ),
152
- actions: [
153
- FilledButton (
154
- onPressed: () {
155
- Navigator .of (context).pop ();
156
- },
157
- child: Text (t.cancelButton),
158
- ),
159
- ],
160
- contentPadding: const EdgeInsets .all (8 ),
161
- content: Wrap (
162
- spacing: 14 ,
163
- runSpacing: 14 ,
164
- children: options
165
- .where (
166
- (option) =>
167
- ! visibleOptions.any ((vOption) => vOption.key == option.key),
168
- )
169
- .map ((e) {
170
- return CustomCard (
171
- padding: const EdgeInsets .all (4 ),
172
- backgroundColor: Theme .of (context).colorScheme.surface,
173
- onTap: () {
174
- addOption (e);
175
- Navigator .pop (context);
176
- },
177
- child: Padding (
178
- padding: const EdgeInsets .all (8.0 ),
179
- child: Row (
180
- children: [
181
- Expanded (
182
- child: Column (
183
- crossAxisAlignment: CrossAxisAlignment .start,
184
- children: [
185
- Text (
186
- e.title,
187
- style: TextStyle (
188
- fontSize: 16 ,
189
- color: Theme .of (context).colorScheme.onSurface,
190
- ),
191
- ),
192
- const SizedBox (height: 4 ),
193
- Text (
194
- e.description,
195
- style: TextStyle (
196
- fontSize: 14 ,
197
- color: Theme .of (context).colorScheme.onSurface,
198
- ),
199
- ),
200
- ],
201
- ),
202
- ),
203
- ],
204
- ),
205
- ),
206
- );
207
- }).toList (),
208
- ),
209
- ),
210
- );
211
- }
103
+ dynamic getDefaultValue (Option patchOption) => _managerAPI.options
104
+ .firstWhere (
105
+ (option) => option.key == patchOption.key,
106
+ )
107
+ .value;
212
108
}
213
109
214
110
Future <void > showRequiredOptionNullDialog (
@@ -248,7 +144,7 @@ Future<void> showRequiredOptionNullDialog(
248
144
PatchesSelectorViewModel ().showPatchesChangeDialog (context);
249
145
}
250
146
},
251
- child: Text (t.patchOptionsView.deselectPatch ),
147
+ child: Text (t.patchOptionsView.unselectPatch ),
252
148
),
253
149
FilledButton (
254
150
onPressed: () {
0 commit comments