123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import 'package:photos/core/constants.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- enum AlbumSortKey {
- albumName,
- newestPhoto,
- lastUpdated,
- }
- class LocalSettings {
- LocalSettings._privateConstructor();
- static final LocalSettings instance = LocalSettings._privateConstructor();
- static const kCollectionSortPref = "collection_sort_pref";
- static const kPhotoGridSize = "photo_grid_size";
- late SharedPreferences _prefs;
- void init(SharedPreferences preferences) {
- _prefs = preferences;
- }
- AlbumSortKey albumSortKey() {
- return AlbumSortKey.values[_prefs.getInt(kCollectionSortPref) ?? 0];
- }
- Future<bool> setAlbumSortKey(AlbumSortKey key) {
- return _prefs.setInt(kCollectionSortPref, key.index);
- }
- int getPhotoGridSize() {
- if (_prefs.containsKey(kPhotoGridSize)) {
- return _prefs.getInt(kPhotoGridSize)!;
- } else {
- return photoGridSizeDefault;
- }
- }
- Future<void> setPhotoGridSize(int value) async {
- await _prefs.setInt(kPhotoGridSize, value);
- }
- }
|