From d78868b4625747b8c30e278d5a6a8fbb49bdc19d Mon Sep 17 00:00:00 2001 From: Ushie Date: Wed, 14 Dec 2022 01:52:06 +0300 Subject: [PATCH] feat: filter apps by patch count --- lib/services/patcher_api.dart | 5 ++--- lib/ui/views/app_selector/app_selector_viewmodel.dart | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/services/patcher_api.dart b/lib/services/patcher_api.dart index c0f7d70e..134f8053 100644 --- a/lib/services/patcher_api.dart +++ b/lib/services/patcher_api.dart @@ -94,15 +94,14 @@ class PatcherAPI { return filteredApps; } - Future> getFilteredPatches(String packageName) async { + List getFilteredPatches(String packageName) { List filteredPatches = []; _patches.forEach((patch) { if (patch.compatiblePackages.isEmpty) { filteredPatches.add(patch); } else { if (!patch.name.contains('settings') && - patch.compatiblePackages.any((pack) => pack.name == packageName) - ) { + patch.compatiblePackages.any((pack) => pack.name == packageName)) { filteredPatches.add(patch); } } diff --git a/lib/ui/views/app_selector/app_selector_viewmodel.dart b/lib/ui/views/app_selector/app_selector_viewmodel.dart index 6802a0ef..b2205dd0 100644 --- a/lib/ui/views/app_selector/app_selector_viewmodel.dart +++ b/lib/ui/views/app_selector/app_selector_viewmodel.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:device_apps/device_apps.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/services/patcher_api.dart'; @@ -19,7 +18,10 @@ class AppSelectorViewModel extends BaseViewModel { Future initialize() async { apps.addAll(await _patcherAPI.getFilteredInstalledApps()); - apps.sort((a, b) => a.appName.compareTo(b.appName)); + apps.sort(((a, b) => _patcherAPI + .getFilteredPatches(b.packageName) + .length + .compareTo(_patcherAPI.getFilteredPatches(a.packageName).length))); noApps = apps.isEmpty; notifyListeners(); }