From 9ecdb53e69c9945102d119e51d98b94845458583 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 14 May 2022 22:10:05 +0800 Subject: [PATCH] Show intro dialog for photo enhancement --- app/lib/help_utils.dart | 2 ++ app/lib/l10n/app_en.arb | 2 ++ app/lib/l10n/untranslated-messages.txt | 22 +++++++++++++ app/lib/pref.dart | 10 ++++++ app/lib/widget/handler/enhance_handler.dart | 36 +++++++++++++++++++++ app/lib/widget/my_app.dart | 13 ++++++++ app/lib/widget/settings.dart | 16 +++++++-- 7 files changed, 98 insertions(+), 3 deletions(-) diff --git a/app/lib/help_utils.dart b/app/lib/help_utils.dart index 7e53e54a..ffe483c9 100644 --- a/app/lib/help_utils.dart +++ b/app/lib/help_utils.dart @@ -6,6 +6,8 @@ const twoFactorAuthUrl = "https://gitlab.com/nkming2/nc-photos/-/wikis/help/two-factor-authentication"; const homeFolderNotFoundUrl = "https://gitlab.com/nkming2/nc-photos/-/wikis/help/home-folder-not-found"; +const enhanceUrl = + "https://gitlab.com/nkming2/nc-photos/-/wikis/help/enhance"; const enhanceZeroDceUrl = "https://gitlab.com/nkming2/nc-photos/-/wikis/help/enhance/zero-dce"; const enhanceDeepLabPortraitBlurUrl = diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 257c2569..317b07f2 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -1182,6 +1182,8 @@ "@enhanceTooltip": { "description": "Enhance a photo" }, + "enhanceIntroDialogTitle": "Enhance your photos", + "enhanceIntroDialogDescription": "Your photos are processed locally on your device. By default, they are downscaled to 2048x1536. You can adjust the output resolution in Settings", "enhanceLowLightTitle": "Low-light enhancement", "@enhanceLowLightTitle": { "description": "Enhance a photo taken in low-light environment" diff --git a/app/lib/l10n/untranslated-messages.txt b/app/lib/l10n/untranslated-messages.txt index 9c111fe9..3d8632c2 100644 --- a/app/lib/l10n/untranslated-messages.txt +++ b/app/lib/l10n/untranslated-messages.txt @@ -89,6 +89,8 @@ "backgroundServiceStopping", "metadataTaskPauseLowBatteryNotification", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -200,6 +202,8 @@ "backgroundServiceStopping", "metadataTaskPauseLowBatteryNotification", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -366,6 +370,8 @@ "backgroundServiceStopping", "metadataTaskPauseLowBatteryNotification", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -383,6 +389,8 @@ "backgroundServiceStopping", "metadataTaskPauseLowBatteryNotification", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -395,6 +403,8 @@ "settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionDescription", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -411,6 +421,8 @@ "helpButtonLabel", "removeFromAlbumTooltip", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -444,6 +456,8 @@ "backgroundServiceStopping", "metadataTaskPauseLowBatteryNotification", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -456,6 +470,8 @@ "settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionDescription", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -468,6 +484,8 @@ "settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionDescription", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -480,6 +498,8 @@ "settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionDescription", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", @@ -492,6 +512,8 @@ "settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionDescription", "enhanceTooltip", + "enhanceIntroDialogTitle", + "enhanceIntroDialogDescription", "enhanceLowLightTitle", "collectionEnhancedPhotosLabel", "deletePermanentlyLocalConfirmationDialogContent", diff --git a/app/lib/pref.dart b/app/lib/pref.dart index cf16da77..c4009065 100644 --- a/app/lib/pref.dart +++ b/app/lib/pref.dart @@ -186,6 +186,13 @@ class Pref { value, (key, value) => provider.setInt(key, value)); + bool? hasShownEnhanceInfo() => provider.getBool(PrefKey.hasShownEnhanceInfo); + bool hasShownEnhanceInfoOr([bool def = false]) => hasShownEnhanceInfo() ?? def; + Future setHasShownEnhanceInfo(bool value) => _set( + PrefKey.hasShownEnhanceInfo, + value, + (key, value) => provider.setBool(key, value)); + Future _set(PrefKey key, T value, Future Function(PrefKey key, T value) setFn) async { if (await setFn(key, value)) { @@ -477,6 +484,7 @@ enum PrefKey { hasShownSharedAlbumInfo, enhanceMaxWidth, enhanceMaxHeight, + hasShownEnhanceInfo, // account pref isEnableFaceRecognitionApp, @@ -535,6 +543,8 @@ extension on PrefKey { return "enhanceMaxWidth"; case PrefKey.enhanceMaxHeight: return "enhanceMaxHeight"; + case PrefKey.hasShownEnhanceInfo: + return "hasShownEnhanceInfo"; // account pref case PrefKey.isEnableFaceRecognitionApp: diff --git a/app/lib/widget/handler/enhance_handler.dart b/app/lib/widget/handler/enhance_handler.dart index aa6c8404..8ed93574 100644 --- a/app/lib/widget/handler/enhance_handler.dart +++ b/app/lib/widget/handler/enhance_handler.dart @@ -13,6 +13,7 @@ import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:nc_photos/pref.dart'; import 'package:nc_photos/snack_bar_manager.dart'; +import 'package:nc_photos/widget/settings.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -26,6 +27,10 @@ class EnhanceHandler { file_util.isSupportedImageFormat(file) && file.contentType != "image/gif"; Future call(BuildContext context) async { + if (!Pref().hasShownEnhanceInfoOr()) { + await _showInfo(context); + } + if (!await _ensurePermission()) { return; } @@ -90,6 +95,37 @@ class EnhanceHandler { } } + Future _showInfo(BuildContext context) async { + await showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text(L10n.global().enhanceIntroDialogTitle), + content: Text(L10n.global().enhanceIntroDialogDescription), + actions: [ + TextButton( + onPressed: () { + launch(enhanceUrl); + }, + child: Text(L10n.global().learnMoreButtonLabel), + ), + TextButton( + onPressed: () { + Navigator.of(context).pushNamed(EnhancementSettings.routeName); + }, + child: Text(L10n.global().configButtonLabel), + ), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text(MaterialLocalizations.of(context).closeButtonLabel), + ), + ], + ), + ); + Pref().setHasShownEnhanceInfo(true); + } + Future _ensurePermission() async { if (platform_k.isAndroid) { if (AndroidInfo().sdkInt < AndroidVersion.R && diff --git a/app/lib/widget/my_app.dart b/app/lib/widget/my_app.dart index d273089b..65e35e82 100644 --- a/app/lib/widget/my_app.dart +++ b/app/lib/widget/my_app.dart @@ -172,6 +172,7 @@ class _MyAppState extends State route ??= _handleFavoriteBrowserRoute(settings); route ??= _handleEnhancedPhotoBrowserRoute(settings); route ??= _handleLocalFileViewerRoute(settings); + route ??= _handleEnhancementSettingsRoute(settings); return route; } @@ -536,6 +537,18 @@ class _MyAppState extends State return null; } + Route? _handleEnhancementSettingsRoute(RouteSettings settings) { + try { + if (settings.name == EnhancementSettings.routeName) { + return EnhancementSettings.buildRoute(); + } + } catch (e) { + _log.severe( + "[_handleEnhancementSettingsRoute] Failed while handling route", e); + } + return null; + } + final _scaffoldMessengerKey = GlobalKey(); final _navigatorKey = GlobalKey(); diff --git a/app/lib/widget/settings.dart b/app/lib/widget/settings.dart index d7a76067..d038690e 100644 --- a/app/lib/widget/settings.dart +++ b/app/lib/widget/settings.dart @@ -145,7 +145,7 @@ class _SettingsState extends State { color: AppTheme.getUnfocusedIconColor(context), ), label: L10n.global().settingsPhotoEnhancementTitle, - builder: () => _EnhancementSettings(), + builder: () => const EnhancementSettings(), ), _buildSubSettings( context, @@ -966,12 +966,22 @@ class _AlbumSettingsState extends State<_AlbumSettings> { static final _log = Logger("widget.settings._AlbumSettingsState"); } -class _EnhancementSettings extends StatefulWidget { +class EnhancementSettings extends StatefulWidget { + static const routeName = "/enhancement-settings"; + + static Route buildRoute() => MaterialPageRoute( + builder: (_) => const EnhancementSettings(), + ); + + const EnhancementSettings({ + Key? key, + }) : super(key: key); + @override createState() => _EnhancementSettingsState(); } -class _EnhancementSettingsState extends State<_EnhancementSettings> { +class _EnhancementSettingsState extends State { @override initState() { super.initState();