diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index c49780918..e16c4d385 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -55,6 +55,7 @@ import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.util.ThemeUtils; import com.keylesspalace.tusky.util.TimestampUtils; +import com.keylesspalace.tusky.util.TouchDelegateHelper; import com.keylesspalace.tusky.view.MediaPreviewImageView; import com.keylesspalace.tusky.view.MediaPreviewLayout; import com.keylesspalace.tusky.viewdata.PollOptionViewData; @@ -63,6 +64,7 @@ import com.keylesspalace.tusky.viewdata.PollViewDataKt; import com.keylesspalace.tusky.viewdata.StatusViewData; import java.text.NumberFormat; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -170,6 +172,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { this.avatarRadius24dp = itemView.getContext().getResources().getDimensionPixelSize(R.dimen.avatar_radius_24dp); mediaPreviewUnloaded = new ColorDrawable(ThemeUtils.getColor(itemView.getContext(), R.attr.colorBackgroundAccent)); + + TouchDelegateHelper.expandTouchSizeToFillRow((ViewGroup) itemView, Arrays.asList(replyButton, reblogButton, favouriteButton, bookmarkButton, moreButton)); } protected void setDisplayName(String name, List customEmojis, StatusDisplayOptions statusDisplayOptions) { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/TouchDelegateHelper.kt b/app/src/main/java/com/keylesspalace/tusky/util/TouchDelegateHelper.kt new file mode 100644 index 000000000..dc3828515 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/util/TouchDelegateHelper.kt @@ -0,0 +1,51 @@ +@file:JvmName("TouchDelegateHelper") + +package com.keylesspalace.tusky.util + +import android.graphics.Rect +import android.view.MotionEvent +import android.view.TouchDelegate +import android.view.View +import android.view.ViewGroup + +/** + * Expands the touch area of the give row of views to fill the space in-between them, using a + * [TouchDelegate]. + */ +fun ViewGroup.expandTouchSizeToFillRow(children: List) { + addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> + touchDelegate = CompositeTouchDelegate( + this, + children.mapIndexed { i, view -> + val rect = Rect() + view.getHitRect(rect) + val left = children.getOrNull(i - 1) + if (left != null) { + // extend half-way to previous view + rect.left -= (view.left - left.right) / 2 + } + val right = children.getOrNull(i + 1) + if (right != null) { + // extend half-way to next view + rect.right += (right.left - view.right) / 2 + } + TouchDelegate(rect, view) + } + ) + } +} + +private class CompositeTouchDelegate(view: View, private val delegates: List) : + TouchDelegate(Rect(), view) { + + override fun onTouchEvent(event: MotionEvent): Boolean { + var res = false + val x = event.x + val y = event.y + for (delegate in delegates) { + event.setLocation(x, y) + res = delegate.onTouchEvent(event) || res + } + return res + } +} diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index 68e2bbb52..38a2ac350 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -8,15 +8,15 @@ android:layout_height="wrap_content" android:clipChildren="false" android:clipToPadding="false" - android:focusable="true" - android:paddingLeft="14dp" - android:paddingRight="14dp"> + android:focusable="true"> - + @@ -267,6 +273,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="4dp" + android:layout_marginEnd="14dp" android:layout_marginBottom="4dp" android:nestedScrollingEnabled="false" app:layout_constraintEnd_toEndOf="parent" @@ -296,6 +303,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="6dp" + android:layout_marginEnd="14dp" android:textSize="?attr/status_text_medium" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="@id/status_display_name" @@ -305,13 +313,11 @@ + tools:text="1+" /> - diff --git a/app/src/main/res/layout/item_status_detailed.xml b/app/src/main/res/layout/item_status_detailed.xml index f30ec627c..d165c7caf 100644 --- a/app/src/main/res/layout/item_status_detailed.xml +++ b/app/src/main/res/layout/item_status_detailed.xml @@ -7,14 +7,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false" - android:clipToPadding="false" - android:paddingLeft="14dp" - android:paddingRight="14dp"> + android:clipToPadding="false"> @@ -98,6 +100,7 @@ style="@style/TuskyButton.Outlined" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:importantForAccessibility="no" @@ -117,14 +120,16 @@ android:id="@+id/status_content" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="4dp" + android:layout_marginEnd="14dp" android:layout_marginBottom="4dp" android:focusable="true" android:hyphenationFrequency="full" android:importantForAccessibility="no" android:lineSpacingMultiplier="1.1" - android:textIsSelectable="true" android:textColor="?android:textColorPrimary" + android:textIsSelectable="true" android:textSize="?attr/status_text_large" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -135,7 +140,9 @@ android:id="@+id/status_card_view" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="8dp" + android:layout_marginEnd="14dp" android:background="@drawable/card_frame" android:clipChildren="true" android:foreground="?attr/selectableItemBackground" @@ -201,7 +208,9 @@ android:id="@+id/status_media_preview_container" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="12dp" + android:layout_marginEnd="14dp" android:layout_marginBottom="4dp" android:background="@drawable/media_preview_outline" android:importantForAccessibility="noHideDescendants" @@ -215,7 +224,9 @@ android:id="@+id/status_poll_options" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="4dp" + android:layout_marginEnd="14dp" android:layout_marginBottom="4dp" android:nestedScrollingEnabled="false" app:layout_constraintEnd_toEndOf="parent" @@ -227,6 +238,7 @@ style="@style/TuskyButton.Outlined" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="4dp" android:gravity="center" android:minWidth="150dp" @@ -244,7 +256,9 @@ android:id="@+id/status_poll_description" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="6dp" + android:layout_marginEnd="14dp" android:textSize="?attr/status_text_medium" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -255,7 +269,9 @@ android:id="@+id/status_timestamp_info" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="14dp" android:layout_marginTop="10dp" + android:layout_marginEnd="14dp" android:drawablePadding="4dp" android:importantForAccessibility="no" android:textColor="?android:textColorTertiary" @@ -270,7 +286,9 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/status_timestamp_info" + android:layout_marginStart="14dp" android:layout_marginTop="6dp" + android:layout_marginEnd="14dp" android:background="?android:attr/listDivider" android:importantForAccessibility="no" android:paddingStart="16dp" @@ -318,7 +336,9 @@ android:id="@+id/status_buttons_divider" android:layout_width="match_parent" android:layout_height="1dp" + android:layout_marginStart="14dp" android:layout_marginTop="6dp" + android:layout_marginEnd="14dp" android:background="?android:attr/listDivider" android:importantForAccessibility="no" android:paddingStart="16dp" @@ -328,10 +348,8 @@