2022-08-09 01:01:06 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:revanced_manager/models/patch.dart';
|
2022-08-14 20:40:34 +02:00
|
|
|
import 'package:revanced_manager/models/patched_application.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:revanced_manager/services/patcher_api.dart';
|
2022-08-09 02:16:33 +02:00
|
|
|
import 'package:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart';
|
2022-08-09 03:30:12 +02:00
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/patch_item.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
class PatchesSelectorViewModel extends BaseViewModel {
|
2022-08-09 02:20:50 +02:00
|
|
|
final PatcherAPI patcherAPI = locator<PatcherAPI>();
|
2022-08-17 19:44:27 +02:00
|
|
|
List<Patch> patches = [];
|
2022-08-09 02:16:33 +02:00
|
|
|
List<Patch> selectedPatches = [];
|
2022-08-07 21:15:52 +02:00
|
|
|
|
2022-08-13 11:56:30 +02:00
|
|
|
Future<void> initialize() async {
|
2022-08-09 02:16:33 +02:00
|
|
|
await getPatches();
|
|
|
|
notifyListeners();
|
2022-08-07 21:15:52 +02:00
|
|
|
}
|
2022-08-09 01:01:06 +02:00
|
|
|
|
2022-08-09 02:16:33 +02:00
|
|
|
Future<void> getPatches() async {
|
2022-08-14 20:40:34 +02:00
|
|
|
PatchedApplication? app = locator<AppSelectorViewModel>().selectedApp;
|
2022-08-13 11:56:30 +02:00
|
|
|
patches = await patcherAPI.getFilteredPatches(app);
|
2022-08-07 21:15:52 +02:00
|
|
|
}
|
2022-08-09 02:16:33 +02:00
|
|
|
|
2022-08-09 03:30:12 +02:00
|
|
|
void selectPatches(List<PatchItem> patchItems) {
|
|
|
|
selectedPatches.clear();
|
2022-08-17 19:44:27 +02:00
|
|
|
for (PatchItem item in patchItems) {
|
|
|
|
if (item.isSelected) {
|
|
|
|
Patch patch =
|
|
|
|
patches.firstWhere((element) => element.name == item.name);
|
|
|
|
if (!selectedPatches.contains(patch)) {
|
|
|
|
selectedPatches.add(patch);
|
2022-08-09 03:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
locator<PatcherViewModel>().notifyListeners();
|
|
|
|
}
|
2022-08-09 01:01:06 +02:00
|
|
|
}
|