Show intro dialog for photo enhancement

This commit is contained in:
Ming Ming 2022-05-14 22:10:05 +08:00
parent fb2bb30e0f
commit 9ecdb53e69
7 changed files with 98 additions and 3 deletions

View file

@ -6,6 +6,8 @@ const twoFactorAuthUrl =
"https://gitlab.com/nkming2/nc-photos/-/wikis/help/two-factor-authentication"; "https://gitlab.com/nkming2/nc-photos/-/wikis/help/two-factor-authentication";
const homeFolderNotFoundUrl = const homeFolderNotFoundUrl =
"https://gitlab.com/nkming2/nc-photos/-/wikis/help/home-folder-not-found"; "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 = const enhanceZeroDceUrl =
"https://gitlab.com/nkming2/nc-photos/-/wikis/help/enhance/zero-dce"; "https://gitlab.com/nkming2/nc-photos/-/wikis/help/enhance/zero-dce";
const enhanceDeepLabPortraitBlurUrl = const enhanceDeepLabPortraitBlurUrl =

View file

@ -1182,6 +1182,8 @@
"@enhanceTooltip": { "@enhanceTooltip": {
"description": "Enhance a photo" "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": "Low-light enhancement",
"@enhanceLowLightTitle": { "@enhanceLowLightTitle": {
"description": "Enhance a photo taken in low-light environment" "description": "Enhance a photo taken in low-light environment"

View file

@ -89,6 +89,8 @@
"backgroundServiceStopping", "backgroundServiceStopping",
"metadataTaskPauseLowBatteryNotification", "metadataTaskPauseLowBatteryNotification",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -200,6 +202,8 @@
"backgroundServiceStopping", "backgroundServiceStopping",
"metadataTaskPauseLowBatteryNotification", "metadataTaskPauseLowBatteryNotification",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -366,6 +370,8 @@
"backgroundServiceStopping", "backgroundServiceStopping",
"metadataTaskPauseLowBatteryNotification", "metadataTaskPauseLowBatteryNotification",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -383,6 +389,8 @@
"backgroundServiceStopping", "backgroundServiceStopping",
"metadataTaskPauseLowBatteryNotification", "metadataTaskPauseLowBatteryNotification",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -395,6 +403,8 @@
"settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionTitle",
"settingsEnhanceMaxResolutionDescription", "settingsEnhanceMaxResolutionDescription",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -411,6 +421,8 @@
"helpButtonLabel", "helpButtonLabel",
"removeFromAlbumTooltip", "removeFromAlbumTooltip",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -444,6 +456,8 @@
"backgroundServiceStopping", "backgroundServiceStopping",
"metadataTaskPauseLowBatteryNotification", "metadataTaskPauseLowBatteryNotification",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -456,6 +470,8 @@
"settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionTitle",
"settingsEnhanceMaxResolutionDescription", "settingsEnhanceMaxResolutionDescription",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -468,6 +484,8 @@
"settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionTitle",
"settingsEnhanceMaxResolutionDescription", "settingsEnhanceMaxResolutionDescription",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -480,6 +498,8 @@
"settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionTitle",
"settingsEnhanceMaxResolutionDescription", "settingsEnhanceMaxResolutionDescription",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",
@ -492,6 +512,8 @@
"settingsEnhanceMaxResolutionTitle", "settingsEnhanceMaxResolutionTitle",
"settingsEnhanceMaxResolutionDescription", "settingsEnhanceMaxResolutionDescription",
"enhanceTooltip", "enhanceTooltip",
"enhanceIntroDialogTitle",
"enhanceIntroDialogDescription",
"enhanceLowLightTitle", "enhanceLowLightTitle",
"collectionEnhancedPhotosLabel", "collectionEnhancedPhotosLabel",
"deletePermanentlyLocalConfirmationDialogContent", "deletePermanentlyLocalConfirmationDialogContent",

View file

@ -186,6 +186,13 @@ class Pref {
value, value,
(key, value) => provider.setInt(key, value)); (key, value) => provider.setInt(key, value));
bool? hasShownEnhanceInfo() => provider.getBool(PrefKey.hasShownEnhanceInfo);
bool hasShownEnhanceInfoOr([bool def = false]) => hasShownEnhanceInfo() ?? def;
Future<bool> setHasShownEnhanceInfo(bool value) => _set<bool>(
PrefKey.hasShownEnhanceInfo,
value,
(key, value) => provider.setBool(key, value));
Future<bool> _set<T>(PrefKey key, T value, Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async { Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) { if (await setFn(key, value)) {
@ -477,6 +484,7 @@ enum PrefKey {
hasShownSharedAlbumInfo, hasShownSharedAlbumInfo,
enhanceMaxWidth, enhanceMaxWidth,
enhanceMaxHeight, enhanceMaxHeight,
hasShownEnhanceInfo,
// account pref // account pref
isEnableFaceRecognitionApp, isEnableFaceRecognitionApp,
@ -535,6 +543,8 @@ extension on PrefKey {
return "enhanceMaxWidth"; return "enhanceMaxWidth";
case PrefKey.enhanceMaxHeight: case PrefKey.enhanceMaxHeight:
return "enhanceMaxHeight"; return "enhanceMaxHeight";
case PrefKey.hasShownEnhanceInfo:
return "hasShownEnhanceInfo";
// account pref // account pref
case PrefKey.isEnableFaceRecognitionApp: case PrefKey.isEnableFaceRecognitionApp:

View file

@ -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/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart'; import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.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:nc_photos_plugin/nc_photos_plugin.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -26,6 +27,10 @@ class EnhanceHandler {
file_util.isSupportedImageFormat(file) && file.contentType != "image/gif"; file_util.isSupportedImageFormat(file) && file.contentType != "image/gif";
Future<void> call(BuildContext context) async { Future<void> call(BuildContext context) async {
if (!Pref().hasShownEnhanceInfoOr()) {
await _showInfo(context);
}
if (!await _ensurePermission()) { if (!await _ensurePermission()) {
return; return;
} }
@ -90,6 +95,37 @@ class EnhanceHandler {
} }
} }
Future<void> _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<bool> _ensurePermission() async { Future<bool> _ensurePermission() async {
if (platform_k.isAndroid) { if (platform_k.isAndroid) {
if (AndroidInfo().sdkInt < AndroidVersion.R && if (AndroidInfo().sdkInt < AndroidVersion.R &&

View file

@ -172,6 +172,7 @@ class _MyAppState extends State<MyApp>
route ??= _handleFavoriteBrowserRoute(settings); route ??= _handleFavoriteBrowserRoute(settings);
route ??= _handleEnhancedPhotoBrowserRoute(settings); route ??= _handleEnhancedPhotoBrowserRoute(settings);
route ??= _handleLocalFileViewerRoute(settings); route ??= _handleLocalFileViewerRoute(settings);
route ??= _handleEnhancementSettingsRoute(settings);
return route; return route;
} }
@ -536,6 +537,18 @@ class _MyAppState extends State<MyApp>
return null; return null;
} }
Route<dynamic>? _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<ScaffoldMessengerState>(); final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
final _navigatorKey = GlobalKey<NavigatorState>(); final _navigatorKey = GlobalKey<NavigatorState>();

View file

@ -145,7 +145,7 @@ class _SettingsState extends State<Settings> {
color: AppTheme.getUnfocusedIconColor(context), color: AppTheme.getUnfocusedIconColor(context),
), ),
label: L10n.global().settingsPhotoEnhancementTitle, label: L10n.global().settingsPhotoEnhancementTitle,
builder: () => _EnhancementSettings(), builder: () => const EnhancementSettings(),
), ),
_buildSubSettings( _buildSubSettings(
context, context,
@ -966,12 +966,22 @@ class _AlbumSettingsState extends State<_AlbumSettings> {
static final _log = Logger("widget.settings._AlbumSettingsState"); 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 @override
createState() => _EnhancementSettingsState(); createState() => _EnhancementSettingsState();
} }
class _EnhancementSettingsState extends State<_EnhancementSettings> { class _EnhancementSettingsState extends State<EnhancementSettings> {
@override @override
initState() { initState() {
super.initState(); super.initState();