Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebb54c26 authored by cketti's avatar cketti
Browse files

Use width of swipe action text to calculate maximum swipe distance

parent f75101df
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -27,12 +27,16 @@ class MessageListSwipeCallback(
    private val adapter: MessageListAdapter,
    private val listener: MessageListSwipeListener
) : ItemTouchHelper.Callback() {
    private val swipePadding = context.resources.getDimension(R.dimen.messageListSwipeIconPadding).toInt()
    private val swipeThreshold = context.resources.getDimension(R.dimen.messageListSwipeThreshold)
    private val backgroundColorPaint = Paint()

    private val swipeRightLayout: View
    private val swipeLeftLayout: View

    private var maxSwipeRightDistance: Int = -1
    private var maxSwipeLeftDistance: Int = -1

    init {
        val layoutInflater = LayoutInflater.from(context)

@@ -166,13 +170,23 @@ class MessageListSwipeCallback(
            val heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
            swipeLayout.measure(widthMeasureSpec, heightMeasureSpec)
            swipeLayout.layout(0, 0, width, height)

            if (swipeRight) {
                maxSwipeRightDistance = textView.right + swipePadding
            } else {
                maxSwipeLeftDistance = swipeLayout.width - textView.left + swipePadding
            }
        }

        swipeLayout.draw(this)
    }

    override fun getMaxSwipeDistance(recyclerView: RecyclerView, direction: Int): Int {
        return recyclerView.width / 2
        return when (direction) {
            ItemTouchHelper.RIGHT -> if (maxSwipeRightDistance > 0) maxSwipeRightDistance else recyclerView.width
            ItemTouchHelper.LEFT -> if (maxSwipeLeftDistance > 0) maxSwipeLeftDistance else recyclerView.width
            else -> recyclerView.width
        }
    }

    override fun shouldAnimateOut(direction: Int): Boolean {
+3 −2
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@

    <TextView
        android:id="@+id/swipe_action_text"
        android:layout_width="0dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
@@ -37,8 +37,9 @@
        android:maxLines="1"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:textColor="?attr/messageListSwipeIconTint"
        app:layout_constrainedWidth="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/swipe_action_icon"
        app:layout_constraintTop_toTopOf="parent"
+2 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@

    <TextView
        android:id="@+id/swipe_action_text"
        android:layout_width="0dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/messageListSwipeTextPadding"
        android:layout_marginTop="16dp"
@@ -37,6 +37,7 @@
        android:maxLines="1"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:textColor="?attr/messageListSwipeIconTint"
        app:layout_constrainedWidth="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toRightOf="@+id/swipe_action_icon"