more refactors and logs page handling

This commit is contained in:
shenlong-tanwen
2024-10-23 02:30:46 +05:30
parent 8f47645cdb
commit a0afea04d8
90 changed files with 2386 additions and 584 deletions
@@ -14,8 +14,8 @@ class ImRemoteThumbnailCacheManager extends CacheManager {
: super(
Config(
kCacheThumbnailsKey,
maxNrOfCacheObjects: kCacheMaxNrOfThumbnails,
stalePeriod: const Duration(days: kCacheStalePeriod),
maxNrOfCacheObjects: kCacheMaxNrOfThumbnails,
),
);
}
@@ -33,8 +33,8 @@ class ImRemoteImageCacheManager extends CacheManager {
: super(
Config(
kCacheFullImagesKey,
maxNrOfCacheObjects: kCacheMaxNrOfFullImages,
stalePeriod: const Duration(days: kCacheStalePeriod),
maxNrOfCacheObjects: kCacheMaxNrOfFullImages,
),
);
}
@@ -19,7 +19,7 @@ class ImageLoadingException implements Exception {
///
/// Credit to [flutter_cached_network_image](https://github.com/Baseflow/flutter_cached_network_image/blob/develop/cached_network_image/lib/src/image_provider/_image_loader.dart)
/// for this wonderful implementation of their image loader
class ImageLoader {
abstract final class ImageLoader {
static Future<ui.Codec> loadImageFromCache(
String uri, {
required CacheManager cache,
@@ -28,8 +28,8 @@ class ImageLoader {
}) async {
final stream = cache.getFileStream(
uri,
withProgress: chunkEvents != null,
headers: di<ImApiClient>().headers,
withProgress: chunkEvents != null,
);
await for (final result in stream) {
@@ -44,8 +44,7 @@ class ImageLoader {
} else if (result is FileInfo) {
// We have the file
final buffer = await ui.ImmutableBuffer.fromFilePath(result.file.path);
final decoded = await decode(buffer);
return decoded;
return await decode(buffer);
}
}
@@ -0,0 +1,17 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:immich_mobile/service_locator.dart';
import 'package:immich_mobile/utils/immich_api_client.dart';
class ImCachedNetworkImage extends CachedNetworkImage {
ImCachedNetworkImage({
super.key,
required super.imageUrl,
super.cacheKey,
super.height,
super.width,
super.fit,
super.placeholder,
super.fadeInDuration,
super.errorWidget,
}) : super(httpHeaders: di<ImApiClient>().headers);
}
@@ -12,9 +12,9 @@ class ImImagePlaceholder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: context.colorScheme.surfaceContainerHighest,
width: 200,
height: 200,
color: context.colorScheme.surfaceContainerHighest,
);
}
}
@@ -63,13 +63,8 @@ class ImImage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return OctoImage(
fadeInDuration: const Duration(milliseconds: 0),
fadeOutDuration: Durations.short4,
placeholderBuilder: (_) => placeholder,
image: ImImage.imageProvider(asset: asset),
width: width,
height: height,
fit: BoxFit.cover,
placeholderBuilder: (_) => placeholder,
errorBuilder: (_, error, stackTrace) {
if (error is PlatformException &&
error.code == "The asset not found!") {
@@ -86,6 +81,11 @@ class ImImage extends StatelessWidget {
color: context.colorScheme.primary,
);
},
fadeOutDuration: Durations.short4,
fadeInDuration: Duration.zero,
width: width,
height: height,
fit: BoxFit.cover,
);
}
}
@@ -4,13 +4,13 @@ import 'package:immich_mobile/utils/extensions/build_context.extension.dart';
class ImLogo extends StatelessWidget {
const ImLogo({
this.width,
this.dimension,
this.filterQuality = FilterQuality.high,
super.key,
});
/// The width of the image.
final double? width;
/// The dimension of the image.
final double? dimension;
/// The rendering quality
final FilterQuality filterQuality;
@@ -18,11 +18,12 @@ class ImLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Image(
width: width,
filterQuality: filterQuality,
semanticLabel: 'Immich Logo',
image: Assets.images.immichLogo.provider(),
semanticLabel: 'Immich Logo',
width: dimension,
height: dimension,
isAntiAlias: true,
filterQuality: filterQuality,
);
}
}
@@ -43,10 +44,10 @@ class ImLogoText extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Image(
semanticLabel: 'Immich Logo Text',
image: (context.isDarkTheme
? Assets.images.immichTextDark.provider
: Assets.images.immichTextLight.provider)(),
semanticLabel: 'Immich Logo Text',
width: fontSize * 4,
filterQuality: FilterQuality.high,
);
@@ -77,9 +77,9 @@ class _PadAlignedIcon extends StatelessWidget {
alignment: alignment,
child: Icon(
icon,
color: Colors.white,
size: 20,
fill: (filled != null && filled!) ? 1 : null,
color: Colors.white,
),
),
);
@@ -49,12 +49,12 @@ class ImLocalImageProvider extends ImageProvider<ImLocalImageProvider> {
// Load a small thumbnail
final thumbBytes =
await di<IDeviceAssetRepository>().getThumbnail(a.localId!);
if (thumbBytes != null) {
if (thumbBytes == null) {
debugPrint("Loading thumb for ${a.name} failed");
} else {
final buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
final codec = await decode(buffer);
yield codec;
} else {
debugPrint("Loading thumb for ${a.name} failed");
}
if (asset.isImage) {
@@ -56,12 +56,12 @@ class ImLocalThumbnailProvider extends ImageProvider<ImLocalThumbnailProvider> {
// Load a small thumbnail
final thumbBytes = await di<IDeviceAssetRepository>()
.getThumbnail(a.localId!, width: 32, height: 32, quality: 75);
if (thumbBytes != null) {
if (thumbBytes == null) {
debugPrint("Loading thumb for ${a.name} failed");
} else {
final buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
final codec = await decode(buffer);
yield codec;
} else {
debugPrint("Loading thumb for ${a.name} failed");
}
final normalThumbBytes = await di<IDeviceAssetRepository>()
@@ -0,0 +1,68 @@
import 'dart:typed_data';
final Uint8List kTransparentImage = Uint8List.fromList([
0x89,
0x50,
0x4E,
0x47,
0x0D,
0x0A,
0x1A,
0x0A,
0x00,
0x00,
0x00,
0x0D,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x01,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1F,
0x15,
0xC4,
0x89,
0x00,
0x00,
0x00,
0x0A,
0x49,
0x44,
0x41,
0x54,
0x78,
0x9C,
0x63,
0x00,
0x01,
0x00,
0x00,
0x05,
0x00,
0x01,
0x0D,
0x0A,
0x2D,
0xB4,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4E,
0x44,
0xAE,
]);