En/disable memory albums

This commit is contained in:
Ming Ming 2022-01-15 22:21:22 +08:00
parent 781d846806
commit 0e1f96999b
5 changed files with 68 additions and 2 deletions

View file

@ -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": {

View file

@ -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",

View file

@ -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<bool> setEnableMemoryAlbum(bool value) => _set<bool>(
PrefKey.isEnableMemoryAlbum,
value,
(key, value) => provider.setBool(key, value));
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> 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";
}
}
}

View file

@ -139,7 +139,9 @@ class _HomePhotosState extends State<HomePhotos>
_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<HomePhotos>
? 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

View file

@ -59,6 +59,9 @@ class _SettingsState extends State<Settings> {
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<Settings> {
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<Settings> {
}
}
Future<void> _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<bool>(
@ -359,6 +386,7 @@ class _SettingsState extends State<Settings> {
}
late bool _isEnableExif;
late bool _isEnableMemoryAlbum;
static final _log = Logger("widget.settings._SettingsState");