Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: original image path was used images when sharing from share extension #2604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/wire/android/model/ImageAsset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package com.wire.android.model

import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import com.wire.android.util.ui.WireSessionImageLoader
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserAssetId
import okio.Path

@Stable
sealed class ImageAsset(private val imageLoader: WireSessionImageLoader) {
Expand All @@ -50,7 +50,7 @@ sealed class ImageAsset(private val imageLoader: WireSessionImageLoader) {
@Stable
data class LocalImageAsset(
private val imageLoader: WireSessionImageLoader,
val dataUri: Uri,
val dataPath: Path,
val idKey: String
) : ImageAsset(imageLoader) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
size = fileMetadata.sizeInBytes,
mimeType = mimeType,
dataPath = tempAssetPath,
dataUri = uri,
key = assetKey,
width = imgWidth,
height = imgHeight,
Expand All @@ -460,7 +459,6 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
size = fileMetadata.sizeInBytes,
mimeType = mimeType,
dataPath = tempAssetPath,
dataUri = uri,
key = assetKey
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wire.android.ui.sharing

import android.net.Uri
import androidx.compose.runtime.Composable
import com.wire.android.model.Clickable
import com.wire.android.model.ImageAsset
Expand Down Expand Up @@ -70,17 +69,15 @@ sealed class ImportedMediaAsset(
open val size: Long,
open val mimeType: String,
open val dataPath: Path,
open val dataUri: Uri,
open val key: String
) {
class GenericAsset(
override val name: String,
override val size: Long,
override val mimeType: String,
override val dataPath: Path,
override val dataUri: Uri,
override val key: String
) : ImportedMediaAsset(name, size, mimeType, dataPath, dataUri, key)
) : ImportedMediaAsset(name, size, mimeType, dataPath, key)

class Image(
val width: Int,
Expand All @@ -89,10 +86,9 @@ sealed class ImportedMediaAsset(
override val size: Long,
override val mimeType: String,
override val dataPath: Path,
override val dataUri: Uri,
override val key: String,
val wireSessionImageLoader: WireSessionImageLoader
) : ImportedMediaAsset(name, size, mimeType, dataPath, dataUri, key) {
val localImageAsset = ImageAsset.LocalImageAsset(wireSessionImageLoader, dataUri, key)
) : ImportedMediaAsset(name, size, mimeType, dataPath, key) {
val localImageAsset = ImageAsset.LocalImageAsset(wireSessionImageLoader, dataPath, key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@

package com.wire.android.util.ui

import android.content.Context
import coil.ImageLoader
import coil.decode.DataSource
import coil.fetch.DrawableResult
import coil.fetch.FetchResult
import coil.fetch.Fetcher
import coil.request.Options
import com.wire.android.model.ImageAsset
import com.wire.android.util.toDrawable
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.feature.asset.DeleteAssetUseCase
Expand All @@ -36,7 +32,6 @@ import com.wire.kalium.logic.feature.asset.MessageAssetResult
import com.wire.kalium.logic.feature.asset.PublicAssetResult

internal class AssetImageFetcher(
private val context: Context,
private val assetFetcherParameters: AssetFetcherParameters,
private val getPublicAsset: GetAvatarAssetUseCase,
private val getPrivateAsset: GetMessageAssetUseCase,
Expand Down Expand Up @@ -79,15 +74,7 @@ internal class AssetImageFetcher(
}
}

is ImageAsset.LocalImageAsset -> {
data.dataUri.toDrawable(context)?.let {
DrawableResult(
drawable = it,
isSampled = true,
dataSource = DataSource.DISK
)
}
}
is ImageAsset.LocalImageAsset -> drawableResultWrapper.toFetchResult(data.dataPath)
}
}
}
Expand All @@ -103,7 +90,6 @@ internal class AssetImageFetcher(
private val getPrivateAssetUseCase: GetMessageAssetUseCase,
private val deleteAssetUseCase: DeleteAssetUseCase,
private val drawableResultWrapper: DrawableResultWrapper,
private val context: Context
) : Fetcher.Factory<ImageAsset> {
override fun create(
data: ImageAsset,
Expand All @@ -115,7 +101,6 @@ internal class AssetImageFetcher(
getPrivateAsset = getPrivateAssetUseCase,
deleteAsset = deleteAssetUseCase,
drawableResultWrapper = drawableResultWrapper,
context = context
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class WireSessionImageLoader(
getPrivateAssetUseCase = getPrivateAsset,
deleteAssetUseCase = deleteAsset,
drawableResultWrapper = DrawableResultWrapper(resources),
context = context
)
)
if (SDK_INT >= 28) {
Expand Down
21 changes: 11 additions & 10 deletions app/src/test/kotlin/com/wire/android/model/ImageAssetTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.wire.android.model

import android.net.Uri
import androidx.core.net.toUri
import com.wire.android.util.ui.WireSessionImageLoader
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.UserAssetId
Expand All @@ -28,6 +27,8 @@ import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockk
import io.mockk.mockkStatic
import okio.Path
import okio.Path.Companion.toPath
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBeEqualTo
import org.junit.jupiter.api.BeforeEach
Expand All @@ -46,21 +47,21 @@ class ImageAssetTest {
every { Uri.parse(any()) } returns mockUri
}

fun createUserAvatarAsset(userAssetId: UserAssetId) = ImageAsset.UserAvatarAsset(
private fun createUserAvatarAsset(userAssetId: UserAssetId) = ImageAsset.UserAvatarAsset(
imageLoader, userAssetId
)

fun createPrivateAsset(
private fun createPrivateAsset(
conversationId: ConversationId,
messageId: String,
isSelfAsset: Boolean
) = ImageAsset.PrivateAsset(imageLoader, conversationId, messageId, isSelfAsset)

fun createLocalAsset(
dataUri: Uri,
private fun createLocalAsset(
dataPath: Path,
imageKey: String
): ImageAsset.LocalImageAsset {
return ImageAsset.LocalImageAsset(imageLoader, dataUri, imageKey)
return ImageAsset.LocalImageAsset(imageLoader, dataPath, imageKey)
}

@Test
Expand Down Expand Up @@ -138,7 +139,7 @@ class ImageAssetTest {
@Test
fun givenEqualUriAndKeyLocalAssets_whenGettingUniqueKey_thenResultsShouldBeEqual() {
val assetKey = "assetKey"
val localAssetUri = "local-uri".toUri()
val localAssetUri = "local-uri".toPath()

val subject1 = createLocalAsset(
localAssetUri,
Expand All @@ -154,7 +155,7 @@ class ImageAssetTest {

@Test
fun givenSameUriButDifferentKeyLocalAssets_whenGettingUniqueKey_thenResultsShouldBeDifferent() {
val assetUri = "assetUri".toUri()
val assetUri = "assetUri".toPath()
val assetKey = "assetKey"

val baseSubject = createLocalAsset(
Expand All @@ -171,8 +172,8 @@ class ImageAssetTest {

@Test
fun givenSameKeyButDifferentUriLocalAssets_whenGettingUniqueKey_thenResultsShouldBeTheSame() {
val assetUri1 = "assetUri1".toUri()
val assetUri2 = "assetUri2".toUri()
val assetUri1 = "assetUri1".toPath()
val assetUri2 = "assetUri2".toPath()
val assetKey = "assetKey"

val baseSubject = createLocalAsset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ internal class AssetImageFetcherTest {
getPublicAsset = getPublicAsset,
getPrivateAsset = getPrivateAsset,
deleteAsset = deleteAsset,
drawableResultWrapper = drawableResultWrapper,
context = mockContext
drawableResultWrapper = drawableResultWrapper
)
}

Expand Down
Loading