diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt index 83932b2ce4..b7103b9c23 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt @@ -9,6 +9,7 @@ import android.util.AttributeSet import android.util.TypedValue import android.view.View import android.view.ViewOutlineProvider +import android.view.ViewTreeObserver import android.widget.FrameLayout import androidx.core.view.isVisible import com.bumptech.glide.load.engine.DiskCacheStrategy @@ -27,7 +28,10 @@ import org.thoughtcrime.securesms.components.GlideDrawableListeningTarget import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestManager +import org.session.libsignal.utilities.Log import org.thoughtcrime.securesms.mms.Slide +import org.thoughtcrime.securesms.ui.afterMeasured +import java.lang.Float.min open class ThumbnailView @JvmOverloads constructor( context: Context, @@ -114,8 +118,23 @@ open class ThumbnailView @JvmOverloads constructor( isPreview: Boolean, naturalWidth: Int, naturalHeight: Int ): ListenableFuture { - binding.playOverlay.isVisible = (slide.thumbnailUri != null && slide.hasPlayOverlay() && - (slide.transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE || isPreview)) + val showPlayOverlay = (slide.thumbnailUri != null && slide.hasPlayOverlay() && + (slide.transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE || isPreview)) + if(showPlayOverlay) { + binding.playOverlay.isVisible = true + // The views are poorly constructed at the moment and there is no good way to know + // if this is used in the main conversation or in the tiny quote window of a reply... + // But when the view is too small the 'play' icon does not scale, + // so we can do it based on measured sizes here + binding.playOverlay.afterMeasured { + // max size if 60% of the width + val ratio = min((binding.root.width * 0.6f) / binding.playOverlay.width, 1f) + binding.playOverlay.scaleX = ratio + binding.playOverlay.scaleY = ratio + } + } else { + binding.playOverlay.isVisible = false + } if (equals(this.slide, slide)) { // don't re-load slide diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt index 22eb4bf860..3dec8d5a2e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt @@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.ui import android.app.Activity import android.content.Context import android.content.ContextWrapper +import android.view.View +import android.view.ViewTreeObserver import androidx.compose.runtime.Composable import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.Fragment @@ -58,3 +60,14 @@ fun Context.findActivity(): Activity { } throw IllegalStateException("Permissions should be called in the context of an Activity") } + +inline fun T.afterMeasured(crossinline block: T.() -> Unit) { + viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + if (measuredWidth > 0 && measuredHeight > 0) { + viewTreeObserver.removeOnGlobalLayoutListener(this) + block() + } + } + }) +} diff --git a/app/src/main/res/drawable/image_loading_background.xml b/app/src/main/res/drawable/image_loading_background.xml index d2e3dfbfa7..04c4a8a2a0 100644 --- a/app/src/main/res/drawable/image_loading_background.xml +++ b/app/src/main/res/drawable/image_loading_background.xml @@ -5,6 +5,4 @@ - - \ No newline at end of file