Skip to content

Commit

Permalink
feat(mobile): faster image loader (#8140)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
  • Loading branch information
fyfrey and alextran1502 committed Mar 21, 2024
1 parent 5ef6215 commit 1abb0bd
Showing 1 changed file with 3 additions and 11 deletions.
Expand Up @@ -16,19 +16,15 @@ class ImageLoader {
required ImageCacheManager cache,
required ImageDecoderCallback decode,
StreamController<ImageChunkEvent>? chunkEvents,
int? height,
int? width,
}) async {
final headers = {
'x-immich-user-token': Store.get(StoreKey.accessToken),
};

final stream = cache.getImageFile(
uri,
withProgress: true,
withProgress: chunkEvents != null,
headers: headers,
maxHeight: height,
maxWidth: width,
);

await for (final result in stream) {
Expand All @@ -40,13 +36,9 @@ class ImageLoader {
expectedTotalBytes: result.totalSize,
),
);
}

if (result is FileInfo) {
} else if (result is FileInfo) {
// We have the file
final file = result.file;
final bytes = await file.readAsBytes();
final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
final buffer = await ui.ImmutableBuffer.fromFilePath(result.file.path);
final decoded = await decode(buffer);
return decoded;
}
Expand Down

0 comments on commit 1abb0bd

Please sign in to comment.