fix: patch selection while scrolling

This commit is contained in:
Alberto Ponces 2022-08-17 23:06:02 +01:00
parent cff27872eb
commit 492aa848ff
5 changed files with 23 additions and 22 deletions

View File

@ -15,7 +15,7 @@ class PatchedApplication {
toJson: encodeBase64,
)
final Uint8List icon;
final DateTime patchDate;
DateTime patchDate;
final bool isRooted;
final bool isFromStorage;
List<String> appliedPatches;

View File

@ -118,6 +118,7 @@ class InstallerViewModel extends BaseViewModel {
isInstalled = await locator<PatcherAPI>().installPatchedFile(selectedApp);
if (isInstalled) {
updateLog('Done');
selectedApp.patchDate = DateTime.now();
selectedApp.appliedPatches
.addAll(selectedPatches.map((p) => p.name).toList());
await saveApp(selectedApp);
@ -157,7 +158,8 @@ class InstallerViewModel extends BaseViewModel {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> patchedApps = prefs.getStringList('patchedApps') ?? [];
String app = json.encode(selectedApp.toJson());
patchedApps.remove(app);
patchedApps.removeWhere(
(a) => json.decode(a)['packageName'] == selectedApp.packageName);
patchedApps.add(app);
prefs.setStringList('patchedApps', patchedApps);
}

View File

@ -62,10 +62,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
onPressed: () {
model.selectPatches(patches);
Navigator.of(context).pop();
},
onPressed: () => Navigator.of(context).pop(),
child: I18nText('patchesSelectorView.fabButton'),
),
],

View File

@ -22,17 +22,17 @@ class PatchesSelectorViewModel extends BaseViewModel {
patches = await patcherAPI.getFilteredPatches(app);
}
void selectPatches(List<PatchItem> patchItems) {
selectedPatches.clear();
for (PatchItem item in patchItems) {
if (item.isSelected) {
Patch patch =
patches.firstWhere((element) => element.name == item.name);
if (!selectedPatches.contains(patch)) {
selectedPatches.add(patch);
}
}
void selectPatch(PatchItem item) {
Patch patch = locator<PatchesSelectorViewModel>()
.patches
.firstWhere((p) => p.name == item.name);
if (item.isSelected &&
!locator<PatchesSelectorViewModel>().selectedPatches.contains(patch)) {
locator<PatchesSelectorViewModel>().selectedPatches.add(patch);
} else {
locator<PatchesSelectorViewModel>().selectedPatches.remove(patch);
}
locator<PatchesSelectorViewModel>().notifyListeners();
locator<PatcherViewModel>().notifyListeners();
}
}

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
// ignore: must_be_immutable
class PatchItem extends StatefulWidget {
@ -26,9 +28,10 @@ class _PatchItemState extends State<PatchItem> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => setState(() {
widget.isSelected = !widget.isSelected;
}),
onTap: () {
setState(() => widget.isSelected = !widget.isSelected);
locator<PatchesSelectorViewModel>().selectPatch(widget);
},
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
@ -78,9 +81,8 @@ class _PatchItemState extends State<PatchItem> {
value: widget.isSelected,
activeColor: Colors.blueGrey[500],
onChanged: (newValue) {
setState(() {
widget.isSelected = newValue!;
});
setState(() => widget.isSelected = newValue!);
locator<PatchesSelectorViewModel>().selectPatch(widget);
},
),
)