mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-26 08:54:42 +01:00
Filter dynamic collections from the picker
This commit is contained in:
parent
815c023ace
commit
9fb8ff6cfc
3 changed files with 13 additions and 7 deletions
|
@ -14,7 +14,7 @@ enum CollectionSort {
|
|||
}
|
||||
}
|
||||
|
||||
extension CollectionListExtension on List<Collection> {
|
||||
extension CollectionListExtension on Iterable<Collection> {
|
||||
List<Collection> sortedBy(CollectionSort by) {
|
||||
return map<Tuple2<Comparable, Collection>>((e) {
|
||||
switch (by) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:copy_with/copy_with.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
|
@ -11,7 +12,9 @@ import 'package:nc_photos/bloc_util.dart';
|
|||
import 'package:nc_photos/cache_manager_util.dart';
|
||||
import 'package:nc_photos/controller/account_controller.dart';
|
||||
import 'package:nc_photos/controller/collections_controller.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/collection.dart';
|
||||
import 'package:nc_photos/entity/collection/adapter.dart';
|
||||
import 'package:nc_photos/entity/collection/util.dart' as collection_util;
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||
|
|
|
@ -16,7 +16,7 @@ class _Bloc extends Bloc<_Event, _State> implements BlocTag {
|
|||
String get tag => _log.fullName;
|
||||
|
||||
Future<void> _onLoad(_LoadCollections ev, Emitter<_State> emit) async {
|
||||
_log.info("[_onLoad] $ev");
|
||||
_log.info(ev);
|
||||
return emit.forEach<CollectionStreamEvent>(
|
||||
controller.stream,
|
||||
onData: (data) => state.copyWith(
|
||||
|
@ -34,24 +34,27 @@ class _Bloc extends Bloc<_Event, _State> implements BlocTag {
|
|||
}
|
||||
|
||||
void _onTransformItems(_TransformItems ev, Emitter<_State> emit) {
|
||||
_log.info("[_onTransformItems] $ev");
|
||||
_log.info(ev);
|
||||
final transformed = _transformCollections(ev.collections);
|
||||
emit(state.copyWith(transformedItems: transformed));
|
||||
}
|
||||
|
||||
void _onSelectCollection(_SelectCollection ev, Emitter<_State> emit) {
|
||||
_log.info("[_onTransformItems] $ev");
|
||||
_log.info(ev);
|
||||
emit(state.copyWith(result: ev.collection));
|
||||
}
|
||||
|
||||
void _onSetError(_SetError ev, Emitter<_State> emit) {
|
||||
_log.info("[_onSetError] $ev");
|
||||
_log.info(ev);
|
||||
emit(state.copyWith(error: ExceptionEvent(ev.error, ev.stackTrace)));
|
||||
}
|
||||
|
||||
List<_Item> _transformCollections(List<Collection> collections) {
|
||||
final sorted =
|
||||
collections.sortedBy(collection_util.CollectionSort.dateDescending);
|
||||
final sorted = collections
|
||||
.where((c) => CollectionAdapter.of(
|
||||
KiwiContainer().resolve<DiContainer>(), account, c)
|
||||
.isPermitted(CollectionCapability.manualItem))
|
||||
.sortedBy(collection_util.CollectionSort.dateDescending);
|
||||
return sorted.map((c) => _Item(c)).toList();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue