From cebf97464da8a0be8dee4676db3b8b4d7eb294c4 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 25 Nov 2023 11:32:33 -0800 Subject: [PATCH] Added setting --- assets/i18n/en_US.json | 3 ++ lib/services/manager_api.dart | 8 ++++ lib/ui/views/home/home_view.dart | 27 ++++++++----- lib/ui/views/home/home_viewmodel.dart | 4 ++ .../views/installer/installer_viewmodel.dart | 6 ++- lib/ui/views/settings/settings_viewmodel.dart | 12 ++++++ .../settings_advanced_section.dart | 2 + .../settingsView/settings_patch_history.dart | 40 +++++++++++++++++++ 8 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 lib/ui/widgets/settingsView/settings_patch_history.dart diff --git a/assets/i18n/en_US.json b/assets/i18n/en_US.json index af77ef29..90c6334b 100644 --- a/assets/i18n/en_US.json +++ b/assets/i18n/en_US.json @@ -239,6 +239,9 @@ "universalPatchesLabel": "Show universal patches", "universalPatchesHint": "Display all apps and universal patches (may slow down the app list)", + "patchHistoryLabel": "Save patched app", + "patchHistoryHint": "Save the last patched app to install/export later", + "versionCompatibilityCheckLabel": "Version compatibility check", "versionCompatibilityCheckHint": "Restricts patches to supported app versions", "requireSuggestedAppVersionLabel": "Require suggested app version", diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 47f528e9..12061089 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -268,6 +268,14 @@ class ManagerAPI { await _prefs.setBool('requireSuggestedAppVersionEnabled', value); } + bool isPatchHistoryEnabled() { + return _prefs.getBool('patchHistoryEnabled') ?? true; + } + + Future enablePatchHistoryStatus(bool value) async { + await _prefs.setBool('patchHistoryEnabled', value); + } + Future setKeystorePassword(String password) async { await _prefs.setString('keystorePassword', password); } diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index c7bff773..90278deb 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -51,16 +51,25 @@ class HomeView extends StatelessWidget { const SizedBox(height: 10), LatestCommitCard(model: model, parentContext: context), const SizedBox(height: 23), - I18nText( - 'homeView.patchHistorySubtitle', - child: Text( - '', - style: Theme.of(context).textTheme.titleLarge, - ), + Visibility( + visible: model.isPatchHistoryEnabled(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + I18nText( + 'homeView.patchHistorySubtitle', + child: Text( + '', + style: Theme.of(context).textTheme.titleLarge, + ), + ), + const SizedBox(height: 10), + PatchHistoryCard(), + const SizedBox(height: 10), + + ], + ), ), - const SizedBox(height: 10), - PatchHistoryCard(), - const SizedBox(height: 10), I18nText( 'homeView.patchedSubtitle', child: Text( diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 6872da9f..8f327afa 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -112,6 +112,10 @@ class HomeViewModel extends BaseViewModel { notifyListeners(); } + bool isPatchHistoryEnabled() { + return _managerAPI.isPatchHistoryEnabled(); + } + Future hasManagerUpdates() async { String currentVersion = await _managerAPI.getCurrentManagerVersion(); diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index fd3254f8..f9e87625 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -147,7 +147,11 @@ class InstallerViewModel extends BaseViewModel { _patches, ); _app.appliedPatches = _patches.map((p) => p.name).toList(); - await _managerAPI.setLastPatchedApp(_app, _patcherAPI.outFile!); + if (_managerAPI.isPatchHistoryEnabled()) { + await _managerAPI.setLastPatchedApp(_app, _patcherAPI.outFile!); + } else { + _app.patchedFilePath = _patcherAPI.outFile!.path; + } locator().initialize(context); } on Exception catch (e) { update( diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index d1dbfd7e..d2c6850f 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -131,6 +131,18 @@ class SettingsViewModel extends BaseViewModel { notifyListeners(); } + bool isPatchHistoryEnabled() { + return _managerAPI.isPatchHistoryEnabled(); + } + + void usePatchHistory(bool value) { + _managerAPI.enablePatchHistoryStatus(value); + if (!value) { + _managerAPI.deleteLastPatchedApp(); + } + notifyListeners(); + } + bool isVersionCompatibilityCheckEnabled() { return _managerAPI.isVersionCompatibilityCheckEnabled(); } diff --git a/lib/ui/widgets/settingsView/settings_advanced_section.dart b/lib/ui/widgets/settingsView/settings_advanced_section.dart index 53b3cadf..ad71af42 100644 --- a/lib/ui/widgets/settingsView/settings_advanced_section.dart +++ b/lib/ui/widgets/settingsView/settings_advanced_section.dart @@ -5,6 +5,7 @@ import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_man import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_manage_sources.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_auto_update_patches.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_enable_patches_selection.dart'; +import 'package:revanced_manager/ui/widgets/settingsView/settings_patch_history.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_require_suggested_app_version.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_universal_patches.dart'; @@ -24,6 +25,7 @@ class SAdvancedSection extends StatelessWidget { SRequireSuggestedAppVersion(), SVersionCompatibilityCheck(), SUniversalPatches(), + SPatchHistory(), SManageSourcesUI(), SManageApiUrlUI(), ], diff --git a/lib/ui/widgets/settingsView/settings_patch_history.dart b/lib/ui/widgets/settingsView/settings_patch_history.dart new file mode 100644 index 00000000..30f9e1a5 --- /dev/null +++ b/lib/ui/widgets/settingsView/settings_patch_history.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_i18n/widgets/I18nText.dart'; +import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart'; + +class SPatchHistory extends StatefulWidget { + const SPatchHistory({super.key}); + + @override + State createState() => + _SPatchHistoryState(); +} + +final _settingsViewModel = SettingsViewModel(); + +class _SPatchHistoryState + extends State { + @override + Widget build(BuildContext context) { + return SwitchListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 20.0), + title: I18nText( + 'settingsView.patchHistoryLabel', + child: const Text( + '', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ), + subtitle: I18nText('settingsView.patchHistoryHint'), + value: _settingsViewModel.isPatchHistoryEnabled(), + onChanged: (value) { + setState(() { + _settingsViewModel.usePatchHistory(value); + }); + }, + ); + } +}