mirror of https://github.com/tasks/tasks
Drag and drop to rearrange filter criteria
parent
1a05278ab0
commit
410af772f2
@ -0,0 +1,39 @@
|
||||
package com.todoroo.astrid.core
|
||||
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.tasks.Callback2
|
||||
|
||||
class CustomFilterItemTouchHelper(private val onMove: Callback2<Int, Int>, private val onClear: Runnable) : ItemTouchHelper.Callback() {
|
||||
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
|
||||
return if (viewHolder.adapterPosition > 0) makeMovementFlags(ItemTouchHelper.UP or ItemTouchHelper.DOWN, 0) else 0
|
||||
}
|
||||
|
||||
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
||||
super.onSelectedChanged(viewHolder, actionState)
|
||||
|
||||
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
|
||||
(viewHolder as CriterionViewHolder).setMoving(true);
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMove(
|
||||
recyclerView: RecyclerView, src: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
|
||||
val toPosition = target.adapterPosition
|
||||
if (toPosition == 0) {
|
||||
return false
|
||||
}
|
||||
onMove.call(src.adapterPosition, toPosition);
|
||||
return true
|
||||
}
|
||||
|
||||
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
|
||||
super.clearView(recyclerView, viewHolder)
|
||||
|
||||
(viewHolder as CriterionViewHolder).setMoving(false)
|
||||
|
||||
onClear.run()
|
||||
}
|
||||
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.tasks;
|
||||
|
||||
public interface Callback2<T1, T2> {
|
||||
void call(T1 t1, T2 t2);
|
||||
}
|
@ -1,46 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/row"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="55dip"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/window_background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
style="@style/horizontal_divider"
|
||||
android:visibility="gone"
|
||||
android:layout_alignParentTop="true" />
|
||||
<RelativeLayout
|
||||
android:id="@+id/row"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/filter_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:padding="@dimen/keyline_first"
|
||||
android:gravity="center_vertical|end" />
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
style="@style/horizontal_divider"
|
||||
android:visibility="gone"
|
||||
android:layout_alignParentTop="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:tint="@color/icon_tint_with_alpha"
|
||||
android:padding="@dimen/keyline_first"
|
||||
android:src="@drawable/ic_outline_add_24px"
|
||||
android:scaleType="center" />
|
||||
<TextView
|
||||
android:id="@+id/filter_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:padding="@dimen/keyline_first"
|
||||
android:gravity="center_vertical|end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
style="@style/TextAppearance"
|
||||
android:layout_toEndOf="@id/icon"
|
||||
android:layout_toStartOf="@id/filter_count"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:paddingStart="@dimen/keyline_first"
|
||||
android:paddingEnd="@dimen/keyline_first"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textAlignment="viewStart"
|
||||
android:textSize="18sp" />
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:tint="@color/icon_tint_with_alpha"
|
||||
android:padding="@dimen/keyline_first"
|
||||
android:src="@drawable/ic_outline_add_24px"
|
||||
android:scaleType="center" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
style="@style/TextAppearance"
|
||||
android:layout_toEndOf="@id/icon"
|
||||
android:layout_toStartOf="@id/filter_count"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="@dimen/keyline_first"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textAlignment="viewStart"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue