From 8c0a8610661aba5db415e7bd6c41b8e7b5f5a85b Mon Sep 17 00:00:00 2001 From: Isabel Martin Date: Wed, 29 May 2024 09:44:41 -0700 Subject: [PATCH] MBL-1522: Blurry images on Campaign tab (#2046) --- app/build.gradle | 5 +- .../ui/components/ImageWithCaptionViewTest.kt | 71 ------------------- .../ui/activities/ProjectPageActivity.kt | 4 -- .../ui/views/ImageWithCaptionView.kt | 43 +++++++++-- .../res/layout/view_image_with_caption.xml | 22 +++--- 5 files changed, 49 insertions(+), 96 deletions(-) delete mode 100644 app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/ImageWithCaptionViewTest.kt diff --git a/app/build.gradle b/app/build.gradle index c1963138fb..a5a63574ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -264,7 +264,7 @@ dependencies { kapt "com.github.bumptech.glide:compiler:$glide_version" //Compose Coil - implementation("io.coil-kt:coil-compose:2.4.0") + implementation("io.coil-kt:coil-compose:2.6.0") // Firebase implementation platform('com.google.firebase:firebase-bom:32.8.1') @@ -292,9 +292,6 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$coroutines" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines" - // Zoom on Images - implementation 'io.github.aghajari:ZoomHelper:1.1.0' - // Testing testImplementation "junit:junit:4.13.2" testImplementation 'org.mockito:mockito-core:4.5.1' diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/ImageWithCaptionViewTest.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/ImageWithCaptionViewTest.kt deleted file mode 100644 index d8fa76979b..0000000000 --- a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/ImageWithCaptionViewTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.kickstarter.screenshoot.testing.ui.components - -import android.view.LayoutInflater -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.test.platform.app.InstrumentationRegistry -import com.karumi.shot.ScreenshotTest -import com.kickstarter.ApplicationComponent -import com.kickstarter.R -import com.kickstarter.screenshoot.testing.InstrumentedApp -import com.kickstarter.ui.views.ImageWithCaptionView -import org.junit.Before -import org.junit.Test - -class ImageWithCaptionViewTest : ScreenshotTest { - - lateinit var component: ApplicationComponent - - @Before - fun setup() { - // - Test Application - val app = - InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as InstrumentedApp - // - Test Dagger component for injecting on environment Mock Objects - component = app.component() - } - - @Test - fun imageWithCaptionInitializationTest() { - val imageWithCaptionView = ( - LayoutInflater.from(InstrumentationRegistry.getInstrumentation().targetContext) - .inflate( - R.layout.view_element_image_from_html, null - ) as ConstraintLayout - ).findViewById(R.id.image_view) as ImageWithCaptionView - - imageWithCaptionView.setImage("http://record.pt/") - - compareScreenshot(imageWithCaptionView) - } - - @Test - fun imageWithCaptionInitializationByDefaultTest() { - val targetContext = InstrumentationRegistry.getInstrumentation().targetContext - val imageWithCaptionView = ( - LayoutInflater.from(InstrumentationRegistry.getInstrumentation().targetContext) - .inflate( - R.layout.view_element_image_from_html, null - ) as ConstraintLayout - ).findViewById(R.id.image_view) as ImageWithCaptionView - - imageWithCaptionView.setImage("http://record.pt/") - imageWithCaptionView.setCaption(targetContext.getString(R.string.A_little_extra_to_help)) - - compareScreenshot(imageWithCaptionView) - } - - @Test - fun imageWithCaptionAndLinkInitializationByDefaultTest() { - val imageWithCaptionView = ( - LayoutInflater.from(InstrumentationRegistry.getInstrumentation().targetContext) - .inflate( - R.layout.view_element_image_from_html, null - ) as ConstraintLayout - ).findViewById(R.id.image_view) as ImageWithCaptionView - - imageWithCaptionView.setImage("http://record.pt/") - imageWithCaptionView.setCaption("This is an Android with a caption and a link", "http://record.pt/") - - compareScreenshot(imageWithCaptionView) - } -} diff --git a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt index 674072e837..f820e2b5c2 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt @@ -37,7 +37,6 @@ import androidx.core.content.ContextCompat import androidx.core.view.isGone import androidx.fragment.app.FragmentManager import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.aghajari.zoomhelper.ZoomHelper import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import com.google.firebase.crashlytics.FirebaseCrashlytics @@ -809,9 +808,6 @@ class ProjectPageActivity : } override fun dispatchTouchEvent(event: MotionEvent?): Boolean { - event?.let { - ZoomHelper.getInstance().dispatchTouchEvent(it, this) - } if (event?.action == MotionEvent.ACTION_DOWN) { val view = currentFocus diff --git a/app/src/main/java/com/kickstarter/ui/views/ImageWithCaptionView.kt b/app/src/main/java/com/kickstarter/ui/views/ImageWithCaptionView.kt index 21ed7741da..17881b3a5d 100644 --- a/app/src/main/java/com/kickstarter/ui/views/ImageWithCaptionView.kt +++ b/app/src/main/java/com/kickstarter/ui/views/ImageWithCaptionView.kt @@ -7,14 +7,21 @@ import android.view.LayoutInflater import android.view.View import android.view.View.OnClickListener import androidx.cardview.widget.CardView +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.LinearProgressIndicator +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale.Companion.FillWidth import androidx.core.view.isVisible -import com.aghajari.zoomhelper.ZoomHelper +import coil.compose.AsyncImagePainter +import coil.compose.SubcomposeAsyncImage +import coil.compose.SubcomposeAsyncImageContent import com.kickstarter.R import com.kickstarter.databinding.ViewImageWithCaptionBinding import com.kickstarter.libs.utils.extensions.isGif +import com.kickstarter.libs.utils.extensions.isNotNull import com.kickstarter.libs.utils.extensions.isWebp import com.kickstarter.ui.extensions.loadGifImage -import com.kickstarter.ui.extensions.loadImage import com.kickstarter.ui.extensions.loadWebp import com.kickstarter.ui.extensions.makeLinks @@ -35,19 +42,43 @@ class ImageWithCaptionView @JvmOverloads constructor( fun setImage(src: String) { if (src.isEmpty() || src.isBlank()) { binding.imageView.setImageDrawable(null) - binding.imageViewPlaceholder.setImageDrawable(null) + binding.composeViewImage.visibility = GONE } else { when { src.isWebp() -> { binding.imageView.loadWebp(src, context) + binding.imageView.visibility = VISIBLE + binding.composeViewImage.visibility = GONE } src.isGif() -> { + binding.imageView.visibility = VISIBLE binding.imageView.loadGifImage(src, context) + binding.composeViewImage.visibility = GONE } else -> { - binding.imageView.loadImage(src, context, binding.imageViewPlaceholder) - ZoomHelper.addZoomableView(binding.imageView) - ZoomHelper.removeZoomableView(binding.imageViewPlaceholder) + binding.composeViewImage.visibility = VISIBLE + binding.imageView.visibility = GONE + binding.composeViewImage.setContent { + if (src.isNotNull()) { + Box( + modifier = Modifier.fillMaxWidth() + ) { + SubcomposeAsyncImage( + model = src, + contentDescription = "null", + contentScale = FillWidth, + modifier = Modifier.fillMaxWidth() + ) { + val state = painter.state + if (state is AsyncImagePainter.State.Loading || state is AsyncImagePainter.State.Error) { + LinearProgressIndicator() + } else { + SubcomposeAsyncImageContent() + } + } + } + } + } } } } diff --git a/app/src/main/res/layout/view_image_with_caption.xml b/app/src/main/res/layout/view_image_with_caption.xml index 68501c3f1f..3f2e6e9cb1 100644 --- a/app/src/main/res/layout/view_image_with_caption.xml +++ b/app/src/main/res/layout/view_image_with_caption.xml @@ -1,37 +1,37 @@ + + app:layout_constraintTop_toTopOf="parent" + android:contentDescription="@null" /> - + + app:layout_constraintTop_toTopOf="parent"/> + app:constraint_referenced_ids="image_view, compose_view_image" />