mirror of
https://github.com/immich-app/immich.git
synced 2026-05-20 06:22:18 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1cc0ca9935 |
@@ -177,8 +177,13 @@ ImageProvider getFullImageProvider(BaseAsset asset, {Size size = const Size(1080
|
|||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageProvider? getThumbnailImageProvider(BaseAsset asset, {Size size = kThumbnailResolution, bool edited = true}) {
|
ImageProvider? getThumbnailImageProvider(
|
||||||
if (_shouldUseLocalAsset(asset)) {
|
BaseAsset asset, {
|
||||||
|
Size size = kThumbnailResolution,
|
||||||
|
bool edited = true,
|
||||||
|
bool localFailed = false,
|
||||||
|
}) {
|
||||||
|
if (_shouldUseLocalAsset(asset) && !localFailed) {
|
||||||
final id = asset is LocalAsset ? asset.id : (asset as RemoteAsset).localId!;
|
final id = asset is LocalAsset ? asset.id : (asset as RemoteAsset).localId!;
|
||||||
return LocalThumbProvider(id: id, size: size, assetType: asset.type);
|
return LocalThumbProvider(id: id, size: size, assetType: asset.type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
import 'package:immich_mobile/extensions/theme_extensions.dart';
|
import 'package:immich_mobile/extensions/theme_extensions.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/images/image_provider.dart';
|
import 'package:immich_mobile/presentation/widgets/images/image_provider.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/images/local_image_provider.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/images/remote_image_provider.dart';
|
import 'package:immich_mobile/presentation/widgets/images/remote_image_provider.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/images/thumb_hash_provider.dart';
|
import 'package:immich_mobile/presentation/widgets/images/thumb_hash_provider.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/timeline/constants.dart';
|
import 'package:immich_mobile/presentation/widgets/timeline/constants.dart';
|
||||||
@@ -18,24 +19,34 @@ class Thumbnail extends StatefulWidget {
|
|||||||
final ImageProvider? imageProvider;
|
final ImageProvider? imageProvider;
|
||||||
final ImageProvider? thumbhashProvider;
|
final ImageProvider? thumbhashProvider;
|
||||||
final BoxFit fit;
|
final BoxFit fit;
|
||||||
|
final Size size;
|
||||||
|
final BaseAsset? asset;
|
||||||
|
|
||||||
const Thumbnail({this.imageProvider, this.fit = BoxFit.cover, this.thumbhashProvider, super.key});
|
const Thumbnail({
|
||||||
|
this.imageProvider,
|
||||||
|
this.fit = BoxFit.cover,
|
||||||
|
this.thumbhashProvider,
|
||||||
|
this.size = kThumbnailResolution,
|
||||||
|
this.asset,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
Thumbnail.remote({
|
Thumbnail.remote({
|
||||||
required String remoteId,
|
required String remoteId,
|
||||||
required String thumbhash,
|
required String thumbhash,
|
||||||
this.fit = BoxFit.cover,
|
this.fit = BoxFit.cover,
|
||||||
Size size = kThumbnailResolution,
|
this.size = kThumbnailResolution,
|
||||||
super.key,
|
super.key,
|
||||||
}) : imageProvider = RemoteImageProvider.thumbnail(assetId: remoteId, thumbhash: thumbhash),
|
}) : imageProvider = RemoteImageProvider.thumbnail(assetId: remoteId, thumbhash: thumbhash),
|
||||||
thumbhashProvider = null;
|
thumbhashProvider = null,
|
||||||
|
asset = null;
|
||||||
|
|
||||||
Thumbnail.fromAsset({
|
Thumbnail.fromAsset({
|
||||||
required BaseAsset? asset,
|
required this.asset,
|
||||||
this.fit = BoxFit.cover,
|
this.fit = BoxFit.cover,
|
||||||
|
|
||||||
/// The logical UI size of the thumbnail. This is only used to determine the ideal image resolution and does not affect the widget size.
|
/// The logical UI size of the thumbnail. This is only used to determine the ideal image resolution and does not affect the widget size.
|
||||||
Size size = kThumbnailResolution,
|
this.size = kThumbnailResolution,
|
||||||
super.key,
|
super.key,
|
||||||
}) : thumbhashProvider = switch (asset) {
|
}) : thumbhashProvider = switch (asset) {
|
||||||
RemoteAsset() when asset.thumbHash != null && asset.localId == null => ThumbHashProvider(
|
RemoteAsset() when asset.thumbHash != null && asset.localId == null => ThumbHashProvider(
|
||||||
@@ -105,9 +116,8 @@ class _ThumbnailState extends State<Thumbnail> with SingleTickerProviderStateMix
|
|||||||
thumbhashStream.addListener(thumbhashStreamListener);
|
thumbhashStream.addListener(thumbhashStreamListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadFromImageProvider() {
|
void _loadFromImageProvider(ImageProvider? imageProvider) {
|
||||||
_stopListeningToImageStream();
|
_stopListeningToImageStream();
|
||||||
final imageProvider = widget.imageProvider;
|
|
||||||
if (imageProvider == null) return;
|
if (imageProvider == null) return;
|
||||||
|
|
||||||
final imageStream = _imageStream = imageProvider.resolve(ImageConfiguration.empty);
|
final imageStream = _imageStream = imageProvider.resolve(ImageConfiguration.empty);
|
||||||
@@ -142,8 +152,18 @@ class _ThumbnailState extends State<Thumbnail> with SingleTickerProviderStateMix
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onError: (exception, stackTrace) {
|
onError: (exception, stackTrace) {
|
||||||
log.severe('Error loading image: $exception', exception, stackTrace);
|
|
||||||
_stopListeningToImageStream();
|
_stopListeningToImageStream();
|
||||||
|
|
||||||
|
if (imageProvider is LocalThumbProvider && widget.asset != null) {
|
||||||
|
ImageProvider? nextProvider = getThumbnailImageProvider(widget.asset!, size: widget.size, localFailed: true);
|
||||||
|
if (nextProvider != null && nextProvider != imageProvider) {
|
||||||
|
log.fine('Error loading image, retrying with other provider: $exception', exception, stackTrace);
|
||||||
|
_loadFromImageProvider(nextProvider);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.severe('Error loading image: $exception', exception, stackTrace);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
imageStream.addListener(imageStreamListener);
|
imageStream.addListener(imageStreamListener);
|
||||||
@@ -180,7 +200,7 @@ class _ThumbnailState extends State<Thumbnail> with SingleTickerProviderStateMix
|
|||||||
_previousImage?.dispose();
|
_previousImage?.dispose();
|
||||||
_previousImage = null;
|
_previousImage = null;
|
||||||
}
|
}
|
||||||
_loadFromImageProvider();
|
_loadFromImageProvider(widget.imageProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_providerImage == null && oldWidget.thumbhashProvider != widget.thumbhashProvider) {
|
if (_providerImage == null && oldWidget.thumbhashProvider != widget.thumbhashProvider) {
|
||||||
@@ -195,7 +215,7 @@ class _ThumbnailState extends State<Thumbnail> with SingleTickerProviderStateMix
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _loadImage() {
|
void _loadImage() {
|
||||||
_loadFromImageProvider();
|
_loadFromImageProvider(widget.imageProvider);
|
||||||
_loadFromThumbhashProvider();
|
_loadFromThumbhashProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user