mirror of
https://github.com/immich-app/immich.git
synced 2025-01-16 16:56:46 +01:00
fix(mobile): more efficient loading local image on ios (#13426)
This commit is contained in:
parent
346a0847ef
commit
452ce73e7f
1 changed files with 8 additions and 34 deletions
|
@ -7,8 +7,6 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
import 'package:immich_mobile/entities/store.entity.dart';
|
|
||||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
|
||||||
import 'package:photo_manager/photo_manager.dart' show ThumbnailSize;
|
import 'package:photo_manager/photo_manager.dart' show ThumbnailSize;
|
||||||
|
|
||||||
/// The local image provider for an asset
|
/// The local image provider for an asset
|
||||||
|
@ -19,12 +17,6 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||||
required this.asset,
|
required this.asset,
|
||||||
}) : assert(asset.local != null, 'Only usable when asset.local is set');
|
}) : assert(asset.local != null, 'Only usable when asset.local is set');
|
||||||
|
|
||||||
/// Whether to show the original file or load a compressed version
|
|
||||||
bool get _useOriginal => Store.get(
|
|
||||||
AppSettingsEnum.loadOriginal.storeKey,
|
|
||||||
AppSettingsEnum.loadOriginal.defaultValue,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Converts an [ImageProvider]'s settings plus an [ImageConfiguration] to a key
|
/// Converts an [ImageProvider]'s settings plus an [ImageConfiguration] to a key
|
||||||
/// that describes the precise image to load.
|
/// that describes the precise image to load.
|
||||||
@override
|
@override
|
||||||
|
@ -68,34 +60,16 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset.isImage) {
|
if (asset.isImage) {
|
||||||
/// Using 2K thumbnail for local iOS image to avoid double swiping issue
|
final File? file = await asset.local?.originFile;
|
||||||
if (Platform.isIOS) {
|
if (file == null) {
|
||||||
final largeImageBytes = _useOriginal
|
throw StateError("Opening file for asset ${asset.fileName} failed");
|
||||||
? await asset.local?.originBytes
|
}
|
||||||
: await asset.local
|
try {
|
||||||
?.thumbnailDataWithSize(const ThumbnailSize(3840, 2160));
|
final buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
|
||||||
|
|
||||||
if (largeImageBytes == null) {
|
|
||||||
throw StateError(
|
|
||||||
"Loading thumb for local photo ${asset.fileName} failed",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final buffer = await ui.ImmutableBuffer.fromUint8List(largeImageBytes);
|
|
||||||
final codec = await decode(buffer);
|
final codec = await decode(buffer);
|
||||||
yield codec;
|
yield codec;
|
||||||
} else {
|
} catch (error) {
|
||||||
// Use the original file for Android
|
throw StateError("Loading asset ${asset.fileName} failed");
|
||||||
final File? file = await asset.local?.originFile;
|
|
||||||
if (file == null) {
|
|
||||||
throw StateError("Opening file for asset ${asset.fileName} failed");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
final buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
|
|
||||||
final codec = await decode(buffer);
|
|
||||||
yield codec;
|
|
||||||
} catch (error) {
|
|
||||||
throw StateError("Loading asset ${asset.fileName} failed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue