From 6d6c87c5825554166b1766d4f983eaba7bdd9790 Mon Sep 17 00:00:00 2001 From: IacobIonut01 Date: Fri, 14 Feb 2025 20:04:11 +0200 Subject: [PATCH] Fix shared elements animation for albums Signed-off-by: IacobIonut01 --- app/build.gradle.kts | 2 +- .../com/dot/gallery/feature_node/domain/model/Album.kt | 5 ++++- .../com/dot/gallery/feature_node/domain/model/Media.kt | 6 +++++- .../feature_node/presentation/albums/AlbumsScreen.kt | 2 ++ .../presentation/albums/components/AlbumComponent.kt | 7 +++++-- .../feature_node/presentation/util/SharedElementsExt.kt | 4 ++-- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 33dbfc263..da6c6b602 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -23,7 +23,7 @@ android { applicationId = "com.dot.gallery" minSdk = 30 targetSdk = 35 - versionCode = 31208 + versionCode = 31209 versionName = "3.1.2" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Album.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Album.kt index 16c164076..c15a94360 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Album.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Album.kt @@ -27,7 +27,10 @@ data class Album( ) : Parcelable { val key: String - get() = "{$id, $pathToThumbnail, $timestamp}" + get() = "{$id, $uri, $timestamp}" + + val idLessKey: String + get() = "{$uri, $timestamp}" @IgnoredOnParcel @Stable diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Media.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Media.kt index 9ee50a077..7aeb7a05e 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Media.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/domain/model/Media.kt @@ -13,6 +13,7 @@ import android.webkit.MimeTypeMap import androidx.room.Entity import com.dot.gallery.core.Constants import com.dot.gallery.feature_node.domain.util.UriSerializer +import com.dot.gallery.feature_node.domain.util.getUri import com.dot.gallery.feature_node.presentation.util.getDate import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable @@ -50,7 +51,10 @@ sealed class Media : Parcelable, java.io.Serializable { } val key: String - get() = "{$id, $path, $definedTimestamp}" + get() = "{$id, ${try { getUri() } catch (_: Exception) { path} }, $definedTimestamp}" + + val idLessKey: String + get() = "{${try { getUri() } catch (_: Exception) { path} }, $definedTimestamp}" @Serializable @Parcelize diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/AlbumsScreen.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/AlbumsScreen.kt index 347e87e99..0054e0c90 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/AlbumsScreen.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/AlbumsScreen.kt @@ -206,6 +206,8 @@ fun AlbumsScreen( AlbumComponent( modifier = Modifier .pinchItem(key = item.toString()) + .animateItem(), + thumbnailModifier = Modifier .mediaSharedElement( album = item, animatedVisibilityScope = animatedContentScope diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/components/AlbumComponent.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/components/AlbumComponent.kt index c74023163..efa2f4b17 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/components/AlbumComponent.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/albums/components/AlbumComponent.kt @@ -58,6 +58,7 @@ import kotlinx.coroutines.launch @Composable fun AlbumComponent( modifier: Modifier = Modifier, + thumbnailModifier: Modifier = Modifier, album: Album, isEnabled: Boolean = true, onItemClick: (Album) -> Unit, @@ -172,6 +173,7 @@ fun AlbumComponent( .aspectRatio(1f) ) { AlbumImage( + modifier = thumbnailModifier, album = album, isEnabled = isEnabled, onItemClick = onItemClick, @@ -227,6 +229,7 @@ fun AlbumComponent( @OptIn(ExperimentalFoundationApi::class) @Composable fun AlbumImage( + modifier: Modifier = Modifier, album: Album, isEnabled: Boolean, onItemClick: (Album) -> Unit, @@ -242,7 +245,7 @@ fun AlbumImage( imageVector = Icons.Outlined.AddCircleOutline, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier + modifier = modifier .fillMaxSize() .border( width = 1.dp, @@ -267,7 +270,7 @@ fun AlbumImage( ) } else { AsyncImage( - modifier = Modifier + modifier = modifier .fillMaxSize() .border( width = 1.dp, diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/util/SharedElementsExt.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/util/SharedElementsExt.kt index 14ecbe2ce..fe96685ff 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/util/SharedElementsExt.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/util/SharedElementsExt.kt @@ -21,7 +21,7 @@ context(SharedTransitionScope) fun Modifier.mediaSharedElement( media: T, animatedVisibilityScope: AnimatedVisibilityScope -): Modifier = mediaSharedElement(key = media.key, animatedVisibilityScope = animatedVisibilityScope) +): Modifier = mediaSharedElement(key = media.idLessKey, animatedVisibilityScope = animatedVisibilityScope) context(SharedTransitionScope) @Composable @@ -29,7 +29,7 @@ context(SharedTransitionScope) fun Modifier.mediaSharedElement( album: Album, animatedVisibilityScope: AnimatedVisibilityScope -): Modifier = mediaSharedElement(key = album.key, animatedVisibilityScope = animatedVisibilityScope) +): Modifier = mediaSharedElement(key = album.idLessKey, animatedVisibilityScope = animatedVisibilityScope) context(SharedTransitionScope) @Composable