From 09d4f6200482b3d359cb9ac6f027d041e6724551 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 10 Aug 2023 19:25:33 +0200 Subject: [PATCH] Start/end the thread divider in the middle of the avatar (#3892) Previously, the thread indicator would start at the top of the avatar for the status at the start of the thread, and end at the top of the avatar for the status at the end of the thread. If these avatars were partially transparent the thread indicator could either (a) poke out of the top of the avatar at the start of the thread, (b) not properly connect with the avatar at the end of the thread, or (c) both. Partially fix this by making the divider start/stop in the middle of the avatar. This assumes that this area will typically have opaque content, even if some of the rest of the avatar is transparent. This is not always true, but it's still better than the current behaviour. --- .../ConversationLineItemDecoration.kt | 30 +++++++++---------- app/src/main/res/layout/item_status.xml | 6 ++-- app/src/main/res/values/dimens.xml | 3 ++ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ConversationLineItemDecoration.kt b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ConversationLineItemDecoration.kt index 36e36d10f..ffd1b9c83 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ConversationLineItemDecoration.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ConversationLineItemDecoration.kt @@ -24,36 +24,34 @@ import androidx.core.view.forEach import androidx.recyclerview.widget.RecyclerView import com.keylesspalace.tusky.R -class ConversationLineItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() { - +class ConversationLineItemDecoration(context: Context) : RecyclerView.ItemDecoration() { private val divider: Drawable = ContextCompat.getDrawable(context, R.drawable.conversation_thread_line)!! - override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) { - val dividerStart = parent.paddingStart + context.resources.getDimensionPixelSize(R.dimen.status_line_margin_start) - val dividerEnd = dividerStart + divider.intrinsicWidth + private val avatarTopMargin = context.resources.getDimensionPixelSize(R.dimen.account_avatar_margin) + private val halfAvatarHeight = context.resources.getDimensionPixelSize(R.dimen.timeline_status_avatar_height) / 2 + private val statusLineMarginStart = context.resources.getDimensionPixelSize(R.dimen.status_line_margin_start) - val avatarMargin = context.resources.getDimensionPixelSize(R.dimen.account_avatar_margin) + override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) { + val dividerStart = parent.paddingStart + statusLineMarginStart + val dividerEnd = dividerStart + divider.intrinsicWidth val items = (parent.adapter as ThreadAdapter).currentList - parent.forEach { child -> + parent.forEach { statusItemView -> + val position = parent.getChildAdapterPosition(statusItemView) - val position = parent.getChildAdapterPosition(child) - - val current = items.getOrNull(position) - - if (current != null) { + items.getOrNull(position)?.let { current -> val above = items.getOrNull(position - 1) val dividerTop = if (above != null && above.id == current.status.inReplyToId) { - child.top + statusItemView.top } else { - child.top + avatarMargin + statusItemView.top + avatarTopMargin + halfAvatarHeight } val below = items.getOrNull(position + 1) val dividerBottom = if (below != null && current.id == below.status.inReplyToId && !current.isDetailed) { - child.bottom + statusItemView.bottom } else { - child.top + avatarMargin + statusItemView.top + avatarTopMargin + halfAvatarHeight } if (parent.layoutDirection == View.LAYOUT_DIRECTION_LTR) { diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index 43a4496cf..0473dfab4 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -33,10 +33,10 @@ 1dp 48dp + + 48dp + 48dp