feat(mobile): persist album sort order (#1997)

Co-authored-by: Atul Mehla <>
This commit is contained in:
Atul Mehla 2023-03-19 17:24:31 -02:30 committed by GitHub
parent 646b912da8
commit 719f074ccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -8,6 +8,8 @@ import 'package:immich_mobile/modules/album/providers/album.provider.dart';
import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart'; import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart';
import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/models/album.dart'; import 'package:immich_mobile/shared/models/album.dart';
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
class LibraryPage extends HookConsumerWidget { class LibraryPage extends HookConsumerWidget {
const LibraryPage({Key? key}) : super(key: key); const LibraryPage({Key? key}) : super(key: key);
@ -16,6 +18,7 @@ class LibraryPage extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final albums = ref.watch(albumProvider); final albums = ref.watch(albumProvider);
var isDarkMode = Theme.of(context).brightness == Brightness.dark; var isDarkMode = Theme.of(context).brightness == Brightness.dark;
var settings = ref.watch(appSettingsServiceProvider);
useEffect( useEffect(
() { () {
@ -40,7 +43,7 @@ class LibraryPage extends HookConsumerWidget {
); );
} }
final selectedAlbumSortOrder = useState(0); final selectedAlbumSortOrder = useState(settings.getSetting(AppSettingsEnum.selectedAlbumSortOrder));
List<Album> sortedAlbums() { List<Album> sortedAlbums() {
if (selectedAlbumSortOrder.value == 0) { if (selectedAlbumSortOrder.value == 0) {
@ -91,6 +94,7 @@ class LibraryPage extends HookConsumerWidget {
}, },
onSelected: (int value) { onSelected: (int value) {
selectedAlbumSortOrder.value = value; selectedAlbumSortOrder.value = value;
settings.setSetting(AppSettingsEnum.selectedAlbumSortOrder, value);
}, },
child: Row( child: Row(
children: [ children: [

View file

@ -18,7 +18,8 @@ enum AppSettingsEnum<T> {
thumbnailCacheSize<int>("thumbnailCacheSize", 10000), thumbnailCacheSize<int>("thumbnailCacheSize", 10000),
imageCacheSize<int>("imageCacheSize", 350), imageCacheSize<int>("imageCacheSize", 350),
albumThumbnailCacheSize<int>("albumThumbnailCacheSize", 200), albumThumbnailCacheSize<int>("albumThumbnailCacheSize", 200),
useExperimentalAssetGrid<bool>("useExperimentalAssetGrid", false); useExperimentalAssetGrid<bool>("useExperimentalAssetGrid", false),
selectedAlbumSortOrder<int>("selectedAlbumSortOrder", 0);
const AppSettingsEnum(this.hiveKey, this.defaultValue); const AppSettingsEnum(this.hiveKey, this.defaultValue);