From 6b5f816b2859f735690919af1e27e3f6e1b6f861 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Sun, 28 Jul 2024 16:24:20 +0200 Subject: [PATCH] feat: Remove preview card placeholder icon (#839) Previous code displayed a large placeholder icon if there was no preview image for a preview card. This reduces the amount of space available for the actual preview text (i.e., title and description) and did not convey additional information in the limited space available on the timeline. So remove it. While I'm here simplify the PreviewCard layout and migrate to ConstraintLayout. --- .../java/app/pachli/view/PreviewCardView.kt | 17 ++- .../res/drawable/card_image_placeholder.xml | 12 --- app/src/main/res/layout/preview_card.xml | 101 +++++++++++------- 3 files changed, 68 insertions(+), 62 deletions(-) delete mode 100644 app/src/main/res/drawable/card_image_placeholder.xml diff --git a/app/src/main/java/app/pachli/view/PreviewCardView.kt b/app/src/main/java/app/pachli/view/PreviewCardView.kt index 5e717d2c9..26db9c30f 100644 --- a/app/src/main/java/app/pachli/view/PreviewCardView.kt +++ b/app/src/main/java/app/pachli/view/PreviewCardView.kt @@ -21,6 +21,7 @@ import android.content.Context import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout @@ -132,7 +133,9 @@ class PreviewCardView @JvmOverloads constructor( previewCardWrapper.setOnClickListener { listener.onClick(card, Target.CARD) } cardImage.setOnClickListener { listener.onClick(card, Target.IMAGE) } - byline.setOnClickListener { listener.onClick(card, Target.BYLINE) } + byline.referencedIds.forEach { id -> + root.findViewById(id).setOnClickListener { listener.onClick(card, Target.BYLINE) } + } cardLink.text = card.url @@ -143,6 +146,7 @@ class PreviewCardView @JvmOverloads constructor( // 2. Card has a blurhash, use that as the image, or // 3. Use R.drawable.card_image_placeholder if (statusDisplayOptions.mediaPreviewEnabled && (!sensitive || statusDisplayOptions.showSensitiveMedia) && !card.image.isNullOrBlank()) { + cardImage.show() cardImage.shapeAppearanceModel = if (card.width > card.height) { setTopBottomLayout() } else { @@ -162,6 +166,7 @@ class PreviewCardView @JvmOverloads constructor( builder.into(cardImage) } } else if (statusDisplayOptions.useBlurhash && !card.blurhash.isNullOrBlank()) { + cardImage.show() cardImage.shapeAppearanceModel = setLeftRightLayout().build() cardImage.scaleType = ImageView.ScaleType.CENTER_CROP @@ -170,12 +175,7 @@ class PreviewCardView @JvmOverloads constructor( .dontTransform() .into(cardImage) } else { - cardImage.shapeAppearanceModel = setLeftRightLayout().build() - cardImage.scaleType = ImageView.ScaleType.CENTER - - Glide.with(cardImage.context) - .load(R.drawable.card_image_placeholder) - .into(cardImage) + cardImage.hide() } card.authors?.firstOrNull()?.account?.let { account -> @@ -191,12 +191,10 @@ class PreviewCardView @JvmOverloads constructor( /** Adjusts the layout parameters to place the image above the information views */ private fun setTopBottomLayout() = with(binding) { val cardImageShape = ShapeAppearanceModel.Builder() - previewCardWrapper.orientation = VERTICAL cardImage.layoutParams.height = cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_vertical_height) cardImage.layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT cardInfo.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT - cardInfo.layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT cardImageShape.setTopLeftCorner(CornerFamily.ROUNDED, cardCornerRadius) cardImageShape.setTopRightCorner(CornerFamily.ROUNDED, cardCornerRadius) return@with cardImageShape @@ -205,7 +203,6 @@ class PreviewCardView @JvmOverloads constructor( /** Adjusts the layout parameters to place the image on the left, the information on the right */ private fun setLeftRightLayout() = with(binding) { val cardImageShape = ShapeAppearanceModel.Builder() - previewCardWrapper.orientation = HORIZONTAL cardImage.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT cardImage.layoutParams.width = cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_horizontal_width) diff --git a/app/src/main/res/drawable/card_image_placeholder.xml b/app/src/main/res/drawable/card_image_placeholder.xml deleted file mode 100644 index 0632fa0d8..000000000 --- a/app/src/main/res/drawable/card_image_placeholder.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/preview_card.xml b/app/src/main/res/layout/preview_card.xml index ec6c1064e..f42a284c9 100644 --- a/app/src/main/res/layout/preview_card.xml +++ b/app/src/main/res/layout/preview_card.xml @@ -16,16 +16,17 @@ --> + xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto"> - + android:scaleType="center" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:srcCompat="@tools:sample/backgrounds/scenic" /> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:ignore="SelectableText" + tools:text="@tools:sample/lorem" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/card_title" + tools:ignore="SelectableText" + tools:text="@tools:sample/lorem" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/card_description" + tools:ignore="SelectableText" + tools:text="@tools:sample/lorem" /> - + android:layout_marginTop="6dp" + app:layout_constraintTop_toBottomOf="@id/card_link" + app:layout_constraintStart_toStartOf="parent" /> - + - - - - + + +