From 0e1f96999b8ed15fdc0b3435f36e7a057367a560 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 15 Jan 2022 22:21:22 +0800 Subject: [PATCH] En/disable memory albums --- lib/l10n/app_en.arb | 8 ++++++++ lib/l10n/untranslated-messages.txt | 14 ++++++++++++++ lib/pref.dart | 11 +++++++++++ lib/widget/home_photos.dart | 9 +++++++-- lib/widget/settings.dart | 28 ++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 1a75626a..7d600992 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -309,6 +309,14 @@ "@settingsExifSupportTrueSubtitle": { "description": "Subtitle of the EXIF support setting when the value is true. The goal is to warn user about the possible side effects of enabling this setting" }, + "settingsMemoriesTitle": "Memories", + "@settingsMemoriesTitle": { + "description": "Memory albums contain photos taken in a specific time range in the past" + }, + "settingsMemoriesSubtitle": "Show photos taken in the past", + "@settingsMemoriesSubtitle": { + "description": "Memory albums contain photos taken in a specific time range in the past" + }, "settingsAccountTitle": "Account", "settingsAccountPageTitle": "Account settings", "@settingsAccountPageTitle": { diff --git a/lib/l10n/untranslated-messages.txt b/lib/l10n/untranslated-messages.txt index 655eaea5..f20edec9 100644 --- a/lib/l10n/untranslated-messages.txt +++ b/lib/l10n/untranslated-messages.txt @@ -1,5 +1,7 @@ { "cs": [ + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsAccountTitle", "settingsAccountPageTitle", "settingsIncludedFoldersTitle", @@ -60,6 +62,8 @@ ], "de": [ + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsAccountTitle", "settingsAccountPageTitle", "settingsIncludedFoldersTitle", @@ -135,6 +139,8 @@ "el": [ "collectionsTooltip", + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsAccountTitle", "settingsAccountPageTitle", "settingsIncludedFoldersTitle", @@ -263,6 +269,8 @@ ], "es": [ + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsMapProviderTitle", "addUserInputHint", "sharedAlbumInfoDialogTitle", @@ -275,6 +283,8 @@ ], "fi": [ + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsMapProviderTitle", "addUserInputHint", "sharedAlbumInfoDialogTitle", @@ -288,6 +298,8 @@ "fr": [ "collectionsTooltip", + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsAccountTitle", "settingsAccountPageTitle", "settingsIncludedFoldersTitle", @@ -396,6 +408,8 @@ ], "ru": [ + "settingsMemoriesTitle", + "settingsMemoriesSubtitle", "settingsAccountTitle", "settingsAccountPageTitle", "settingsIncludedFoldersTitle", diff --git a/lib/pref.dart b/lib/pref.dart index 23f04e15..a7c9ac13 100644 --- a/lib/pref.dart +++ b/lib/pref.dart @@ -228,6 +228,14 @@ class AccountPref { value, (key, value) => provider.setBool(key, value)); + bool? isEnableMemoryAlbum() => provider.getBool(PrefKey.isEnableMemoryAlbum); + bool isEnableMemoryAlbumOr([bool def = false]) => + isEnableMemoryAlbum() ?? def; + Future setEnableMemoryAlbum(bool value) => _set( + PrefKey.isEnableMemoryAlbum, + 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)) { @@ -430,6 +438,7 @@ enum PrefKey { isEnableFaceRecognitionApp, shareFolder, hasNewSharedAlbum, + isEnableMemoryAlbum, } extension on PrefKey { @@ -485,6 +494,8 @@ extension on PrefKey { return "shareFolder"; case PrefKey.hasNewSharedAlbum: return "hasNewSharedAlbum"; + case PrefKey.isEnableMemoryAlbum: + return "isEnableMemoryAlbum"; } } } diff --git a/lib/widget/home_photos.dart b/lib/widget/home_photos.dart index f493f5d2..bbc9b8a6 100644 --- a/lib/widget/home_photos.dart +++ b/lib/widget/home_photos.dart @@ -139,7 +139,9 @@ class _HomePhotosState extends State _buildAppBar(context), if (_metadataTaskState != MetadataTaskState.idle) _buildMetadataTaskHeader(context), - if (_smartAlbums.isNotEmpty) + if (AccountPref.of(widget.account) + .isEnableMemoryAlbumOr(true) && + _smartAlbums.isNotEmpty) _buildSmartAlbumList(context), SliverPadding( padding: const EdgeInsets.symmetric(vertical: 8), @@ -627,7 +629,10 @@ class _HomePhotosState extends State ? 0 : _metadataTaskHeaderHeight; final smartAlbumListHeight = - _smartAlbums.isNotEmpty ? _SmartAlbumItem.height : 0; + AccountPref.of(widget.account).isEnableMemoryAlbumOr(true) && + _smartAlbums.isNotEmpty + ? _SmartAlbumItem.height + : 0; // scroll extent = list height - widget viewport height // + sliver app bar height + metadata task header height // + smart album list height + list padding diff --git a/lib/widget/settings.dart b/lib/widget/settings.dart index 4c16a132..cc14bbda 100644 --- a/lib/widget/settings.dart +++ b/lib/widget/settings.dart @@ -59,6 +59,9 @@ class _SettingsState extends State { initState() { super.initState(); _isEnableExif = Pref().isEnableExifOr(); + + final settings = AccountPref.of(widget.account); + _isEnableMemoryAlbum = settings.isEnableMemoryAlbumOr(true); } @override @@ -96,6 +99,12 @@ class _SettingsState extends State { value: _isEnableExif, onChanged: (value) => _onExifSupportChanged(context, value), ), + SwitchListTile( + title: Text(L10n.global().settingsMemoriesTitle), + subtitle: Text(L10n.global().settingsMemoriesSubtitle), + value: _isEnableMemoryAlbum, + onChanged: _onEnableMemoryAlbumChanged, + ), _buildSubSettings( context, leading: Icon( @@ -283,6 +292,24 @@ class _SettingsState extends State { } } + Future _onEnableMemoryAlbumChanged(bool value) async { + _log.info("[_onEnableMemoryAlbumChanged] New value: $value"); + final oldValue = _isEnableMemoryAlbum; + setState(() { + _isEnableMemoryAlbum = value; + }); + if (!await AccountPref.of(widget.account).setEnableMemoryAlbum(value)) { + _log.severe("[_onEnableMemoryAlbumChanged] Failed writing pref"); + SnackBarManager().showSnackBar(SnackBar( + content: Text(L10n.global().writePreferenceFailureNotification), + duration: k.snackBarDurationNormal, + )); + setState(() { + _isEnableMemoryAlbum = oldValue; + }); + } + } + void _onCaptureLogChanged(BuildContext context, bool value) async { if (value) { final result = await showDialog( @@ -359,6 +386,7 @@ class _SettingsState extends State { } late bool _isEnableExif; + late bool _isEnableMemoryAlbum; static final _log = Logger("widget.settings._SettingsState");