2020-08-14 18:07:27 +08:00
|
|
|
part of photogallery;
|
|
|
|
|
|
|
|
/// Fetches the given album thumbnail from the gallery.
|
|
|
|
class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
|
|
|
const AlbumThumbnailProvider({
|
2021-03-18 12:00:31 +00:00
|
|
|
required this.albumId,
|
2020-09-20 18:34:26 +08:00
|
|
|
this.mediumType,
|
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
|
|
|
|
|
|
|
final String albumId;
|
2021-03-18 12:00:31 +00:00
|
|
|
final MediumType? mediumType;
|
|
|
|
final int? height;
|
|
|
|
final int? width;
|
|
|
|
final bool? highQuality;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
@override
|
2023-05-03 18:55:29 +08:00
|
|
|
ImageStreamCompleter loadBuffer(key, decode) {
|
2020-08-14 18:07:27 +08:00
|
|
|
return MultiFrameImageStreamCompleter(
|
|
|
|
codec: _loadAsync(key, decode),
|
|
|
|
scale: 1.0,
|
|
|
|
informationCollector: () sync* {
|
|
|
|
yield ErrorDescription('Id: $albumId');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-03 18:55:29 +08:00
|
|
|
Future<ui.Codec> _loadAsync(AlbumThumbnailProvider key, DecoderBufferCallback decode) async {
|
2020-08-14 18:07:27 +08:00
|
|
|
assert(key == this);
|
2023-05-03 18:55:29 +08:00
|
|
|
final data = await PhotoGallery.getAlbumThumbnail(
|
2020-08-14 18:07:27 +08:00
|
|
|
albumId: albumId,
|
2020-09-20 18:34:26 +08:00
|
|
|
mediumType: mediumType,
|
2020-08-14 18:07:27 +08:00
|
|
|
height: height,
|
|
|
|
width: width,
|
|
|
|
highQuality: highQuality,
|
|
|
|
);
|
2023-05-03 18:55:29 +08:00
|
|
|
ui.ImmutableBuffer buffer;
|
|
|
|
if (data != null) {
|
|
|
|
buffer = await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(data));
|
|
|
|
} else {
|
|
|
|
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
|
|
|
|
bool operator ==(dynamic other) {
|
|
|
|
if (other.runtimeType != runtimeType) return false;
|
|
|
|
final AlbumThumbnailProvider typedOther = other;
|
|
|
|
return albumId == typedOther.albumId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-03-18 12:00:31 +00:00
|
|
|
int get hashCode => albumId.hashCode;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => '$runtimeType("$albumId")';
|
|
|
|
}
|