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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/row"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="55dip"
|
android:background="@color/window_background"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:orientation="vertical">
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<View
|
<RelativeLayout
|
||||||
android:id="@+id/divider"
|
android:id="@+id/row"
|
||||||
style="@style/horizontal_divider"
|
android:layout_width="fill_parent"
|
||||||
android:visibility="gone"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentTop="true" />
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<View
|
||||||
android:id="@+id/filter_count"
|
android:id="@+id/divider"
|
||||||
android:layout_width="wrap_content"
|
style="@style/horizontal_divider"
|
||||||
android:layout_height="fill_parent"
|
android:visibility="gone"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentTop="true" />
|
||||||
android:padding="@dimen/keyline_first"
|
|
||||||
android:gravity="center_vertical|end" />
|
|
||||||
|
|
||||||
<ImageView
|
<TextView
|
||||||
android:id="@+id/icon"
|
android:id="@+id/filter_count"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="fill_parent"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:tint="@color/icon_tint_with_alpha"
|
android:padding="@dimen/keyline_first"
|
||||||
android:padding="@dimen/keyline_first"
|
android:gravity="center_vertical|end" />
|
||||||
android:src="@drawable/ic_outline_add_24px"
|
|
||||||
android:scaleType="center" />
|
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:id="@+id/name"
|
android:id="@+id/icon"
|
||||||
style="@style/TextAppearance"
|
android:layout_width="wrap_content"
|
||||||
android:layout_toEndOf="@id/icon"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toStartOf="@id/filter_count"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_width="fill_parent"
|
android:tint="@color/icon_tint_with_alpha"
|
||||||
android:layout_height="fill_parent"
|
android:padding="@dimen/keyline_first"
|
||||||
android:paddingStart="@dimen/keyline_first"
|
android:src="@drawable/ic_outline_add_24px"
|
||||||
android:paddingEnd="@dimen/keyline_first"
|
android:scaleType="center" />
|
||||||
android:gravity="start|center_vertical"
|
|
||||||
android:textAlignment="viewStart"
|
<TextView
|
||||||
android:textSize="18sp" />
|
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