fix: Correctly position preview card images, show card description (#860)
Byline changes inadvertently changed how the preview image is laid out, breaking the "Image at start, info at end" variant. Previous code did not always show the card description if the text was present, fix that.
This commit is contained in:
parent
a0b3b1ffac
commit
ff8b71a2d8
|
@ -25,6 +25,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import app.pachli.R
|
import app.pachli.R
|
||||||
import app.pachli.core.activity.decodeBlurHash
|
import app.pachli.core.activity.decodeBlurHash
|
||||||
import app.pachli.core.activity.emojify
|
import app.pachli.core.activity.emojify
|
||||||
|
@ -129,7 +130,10 @@ class PreviewCardView @JvmOverloads constructor(
|
||||||
card.description.isNotBlank() -> card.description
|
card.description.isNotBlank() -> card.description
|
||||||
card.authorName.isNotBlank() -> card.authorName
|
card.authorName.isNotBlank() -> card.authorName
|
||||||
else -> null
|
else -> null
|
||||||
}?.let { cardDescription.text = it } ?: cardDescription.hide()
|
}?.let {
|
||||||
|
cardDescription.text = it
|
||||||
|
cardDescription.show()
|
||||||
|
} ?: cardDescription.hide()
|
||||||
|
|
||||||
previewCardWrapper.setOnClickListener { listener.onClick(card, Target.CARD) }
|
previewCardWrapper.setOnClickListener { listener.onClick(card, Target.CARD) }
|
||||||
cardImage.setOnClickListener { listener.onClick(card, Target.IMAGE) }
|
cardImage.setOnClickListener { listener.onClick(card, Target.IMAGE) }
|
||||||
|
@ -150,7 +154,7 @@ class PreviewCardView @JvmOverloads constructor(
|
||||||
cardImage.shapeAppearanceModel = if (card.width > card.height) {
|
cardImage.shapeAppearanceModel = if (card.width > card.height) {
|
||||||
setTopBottomLayout()
|
setTopBottomLayout()
|
||||||
} else {
|
} else {
|
||||||
setLeftRightLayout()
|
setStartEndLayout()
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
cardImage.scaleType = ImageView.ScaleType.CENTER_CROP
|
cardImage.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
|
@ -167,7 +171,7 @@ class PreviewCardView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
} else if (statusDisplayOptions.useBlurhash && !card.blurhash.isNullOrBlank()) {
|
} else if (statusDisplayOptions.useBlurhash && !card.blurhash.isNullOrBlank()) {
|
||||||
cardImage.show()
|
cardImage.show()
|
||||||
cardImage.shapeAppearanceModel = setLeftRightLayout().build()
|
cardImage.shapeAppearanceModel = setStartEndLayout().build()
|
||||||
cardImage.scaleType = ImageView.ScaleType.CENTER_CROP
|
cardImage.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
|
|
||||||
Glide.with(cardImage.context)
|
Glide.with(cardImage.context)
|
||||||
|
@ -191,23 +195,53 @@ class PreviewCardView @JvmOverloads constructor(
|
||||||
/** Adjusts the layout parameters to place the image above the information views */
|
/** Adjusts the layout parameters to place the image above the information views */
|
||||||
private fun setTopBottomLayout() = with(binding) {
|
private fun setTopBottomLayout() = with(binding) {
|
||||||
val cardImageShape = ShapeAppearanceModel.Builder()
|
val cardImageShape = ShapeAppearanceModel.Builder()
|
||||||
cardImage.layoutParams.height =
|
|
||||||
cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_vertical_height)
|
// Move image to top.
|
||||||
cardImage.layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
|
with(cardImage.layoutParams as ConstraintLayout.LayoutParams) {
|
||||||
|
height = cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_vertical_height)
|
||||||
|
width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
|
||||||
|
bottomToBottom = ConstraintLayout.LayoutParams.UNSET
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move cardInfo below image
|
||||||
|
with(cardInfo.layoutParams as ConstraintLayout.LayoutParams) {
|
||||||
|
startToStart = ConstraintLayout.LayoutParams.PARENT_ID
|
||||||
|
topToBottom = cardImage.id
|
||||||
|
|
||||||
|
startToEnd = ConstraintLayout.LayoutParams.UNSET
|
||||||
|
topToTop = ConstraintLayout.LayoutParams.UNSET
|
||||||
|
}
|
||||||
|
|
||||||
cardInfo.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
cardInfo.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
cardImageShape.setTopLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
cardImageShape.setTopLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
||||||
cardImageShape.setTopRightCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
cardImageShape.setTopRightCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
||||||
return@with cardImageShape
|
return@with cardImageShape
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adjusts the layout parameters to place the image on the left, the information on the right */
|
/**
|
||||||
private fun setLeftRightLayout() = with(binding) {
|
* Adjusts the layout parameters to place the image at the start, the information at
|
||||||
|
* the end.
|
||||||
|
*/
|
||||||
|
private fun setStartEndLayout() = with(binding) {
|
||||||
val cardImageShape = ShapeAppearanceModel.Builder()
|
val cardImageShape = ShapeAppearanceModel.Builder()
|
||||||
cardImage.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
|
||||||
cardImage.layoutParams.width =
|
// Move image to start with fixed width to allow space for cardInfo.
|
||||||
cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_horizontal_width)
|
with(cardImage.layoutParams as ConstraintLayout.LayoutParams) {
|
||||||
cardInfo.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
height = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
|
||||||
cardInfo.layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
|
width = cardImage.resources.getDimensionPixelSize(DR.dimen.card_image_horizontal_width)
|
||||||
|
bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move cardInfo to end of image
|
||||||
|
with(cardInfo.layoutParams as ConstraintLayout.LayoutParams) {
|
||||||
|
startToEnd = binding.cardImage.id
|
||||||
|
topToTop = ConstraintLayout.LayoutParams.PARENT_ID
|
||||||
|
|
||||||
|
startToStart = ConstraintLayout.LayoutParams.UNSET
|
||||||
|
topToBottom = ConstraintLayout.LayoutParams.UNSET
|
||||||
|
}
|
||||||
|
|
||||||
cardImageShape.setTopLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
cardImageShape.setTopLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
||||||
cardImageShape.setBottomLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
cardImageShape.setBottomLeftCorner(CornerFamily.ROUNDED, cardCornerRadius)
|
||||||
return@with cardImageShape
|
return@with cardImageShape
|
||||||
|
|
|
@ -42,14 +42,15 @@
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/card_info"
|
android:id="@+id/card_info"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toBottomOf="@id/card_image"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
android:paddingLeft="6dp"
|
android:paddingLeft="6dp"
|
||||||
android:paddingTop="6dp"
|
android:paddingTop="6dp"
|
||||||
android:paddingRight="6dp"
|
android:paddingRight="6dp"
|
||||||
android:paddingBottom="6dp">
|
android:paddingBottom="6dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/card_image">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/card_title"
|
android:id="@+id/card_title"
|
||||||
|
@ -102,8 +103,8 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="6dp"
|
android:layout_marginTop="6dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/card_link"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintTop_toBottomOf="@id/card_link" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/author_info"
|
android:id="@+id/author_info"
|
||||||
|
|
Loading…
Reference in New Issue