2022-08-09 01:01:06 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-08-13 11:56:30 +02:00
|
|
|
import 'package:revanced_manager/models/application_info.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 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-09 02:16:33 +02:00
|
|
|
List<Patch>? patches = [];
|
|
|
|
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-13 11:56:30 +02:00
|
|
|
ApplicationInfo? app = locator<AppSelectorViewModel>().selectedApp;
|
|
|
|
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();
|
|
|
|
if (patches != null) {
|
|
|
|
for (PatchItem patch in patchItems) {
|
|
|
|
if (patch.isSelected) {
|
|
|
|
selectedPatches.add(
|
|
|
|
patches!.firstWhere((element) => element.name == patch.name),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-10 01:49:17 +02:00
|
|
|
locator<PatcherViewModel>().showFabButton =
|
|
|
|
selectedPatches.isNotEmpty ? true : false;
|
2022-08-09 03:30:12 +02:00
|
|
|
locator<PatcherViewModel>().notifyListeners();
|
|
|
|
}
|
2022-08-09 01:01:06 +02:00
|
|
|
}
|