From dd72ec2621c9cc686997d26e20f1d2761c716c90 Mon Sep 17 00:00:00 2001 From: Thomas <9749173+uhthomas@users.noreply.github.com> Date: Sat, 7 Mar 2026 18:07:34 +0000 Subject: [PATCH] fix(mobile): correct local asset dimensions (#26677) * fix(mobile): correct local asset dimensions We are constraining the size of videos so that they play nicely with hero animations, and don't stretch in weird ways. This however caused a regression as we are not account for local assets on Android which have un-oriented dimensions. * post-orientation width and height in local sync * migration * no need to handle it in asset viewer --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com> Co-authored-by: Alex --- .../alextran/immich/sync/MessagesImplBase.kt | 7 ++++--- mobile/lib/utils/migration.dart | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt index 949720325e..05671579ae 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt @@ -185,16 +185,17 @@ open class NativeSyncApiImplBase(context: Context) : ImmichPlugin() { numericId, rawMediaType, mimeTypeColumn, specialFormatColumn, xmpColumn, c ) + val isFlipped = orientation == 90 || orientation == 270 val asset = PlatformAsset( id, name, assetType, createdAt, modifiedAt, - width, - height, + if (isFlipped) height else width, + if (isFlipped) width else height, duration, - orientation.toLong(), + 0L, isFavorite, playbackStyle = playbackStyle, ) diff --git a/mobile/lib/utils/migration.dart b/mobile/lib/utils/migration.dart index aeed9f616e..efb4d60369 100644 --- a/mobile/lib/utils/migration.dart +++ b/mobile/lib/utils/migration.dart @@ -35,7 +35,7 @@ import 'package:isar/isar.dart'; // ignore: import_rule_photo_manager import 'package:photo_manager/photo_manager.dart'; -const int targetVersion = 23; +const int targetVersion = 24; Future migrateDatabaseIfNeeded(Isar db, Drift drift) async { final hasVersion = Store.tryGet(StoreKey.version) != null; @@ -105,6 +105,10 @@ Future migrateDatabaseIfNeeded(Isar db, Drift drift) async { await _populateLocalAssetPlaybackStyle(drift); } + if (version < 24 && Store.isBetaTimelineEnabled) { + await _applyLocalAssetOrientation(drift); + } + if (version < 22 && !Store.isBetaTimelineEnabled) { await Store.put(StoreKey.needBetaMigration, true); } @@ -436,6 +440,18 @@ Future _populateLocalAssetPlaybackStyle(Drift db) async { } } +Future _applyLocalAssetOrientation(Drift db) { + final query = db.localAssetEntity.update() + ..where((filter) => (filter.orientation.equals(90) | (filter.orientation.equals(270)))); + return query.write( + LocalAssetEntityCompanion.custom( + width: db.localAssetEntity.height, + height: db.localAssetEntity.width, + orientation: const Variable(0), + ), + ); +} + AssetPlaybackStyle _toPlaybackStyle(PlatformAssetPlaybackStyle style) => switch (style) { PlatformAssetPlaybackStyle.unknown => AssetPlaybackStyle.unknown, PlatformAssetPlaybackStyle.image => AssetPlaybackStyle.image,