revanced-manager/lib/ui/views/patches_selector/patches_selector_viewmodel.dart

35 lines
1.1 KiB
Dart
Raw Normal View History

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';
import 'package:revanced_manager/services/patcher_api.dart';
2022-08-09 03:30:12 +02:00
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
2022-08-07 21:15:52 +02:00
import 'package:stacked/stacked.dart';
class PatchesSelectorViewModel extends BaseViewModel {
2022-08-18 16:33:33 +02:00
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final List<Patch> patches = [];
final List<Patch> selectedPatches =
locator<PatcherViewModel>().selectedPatches;
2022-08-07 21:15:52 +02:00
Future<void> initialize() async {
2022-08-18 16:33:33 +02:00
patches.addAll(await _patcherAPI.getFilteredPatches(
locator<PatcherViewModel>().selectedApp,
));
notifyListeners();
2022-08-07 21:15:52 +02:00
}
2022-08-09 01:01:06 +02:00
2022-08-18 16:33:33 +02:00
void selectPatch(String name, bool isSelected) {
Patch patch = patches.firstWhere((p) => p.name == name);
if (isSelected && !selectedPatches.contains(patch)) {
selectedPatches.add(patch);
2022-08-18 00:06:02 +02:00
} else {
2022-08-18 16:33:33 +02:00
selectedPatches.remove(patch);
2022-08-09 03:30:12 +02:00
}
2022-08-18 16:33:33 +02:00
notifyListeners();
}
void selectPatches() {
locator<PatcherViewModel>().selectedPatches = selectedPatches;
2022-08-09 03:30:12 +02:00
locator<PatcherViewModel>().notifyListeners();
}
2022-08-09 01:01:06 +02:00
}