mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 20:57:36 +02:00
feat: ability to store and load selected patches (#469)
* feat: ability to store and load selected patches * fix: I18n * fix: do not append but truncate file * fix: use json file, minor fixes * fix: better ui * WIP * feat: load patches selection after app selection * feat: import/export json file * fix: reformat code * fix: rare bug on import feature fixed * fix: move export/ipmort to settings page & import full json * fix: minor improvements * fix: minor code quality improvements * fix: export filename fix * fix: select list element istead of removing it
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_item.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/custom_popup_menu.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/search_bar.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@ -63,7 +64,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
actions: [
|
||||
Container(
|
||||
height: 2,
|
||||
margin: const EdgeInsets.only(right: 16, top: 12, bottom: 12),
|
||||
margin: const EdgeInsets.only(top: 12, bottom: 12),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 6, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
@ -78,6 +79,22 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
),
|
||||
),
|
||||
),
|
||||
CustomPopupMenu(
|
||||
onSelected: (value) => {
|
||||
model.onMenuSelection(value)
|
||||
},
|
||||
children: {
|
||||
0: I18nText(
|
||||
'patchesSelectorView.loadPatchesSelection',
|
||||
child: const Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(64.0),
|
||||
|
@ -5,6 +5,7 @@ import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/services/toast.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
@ -76,6 +77,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||
|
||||
void selectPatches() {
|
||||
locator<PatcherViewModel>().selectedPatches = selectedPatches;
|
||||
saveSelectedPatches();
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
|
||||
@ -117,4 +119,33 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||
pack.name == app.packageName &&
|
||||
(pack.versions.isEmpty || pack.versions.contains(app.version)));
|
||||
}
|
||||
|
||||
void onMenuSelection(value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
loadSelectedPatches();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveSelectedPatches() async {
|
||||
List<String> selectedPatches =
|
||||
this.selectedPatches.map((patch) => patch.name).toList();
|
||||
await _managerAPI.setSelectedPatches(
|
||||
locator<PatcherViewModel>().selectedApp!.originalPackageName,
|
||||
selectedPatches);
|
||||
}
|
||||
|
||||
Future<void> loadSelectedPatches() async {
|
||||
List<String> selectedPatches = await _managerAPI.getSelectedPatches(
|
||||
locator<PatcherViewModel>().selectedApp!.originalPackageName);
|
||||
if (selectedPatches.isNotEmpty) {
|
||||
this.selectedPatches.clear();
|
||||
this.selectedPatches.addAll(
|
||||
patches.where((patch) => selectedPatches.contains(patch.name)));
|
||||
} else {
|
||||
locator<Toast>().showBottom('patchesSelectorView.noSavedPatches');
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user