import 'package:aves/model/filters/container/album_group.dart'; import 'package:aves/model/filters/container/dynamic_album.dart'; import 'package:aves/model/filters/filters.dart'; import 'package:aves/model/grouping/common.dart'; import 'package:aves/model/settings/defaults.dart'; import 'package:aves/utils/collection_utils.dart'; import 'package:aves_model/aves_model.dart'; import 'package:synchronized/synchronized.dart'; mixin NavigationSettings on SettingsAccess { bool get mustBackTwiceToExit => getBool(SettingKeys.mustBackTwiceToExitKey) ?? SettingsDefaults.mustBackTwiceToExit; set mustBackTwiceToExit(bool newValue) => set(SettingKeys.mustBackTwiceToExitKey, newValue); KeepScreenOn get keepScreenOn => getEnumOrDefault(SettingKeys.keepScreenOnKey, SettingsDefaults.keepScreenOn, KeepScreenOn.values); set keepScreenOn(KeepScreenOn newValue) => set(SettingKeys.keepScreenOnKey, newValue.toString()); HomePageSetting get homePage => getEnumOrDefault(SettingKeys.homePageKey, SettingsDefaults.homePage, HomePageSetting.values); Set get homeCustomCollection => (getStringList(SettingKeys.homeCustomCollectionKey) ?? []).map(CollectionFilter.fromJson).nonNulls.toSet(); String? get homeCustomExplorerPath => getString(SettingKeys.homeCustomExplorerPathKey); void setHome( HomePageSetting homePage, { Set customCollection = const {}, String? customExplorerPath, }) { set(SettingKeys.homePageKey, homePage.toString()); set(SettingKeys.homeCustomCollectionKey, customCollection.map((filter) => filter.toJson()).toList()); set(SettingKeys.homeCustomExplorerPathKey, customExplorerPath); } bool get enableBottomNavigationBar => getBool(SettingKeys.enableBottomNavigationBarKey) ?? SettingsDefaults.enableBottomNavigationBar; set enableBottomNavigationBar(bool newValue) => set(SettingKeys.enableBottomNavigationBarKey, newValue); bool get confirmCreateVault => getBool(SettingKeys.confirmCreateVaultKey) ?? SettingsDefaults.confirm; set confirmCreateVault(bool newValue) => set(SettingKeys.confirmCreateVaultKey, newValue); bool get confirmDeleteForever => getBool(SettingKeys.confirmDeleteForeverKey) ?? SettingsDefaults.confirm; set confirmDeleteForever(bool newValue) => set(SettingKeys.confirmDeleteForeverKey, newValue); bool get confirmMoveToBin => getBool(SettingKeys.confirmMoveToBinKey) ?? SettingsDefaults.confirm; set confirmMoveToBin(bool newValue) => set(SettingKeys.confirmMoveToBinKey, newValue); bool get confirmMoveUndatedItems => getBool(SettingKeys.confirmMoveUndatedItemsKey) ?? SettingsDefaults.confirm; set confirmMoveUndatedItems(bool newValue) => set(SettingKeys.confirmMoveUndatedItemsKey, newValue); bool get confirmAfterMoveToBin => getBool(SettingKeys.confirmAfterMoveToBinKey) ?? SettingsDefaults.confirm; set confirmAfterMoveToBin(bool newValue) => set(SettingKeys.confirmAfterMoveToBinKey, newValue); bool get setMetadataDateBeforeFileOp => getBool(SettingKeys.setMetadataDateBeforeFileOpKey) ?? SettingsDefaults.setMetadataDateBeforeFileOp; set setMetadataDateBeforeFileOp(bool newValue) => set(SettingKeys.setMetadataDateBeforeFileOpKey, newValue); List get drawerTypeBookmarks => getStringList(SettingKeys.drawerTypeBookmarksKey)?.map((v) { if (v.isEmpty) return null; return CollectionFilter.fromJson(v); }).toList() ?? SettingsDefaults.drawerTypeBookmarks; set drawerTypeBookmarks(List newValue) => set(SettingKeys.drawerTypeBookmarksKey, newValue.map((filter) => filter?.toJson() ?? '').toList()); List? get drawerAlbumBookmarks => getStringList(SettingKeys.drawerAlbumBookmarksKey)?.map(CollectionFilter.fromJson).whereType().toList(); set drawerAlbumBookmarks(List? newValue) => set(SettingKeys.drawerAlbumBookmarksKey, newValue?.map((filter) => filter.toJson()).toList()); List get drawerPageBookmarks => getStringList(SettingKeys.drawerPageBookmarksKey) ?? SettingsDefaults.drawerPageBookmarks; set drawerPageBookmarks(List newValue) => set(SettingKeys.drawerPageBookmarksKey, newValue); final _lockForBookmarks = Lock(); Future updateBookmarkedDynamicAlbums(Map changes) async { await _lockForBookmarks.synchronized(() async { final _bookmarks = drawerAlbumBookmarks; bool changed = false; if (_bookmarks != null) { changes.forEach((oldFilter, newFilter) { if (newFilter != null) { changed |= _bookmarks.replace(oldFilter, newFilter); } else { changed |= _bookmarks.remove(oldFilter); } }); } if (changed) { drawerAlbumBookmarks = _bookmarks; } }); } Future updateBookmarkedGroup(Uri oldGroupUri, Uri newGroupUri) async { await _lockForBookmarks.synchronized(() async { final _bookmarks = drawerAlbumBookmarks; bool changed = false; if (_bookmarks != null) { final grouping = FilterGrouping.forUri(oldGroupUri); if (grouping != null) { final oldFilter = grouping.uriToFilter(oldGroupUri); final newFilter = grouping.uriToFilter(newGroupUri); if (oldFilter is AlbumBaseFilter && newFilter is AlbumBaseFilter) { changed |= _bookmarks.replace(oldFilter, newFilter); } } } if (changed) { drawerAlbumBookmarks = _bookmarks; } }); } }