mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Fix initial value of collection sort not read from pref
This commit is contained in:
parent
f554bc212a
commit
3be4851425
4 changed files with 21 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/collection/util.dart';
|
||||
import 'package:nc_photos/entity/pref.dart';
|
||||
import 'package:nc_photos/language_util.dart';
|
||||
import 'package:nc_photos/object_extension.dart';
|
||||
|
@ -38,9 +39,9 @@ class PrefController {
|
|||
value: value,
|
||||
);
|
||||
|
||||
Future<bool> setHomeAlbumsSort(int value) => _set<int>(
|
||||
Future<bool> setHomeAlbumsSort(CollectionSort value) => _set<CollectionSort>(
|
||||
controller: _homeAlbumsSortController,
|
||||
setter: (pref, value) => pref.setHomeAlbumsSort(value),
|
||||
setter: (pref, value) => pref.setHomeAlbumsSort(value.index),
|
||||
value: value,
|
||||
);
|
||||
|
||||
|
@ -190,8 +191,8 @@ class PrefController {
|
|||
late final _albumBrowserZoomLevelController =
|
||||
BehaviorSubject.seeded(_c.pref.getAlbumBrowserZoomLevelOr(0));
|
||||
@npSubjectAccessor
|
||||
late final _homeAlbumsSortController =
|
||||
BehaviorSubject.seeded(_c.pref.getHomeAlbumsSortOr(0));
|
||||
late final _homeAlbumsSortController = BehaviorSubject.seeded(
|
||||
CollectionSort.values[_c.pref.getHomeAlbumsSortOr(0)]);
|
||||
@npSubjectAccessor
|
||||
late final _isEnableExifController =
|
||||
BehaviorSubject.seeded(_c.pref.isEnableExifOr(true));
|
||||
|
|
|
@ -38,10 +38,12 @@ extension $PrefControllerNpSubjectAccessor on PrefController {
|
|||
albumBrowserZoomLevel.distinct().skip(1);
|
||||
int get albumBrowserZoomLevelValue => _albumBrowserZoomLevelController.value;
|
||||
// _homeAlbumsSortController
|
||||
ValueStream<int> get homeAlbumsSort => _homeAlbumsSortController.stream;
|
||||
Stream<int> get homeAlbumsSortNew => homeAlbumsSort.skip(1);
|
||||
Stream<int> get homeAlbumsSortChange => homeAlbumsSort.distinct().skip(1);
|
||||
int get homeAlbumsSortValue => _homeAlbumsSortController.value;
|
||||
ValueStream<CollectionSort> get homeAlbumsSort =>
|
||||
_homeAlbumsSortController.stream;
|
||||
Stream<CollectionSort> get homeAlbumsSortNew => homeAlbumsSort.skip(1);
|
||||
Stream<CollectionSort> get homeAlbumsSortChange =>
|
||||
homeAlbumsSort.distinct().skip(1);
|
||||
CollectionSort get homeAlbumsSortValue => _homeAlbumsSortController.value;
|
||||
// _isEnableExifController
|
||||
ValueStream<bool> get isEnableExif => _isEnableExifController.stream;
|
||||
Stream<bool> get isEnableExifNew => isEnableExif.skip(1);
|
||||
|
|
|
@ -6,7 +6,9 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
required this.account,
|
||||
required this.controller,
|
||||
required this.prefController,
|
||||
}) : super(_State.init()) {
|
||||
}) : super(_State.init(
|
||||
sort: prefController.homeAlbumsSortValue,
|
||||
)) {
|
||||
on<_LoadCollections>(_onLoad);
|
||||
on<_ReloadCollections>(_onReload);
|
||||
on<_TransformItems>(_onTransformItems);
|
||||
|
@ -21,7 +23,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
on<_SetError>(_onSetError);
|
||||
|
||||
_subscriptions.add(prefController.homeAlbumsSortChange.listen((event) {
|
||||
add(_UpdateCollectionSort(collection_util.CollectionSort.values[event]));
|
||||
add(_UpdateCollectionSort(event));
|
||||
}));
|
||||
_subscriptions.add(controller.stream.listen((event) {
|
||||
for (final s in _itemSubscriptions) {
|
||||
|
@ -120,7 +122,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
|
||||
void _onSetCollectionSort(_SetCollectionSort ev, Emitter<_State> emit) {
|
||||
_log.info(ev);
|
||||
prefController.setHomeAlbumsSort(ev.sort.index);
|
||||
prefController.setHomeAlbumsSort(ev.sort);
|
||||
}
|
||||
|
||||
void _onSetItemCount(_SetItemCount ev, Emitter<_State> emit) {
|
||||
|
|
|
@ -14,10 +14,12 @@ class _State {
|
|||
required this.removeError,
|
||||
});
|
||||
|
||||
factory _State.init() {
|
||||
return const _State(
|
||||
factory _State.init({
|
||||
required collection_util.CollectionSort sort,
|
||||
}) {
|
||||
return _State(
|
||||
collections: [],
|
||||
sort: collection_util.CollectionSort.dateDescending,
|
||||
sort: sort,
|
||||
isLoading: false,
|
||||
transformedItems: [],
|
||||
selectedItems: {},
|
||||
|
|
Loading…
Reference in a new issue