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

MBL-1522: Blurry images on Campaign tab #2046

Merged
merged 4 commits into from
May 29, 2024
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
5 changes: 1 addition & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
43 changes: 37 additions & 6 deletions app/src/main/java/com/kickstarter/ui/views/ImageWithCaptionView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoids recycling cell issues

} 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()
}
}
}
}
}
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/layout/view_image_with_caption.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/image_with_caption_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- To load gifs/webp images -->
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_view_placeholder"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placeholder was the target of zoomIn images, no longer available.

android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@null"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@null" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_view"
android:layout_width="0dp"
<!-- To load images of unknown size, specially for really huge images -->
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@null" />
app:layout_constraintTop_toTopOf="parent"/>

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="image_view_placeholder,image_view" />
app:constraint_referenced_ids="image_view, compose_view_image" />

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
Expand Down