From 80eeafaf2bdf022c1351bec928b333b2ba492747 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Wed, 7 Sep 2022 13:03:54 +0100 Subject: [PATCH] feat: Add a confirmation dialog to update Manager button --- assets/i18n/en.json | 13 ++++++---- lib/ui/views/home/home_view.dart | 3 ++- lib/ui/views/home/home_viewmodel.dart | 25 ++++++++++++++++++- .../appInfoView/app_info_viewmodel.dart | 8 +++--- .../patchesSelectorView/patch_item.dart | 4 +-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index b4f7ca68..594bf036 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -18,6 +18,8 @@ "noUpdates": "No updates available", "noInstallations": "No patched applications installed", "installed": "Installed", + "updateDialogTitle": "Update", + "updateDialogText": "Are you sure you want to download and update Manager?", "notificationTitle": "ReVanced Manager was updated!", "notificationText": "Tap to open the app", "downloadingMessage": "Downloading update!", @@ -68,8 +70,8 @@ }, "patchItem": { "unsupportedWarningButton": "Unsupported version", - "alertDialogTitle": "Warning", - "alertDialogText": "Selecting this patch may or may not result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}" + "unsupportedDialogTitle": "Warning", + "unsupportedDialogText": "Selecting this patch may or may not result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}" }, "installerView": { "widgetTitle": "Installer", @@ -113,9 +115,10 @@ "openButton": "Open", "uninstallButton": "Uninstall", "patchButton": "Patch", - "alertDialogTitle": "Uninstall", - "alertDialogText": "Are you sure you want to uninstall this app?", - "errorDialogText": "App was installed with root mode enabled but currently root mode is disabled.\nPlease enable root mode first.", + "uninstallDialogTitle": "Uninstall", + "uninstallDialogText": "Are you sure you want to uninstall this app?", + "rootDialogTitle": "Error", + "rootDialogText": "App was installed with root mode enabled but currently root mode is disabled.\nPlease enable root mode first.", "packageNameLabel": "Package Name", "installTypeLabel": "Installation Type", "rootTypeLabel": "Root", diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index 28831c4c..972c469f 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -47,7 +47,8 @@ class HomeView extends StatelessWidget { ), const SizedBox(height: 10), LatestCommitCard( - onPressed: () => model.updateManager(context), + onPressed: () => + model.showUpdateConfirmationDialog(context), ), const SizedBox(height: 23), I18nText( diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 240f1be3..737fa446 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:app_installer/app_installer.dart'; import 'package:device_apps/device_apps.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -14,6 +14,7 @@ import 'package:revanced_manager/services/manager_api.dart'; import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; +import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; @@ -147,4 +148,26 @@ class HomeViewModel extends BaseViewModel { ); } } + + Future showUpdateConfirmationDialog(BuildContext context) async { + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: I18nText('homeView.updateDialogTitle'), + backgroundColor: Theme.of(context).colorScheme.secondaryContainer, + content: I18nText('homeView.updateDialogText'), + actions: [ + CustomMaterialButton( + isFilled: false, + label: I18nText('cancelButton'), + onPressed: () => Navigator.of(context).pop(), + ), + CustomMaterialButton( + label: I18nText('okButton'), + onPressed: () => updateManager(context), + ) + ], + ), + ); + } } diff --git a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart index 0f845e30..1b49cefa 100644 --- a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart +++ b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart @@ -45,9 +45,9 @@ class AppInfoViewModel extends BaseViewModel { return showDialog( context: context, builder: (context) => AlertDialog( - title: I18nText('appInfoView.alertDialogTitle'), + title: I18nText('appInfoView.rootDialogTitle'), backgroundColor: Theme.of(context).colorScheme.secondaryContainer, - content: I18nText('appInfoView.errorDialogText'), + content: I18nText('appInfoView.rootDialogText'), actions: [ CustomMaterialButton( label: I18nText('okButton'), @@ -60,9 +60,9 @@ class AppInfoViewModel extends BaseViewModel { return showDialog( context: context, builder: (context) => AlertDialog( - title: I18nText('appInfoView.alertDialogTitle'), + title: I18nText('appInfoView.uninstallDialogTitle'), backgroundColor: Theme.of(context).colorScheme.secondaryContainer, - content: I18nText('appInfoView.alertDialogText'), + content: I18nText('appInfoView.uninstallDialogText'), actions: [ CustomMaterialButton( isFilled: false, diff --git a/lib/ui/widgets/patchesSelectorView/patch_item.dart b/lib/ui/widgets/patchesSelectorView/patch_item.dart index e658a1cb..ab58d59d 100644 --- a/lib/ui/widgets/patchesSelectorView/patch_item.dart +++ b/lib/ui/widgets/patchesSelectorView/patch_item.dart @@ -144,10 +144,10 @@ class _PatchItemState extends State { return showDialog( context: context, builder: (context) => AlertDialog( - title: I18nText('patchItem.alertDialogTitle'), + title: I18nText('patchItem.unsupportedDialogTitle'), backgroundColor: Theme.of(context).colorScheme.secondaryContainer, content: I18nText( - 'patchItem.alertDialogText', + 'patchItem.unsupportedDialogText', translationParams: { 'packageVersion': widget.packageVersion, 'supportedVersions':