From 1fad90441cda88d6632307adc207adb0eadf4964 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 12 Dec 2023 02:32:45 +0100 Subject: [PATCH 1/9] perf: Use hashset for fast comparison --- .../patches_selector_viewmodel.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart index 173c1f5376..6b6d7d2439 100644 --- a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart +++ b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart @@ -25,6 +25,9 @@ class PatchesSelectorViewModel extends BaseViewModel { locator().selectedPatches; PatchedApplication? selectedApp = locator().selectedApp; String? patchesVersion = ''; + + Set savedPatchNames = {}; + bool isDefaultPatchesRepo() { return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches'; } @@ -48,6 +51,9 @@ class PatchesSelectorViewModel extends BaseViewModel { }); currentSelection.clear(); currentSelection.addAll(selectedPatches); + + savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet(); + notifyListeners(); } @@ -281,13 +287,10 @@ class PatchesSelectorViewModel extends BaseViewModel { } bool isPatchNew(Patch patch) { - final List savedPatches = - _managerAPI.getSavedPatches(selectedApp!.packageName); - if (savedPatches.isEmpty) { + if (savedPatchNames.isEmpty) { return false; } else { - return !savedPatches - .any((p) => p.getSimpleName() == patch.getSimpleName()); + return !savedPatchNames.contains(patch.name); } } From 7831a3438d46630dad78425eba18c209210e6d1d Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 12 Dec 2023 02:32:57 +0100 Subject: [PATCH 2/9] fix: Include new patches that are used by default --- .../views/patches_selector/patches_selector_viewmodel.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart index 6b6d7d2439..399fe34945 100644 --- a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart +++ b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart @@ -59,8 +59,9 @@ class PatchesSelectorViewModel extends BaseViewModel { bool isSelected(Patch patch) { return selectedPatches.any( - (element) => element.name == patch.name, - ); + (element) => element.name == patch.name, + ) || + (isPatchNew(patch) && !patch.excluded); } void navigateToPatchOptions(List