adding a drag handler at checklist items

This commit is contained in:
tibbi 2019-12-08 13:03:17 +01:00
parent 812f382775
commit 11155ee12a
3 changed files with 37 additions and 12 deletions

View File

@ -51,7 +51,8 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.20.7'
implementation 'com.simplemobiletools:commons:5.20.9'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
kapt 'androidx.room:room-compiler:2.2.2'
implementation 'androidx.room:room-runtime:2.2.2'

View File

@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.views.MyRecyclerView
@ -21,7 +22,8 @@ import kotlinx.android.synthetic.main.item_checklist.view.*
import java.util.*
class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<ChecklistItem>, val listener: ChecklistItemsListener?,
recyclerView: MyRecyclerView, val showIcons: Boolean, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
recyclerView: MyRecyclerView, val showIcons: Boolean, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
private lateinit var crossDrawable: Drawable
private lateinit var checkDrawable: Drawable
@ -52,6 +54,14 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
override fun onActionModeCreated() {
notifyDataSetChanged()
}
override fun onActionModeDestroyed() {
notifyDataSetChanged()
}
override fun prepareActionMode(menu: Menu) {
val selectedItems = getSelectedItems()
if (selectedItems.isEmpty()) {
@ -139,6 +149,9 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
checklist_image.setImageDrawable(if (checklistItem.isDone) checkDrawable else crossDrawable)
checklist_image.beVisibleIf(showIcons)
checklist_drag_handle.beVisibleIf(selectedKeys.isNotEmpty())
checklist_drag_handle.applyColorFilter(textColor)
checklist_holder.isSelected = isSelected
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/checklist_holder"
android:layout_width="match_parent"
@ -14,22 +15,32 @@
android:id="@+id/checklist_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:layout_toStartOf="@+id/checklist_image"
android:paddingStart="@dimen/activity_margin"
android:textSize="@dimen/bigger_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/checklist_image"
app:layout_constraintTop_toTopOf="parent"
tools:text="Butter" />
<ImageView
android:id="@+id/checklist_image"
android:layout_width="@dimen/checklist_image_size"
android:layout_height="@dimen/checklist_image_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_cross_vector" />
android:src="@drawable/ic_cross_vector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/checklist_drag_handle"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
<ImageView
android:id="@+id/checklist_drag_handle"
android:layout_width="@dimen/checklist_image_size"
android:layout_height="@dimen/checklist_image_size"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_drag_handle_vector"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>