Regression: dynamic album cover not shown even after opening it

This commit is contained in:
Ming Ming 2023-04-22 11:43:13 +08:00
parent 0eb13273a1
commit 203eaf290a
6 changed files with 58 additions and 0 deletions

View file

@ -21,6 +21,7 @@ import 'package:nc_photos/rx_extension.dart';
import 'package:nc_photos/use_case/collection/add_file_to_collection.dart';
import 'package:nc_photos/use_case/collection/list_collection_item.dart';
import 'package:nc_photos/use_case/collection/remove_from_collection.dart';
import 'package:nc_photos/use_case/collection/update_collection_post_load.dart';
import 'package:nc_photos/use_case/remove.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:rxdart/rxdart.dart';
@ -289,6 +290,11 @@ class CollectionItemsController {
items: items,
hasNext: false,
));
final newCollection =
await UpdateCollectionPostLoad(_c)(account, collection, items);
if (newCollection != null) {
onCollectionUpdated(newCollection);
}
}
} catch (e, stackTrace) {
_dataStreamController

View file

@ -79,6 +79,10 @@ abstract class CollectionAdapter {
/// Return if the cover of this collection has been manually set
bool isManualCover();
/// Called when the collection items belonging to this collection is first
/// loaded
Future<Collection?> updatePostLoad(List<CollectionItem> items);
}
abstract class CollectionItemAdapter {

View file

@ -24,6 +24,7 @@ import 'package:nc_photos/use_case/album/edit_album.dart';
import 'package:nc_photos/use_case/album/remove_album.dart';
import 'package:nc_photos/use_case/album/remove_from_album.dart';
import 'package:nc_photos/use_case/preprocess_album.dart';
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_common/type.dart';
import 'package:tuple/tuple.dart';
@ -222,6 +223,23 @@ class CollectionAlbumAdapter implements CollectionAdapter {
bool isManualCover() =>
_provider.album.coverProvider is AlbumManualCoverProvider;
@override
Future<Collection?> updatePostLoad(List<CollectionItem> items) async {
final album = await UpdateAlbumWithActualItems(_c.albumRepo)(
account,
_provider.album,
items
.whereType<AlbumAdaptedCollectionItem>()
.map((e) => e.albumItem)
.toList(),
);
if (!identical(album, _provider.album)) {
return CollectionBuilder.byAlbum(account, album);
} else {
return null;
}
}
final DiContainer _c;
final Account account;
final Collection collection;

View file

@ -145,6 +145,10 @@ class CollectionNcAlbumAdapter implements CollectionAdapter {
@override
bool isManualCover() => false;
@override
Future<Collection?> updatePostLoad(List<CollectionItem> items) =>
Future.value(null);
Future<NcAlbum> _syncRemote() async {
final remote = await ListNcAlbum(_c)(account).last;
return remote.firstWhere((e) => e.compareIdentity(_provider.album));

View file

@ -42,4 +42,8 @@ mixin CollectionReadOnlyAdapter implements CollectionAdapter {
@override
bool isManualCover() => false;
@override
Future<Collection?> updatePostLoad(List<CollectionItem> items) =>
Future.value(null);
}

View file

@ -0,0 +1,22 @@
import 'package:nc_photos/account.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_item.dart';
class UpdateCollectionPostLoad {
const UpdateCollectionPostLoad(this._c);
/// Update the collection after its items are loaded if necessary
///
/// Return a new collection if its updated, otherwise null
Future<Collection?> call(
Account account,
Collection collection,
List<CollectionItem> items,
) {
return CollectionAdapter.of(_c, account, collection).updatePostLoad(items);
}
final DiContainer _c;
}