2023-04-13 17:32:31 +02:00
|
|
|
import 'package:copy_with/copy_with.dart';
|
2023-04-28 19:21:53 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
2023-04-13 17:32:31 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
|
|
|
import 'package:nc_photos/entity/album.dart';
|
|
|
|
import 'package:nc_photos/entity/album/provider.dart';
|
|
|
|
import 'package:nc_photos/entity/collection.dart';
|
|
|
|
import 'package:nc_photos/entity/collection_item/util.dart';
|
|
|
|
import 'package:to_string/to_string.dart';
|
|
|
|
|
|
|
|
part 'album.g.dart';
|
|
|
|
|
|
|
|
/// Album provided by our app
|
|
|
|
@genCopyWith
|
|
|
|
@toString
|
2023-04-28 19:21:53 +02:00
|
|
|
class CollectionAlbumProvider
|
|
|
|
with EquatableMixin
|
|
|
|
implements CollectionContentProvider {
|
2023-04-13 17:32:31 +02:00
|
|
|
const CollectionAlbumProvider({
|
|
|
|
required this.account,
|
|
|
|
required this.album,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => _$toString();
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get fourCc => "ALBM";
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get id => album.albumFile!.fileId!.toString();
|
|
|
|
|
|
|
|
@override
|
|
|
|
int? get count {
|
|
|
|
if (album.provider is AlbumStaticProvider) {
|
|
|
|
return (album.provider as AlbumStaticProvider).items.length;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
DateTime get lastModified =>
|
|
|
|
album.provider.latestItemTime ?? album.lastUpdated;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<CollectionCapability> get capabilities => [
|
2023-04-15 10:39:24 +02:00
|
|
|
CollectionCapability.sort,
|
|
|
|
CollectionCapability.rename,
|
2023-04-17 18:15:29 +02:00
|
|
|
CollectionCapability.manualCover,
|
2023-04-13 17:32:31 +02:00
|
|
|
if (album.provider is AlbumStaticProvider) ...[
|
|
|
|
CollectionCapability.manualItem,
|
|
|
|
CollectionCapability.manualSort,
|
|
|
|
CollectionCapability.labelItem,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2023-04-17 18:15:29 +02:00
|
|
|
/// Capabilities when this album is shared to this user by someone else
|
|
|
|
List<CollectionCapability> get guestCapabilities => [
|
|
|
|
if (album.provider is AlbumStaticProvider) ...[
|
|
|
|
CollectionCapability.manualItem,
|
|
|
|
CollectionCapability.labelItem,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2023-04-13 17:32:31 +02:00
|
|
|
@override
|
|
|
|
CollectionItemSort get itemSort => album.sortProvider.toCollectionItemSort();
|
|
|
|
|
|
|
|
@override
|
2023-04-28 19:21:53 +02:00
|
|
|
String? getCoverUrl(
|
|
|
|
int width,
|
|
|
|
int height, {
|
|
|
|
bool? isKeepAspectRatio,
|
|
|
|
}) {
|
2023-04-13 17:32:31 +02:00
|
|
|
final fd = album.coverProvider.getCover(album);
|
|
|
|
if (fd == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return api_util.getFilePreviewUrlByFileId(
|
|
|
|
account,
|
|
|
|
fd.fdId,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
2023-04-28 19:21:53 +02:00
|
|
|
isKeepAspectRatio: isKeepAspectRatio ?? false,
|
2023-04-13 17:32:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 19:21:53 +02:00
|
|
|
@override
|
|
|
|
List<Object?> get props => [account, album];
|
|
|
|
|
2023-04-13 17:32:31 +02:00
|
|
|
final Account account;
|
|
|
|
final Album album;
|
|
|
|
}
|