2024-03-25 03:37:31 +08:00
|
|
|
part of '../../photo_gallery.dart';
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
/// Fetches the given album thumbnail from the gallery.
|
|
|
|
class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
2023-07-30 00:54:28 +08:00
|
|
|
/// ImageProvider of album thumbnail
|
2020-08-14 18:07:27 +08:00
|
|
|
const AlbumThumbnailProvider({
|
2023-05-13 15:49:58 +08:00
|
|
|
required this.album,
|
2020-08-14 18:07:27 +08:00
|
|
|
this.height,
|
|
|
|
this.width,
|
|
|
|
this.highQuality = false,
|
2021-03-18 12:00:31 +00:00
|
|
|
});
|
2020-08-14 18:07:27 +08:00
|
|
|
|
2023-07-30 00:54:28 +08:00
|
|
|
/// Album info
|
2023-05-13 15:49:58 +08:00
|
|
|
final Album album;
|
2023-07-30 00:54:28 +08:00
|
|
|
|
|
|
|
/// Height of album thumbnail
|
2021-03-18 12:00:31 +00:00
|
|
|
final int? height;
|
2023-07-30 00:54:28 +08:00
|
|
|
|
|
|
|
/// Width of album thumbnail
|
2021-03-18 12:00:31 +00:00
|
|
|
final int? width;
|
2023-07-30 00:54:28 +08:00
|
|
|
|
|
|
|
/// Whether using high quality of album thumbnail
|
2021-03-18 12:00:31 +00:00
|
|
|
final bool? highQuality;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
@override
|
2023-05-16 00:30:33 +08:00
|
|
|
ImageStreamCompleter loadImage(key, decode) {
|
2020-08-14 18:07:27 +08:00
|
|
|
return MultiFrameImageStreamCompleter(
|
|
|
|
codec: _loadAsync(key, decode),
|
|
|
|
scale: 1.0,
|
|
|
|
informationCollector: () sync* {
|
2023-05-13 15:49:58 +08:00
|
|
|
yield ErrorDescription('Id: ${album.id}');
|
2020-08-14 18:07:27 +08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-16 00:30:33 +08:00
|
|
|
Future<ui.Codec> _loadAsync(AlbumThumbnailProvider key, ImageDecoderCallback decode) async {
|
2020-08-14 18:07:27 +08:00
|
|
|
assert(key == this);
|
2023-07-25 22:36:41 +08:00
|
|
|
late ui.ImmutableBuffer buffer;
|
|
|
|
try {
|
|
|
|
final data = await PhotoGallery.getAlbumThumbnail(
|
|
|
|
albumId: album.id,
|
|
|
|
mediumType: album.mediumType,
|
|
|
|
newest: album.newest,
|
|
|
|
height: height,
|
|
|
|
width: width,
|
|
|
|
highQuality: highQuality,
|
|
|
|
);
|
2023-05-03 18:55:29 +08:00
|
|
|
buffer = await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(data));
|
2023-07-25 22:36:41 +08:00
|
|
|
} catch (e) {
|
2023-05-03 18:55:29 +08:00
|
|
|
buffer = await ui.ImmutableBuffer.fromAsset("packages/photo_gallery/images/grey.bmp");
|
|
|
|
}
|
|
|
|
return decode(buffer);
|
2020-08-14 18:07:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<AlbumThumbnailProvider> obtainKey(ImageConfiguration configuration) {
|
|
|
|
return SynchronousFuture<AlbumThumbnailProvider>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-03-25 02:13:46 +08:00
|
|
|
bool operator ==(Object other) {
|
2020-08-14 18:07:27 +08:00
|
|
|
if (other.runtimeType != runtimeType) return false;
|
2024-03-25 02:13:46 +08:00
|
|
|
final typedOther = other as AlbumThumbnailProvider;
|
2023-05-13 15:49:58 +08:00
|
|
|
return album.id == typedOther.album.id;
|
2020-08-14 18:07:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-05-13 15:49:58 +08:00
|
|
|
int get hashCode => album.id.hashCode;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
@override
|
2023-05-13 15:49:58 +08:00
|
|
|
String toString() => '$runtimeType("${album.id}")';
|
2020-08-14 18:07:27 +08:00
|
|
|
}
|