mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
fix: improve patches selector.
This commit is contained in:
@ -14,6 +14,7 @@ class PatchesSelectorView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
final List<PatchItem> patches = [];
|
||||
String query = '';
|
||||
|
||||
@override
|
||||
@ -24,7 +25,10 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
viewModelBuilder: () => locator<PatchesSelectorViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => {},
|
||||
onPressed: () {
|
||||
model.selectPatches(patches);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
label: I18nText('patchesSelectorView.fabButton'),
|
||||
icon: const Icon(Icons.check),
|
||||
backgroundColor: const Color(0xff7792BA),
|
||||
@ -66,23 +70,30 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
}
|
||||
|
||||
Widget _getAllResults(PatchesSelectorViewModel model) {
|
||||
patches.clear();
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.patches!.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.patches!.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
||||
return PatchItem(
|
||||
name: model.patches![index].simpleName,
|
||||
PatchItem item = PatchItem(
|
||||
name: model.patches![index].name,
|
||||
simpleName: model.patches![index].simpleName,
|
||||
version: model.patches![index].version,
|
||||
description: model.patches![index].description,
|
||||
isSelected: false,
|
||||
isSelected: model.selectedPatches.any(
|
||||
(element) => element.name == model.patches![index].name,
|
||||
),
|
||||
);
|
||||
patches.add(item);
|
||||
return item;
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getFilteredResults(PatchesSelectorViewModel model) {
|
||||
patches.clear();
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.patches!.length,
|
||||
@ -91,12 +102,17 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
if (model.patches![index].simpleName.toLowerCase().contains(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
return PatchItem(
|
||||
name: model.patches![index].simpleName,
|
||||
PatchItem item = PatchItem(
|
||||
name: model.patches![index].name,
|
||||
simpleName: model.patches![index].simpleName,
|
||||
version: model.patches![index].version,
|
||||
description: model.patches![index].description,
|
||||
isSelected: false,
|
||||
isSelected: model.selectedPatches.any(
|
||||
(element) => element.name == model.patches![index].name,
|
||||
),
|
||||
);
|
||||
patches.add(item);
|
||||
return item;
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/patch_item.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class PatchesSelectorViewModel extends BaseViewModel {
|
||||
@ -20,5 +22,19 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||
patches = await patcherAPI.getFilteredPatches(appInfo);
|
||||
}
|
||||
|
||||
void selectPatches(List<Patch> patches) {}
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
locator<PatcherViewModel>().hideFabButton =
|
||||
selectedPatches.isEmpty ? true : false;
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user