Skip to content

Commit 11155ee

Browse files
committed
adding a drag handler at checklist items
1 parent 812f382 commit 11155ee

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ android {
5151
}
5252

5353
dependencies {
54-
implementation 'com.simplemobiletools:commons:5.20.7'
54+
implementation 'com.simplemobiletools:commons:5.20.9'
55+
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
5556

5657
kapt 'androidx.room:room-compiler:2.2.2'
5758
implementation 'androidx.room:room-runtime:2.2.2'

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/ChecklistAdapter.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.View
88
import android.view.ViewGroup
99
import com.simplemobiletools.commons.activities.BaseSimpleActivity
1010
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
11+
import com.simplemobiletools.commons.extensions.applyColorFilter
1112
import com.simplemobiletools.commons.extensions.beVisibleIf
1213
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
1314
import com.simplemobiletools.commons.views.MyRecyclerView
@@ -21,7 +22,8 @@ import kotlinx.android.synthetic.main.item_checklist.view.*
2122
import java.util.*
2223

2324
class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<ChecklistItem>, val listener: ChecklistItemsListener?,
24-
recyclerView: MyRecyclerView, val showIcons: Boolean, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
25+
recyclerView: MyRecyclerView, val showIcons: Boolean, itemClick: (Any) -> Unit) :
26+
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
2527

2628
private lateinit var crossDrawable: Drawable
2729
private lateinit var checkDrawable: Drawable
@@ -52,6 +54,14 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
5254

5355
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
5456

57+
override fun onActionModeCreated() {
58+
notifyDataSetChanged()
59+
}
60+
61+
override fun onActionModeDestroyed() {
62+
notifyDataSetChanged()
63+
}
64+
5565
override fun prepareActionMode(menu: Menu) {
5666
val selectedItems = getSelectedItems()
5767
if (selectedItems.isEmpty()) {
@@ -139,6 +149,9 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
139149

140150
checklist_image.setImageDrawable(if (checklistItem.isDone) checkDrawable else crossDrawable)
141151
checklist_image.beVisibleIf(showIcons)
152+
153+
checklist_drag_handle.beVisibleIf(selectedKeys.isNotEmpty())
154+
checklist_drag_handle.applyColorFilter(textColor)
142155
checklist_holder.isSelected = isSelected
143156
}
144157
}
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
2+
<androidx.constraintlayout.widget.ConstraintLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:id="@+id/checklist_holder"
67
android:layout_width="match_parent"
@@ -14,22 +15,32 @@
1415
android:id="@+id/checklist_title"
1516
android:layout_width="match_parent"
1617
android:layout_height="wrap_content"
17-
android:layout_centerVertical="true"
18-
android:layout_marginLeft="@dimen/medium_margin"
19-
android:layout_marginTop="@dimen/medium_margin"
20-
android:layout_marginRight="@dimen/medium_margin"
21-
android:layout_toStartOf="@+id/checklist_image"
2218
android:paddingStart="@dimen/activity_margin"
2319
android:textSize="@dimen/bigger_text_size"
20+
app:layout_constraintBottom_toBottomOf="parent"
21+
app:layout_constraintEnd_toStartOf="@+id/checklist_image"
22+
app:layout_constraintTop_toTopOf="parent"
2423
tools:text="Butter" />
2524

2625
<ImageView
2726
android:id="@+id/checklist_image"
2827
android:layout_width="@dimen/checklist_image_size"
2928
android:layout_height="@dimen/checklist_image_size"
30-
android:layout_alignParentEnd="true"
31-
android:layout_centerVertical="true"
3229
android:padding="@dimen/normal_margin"
33-
android:src="@drawable/ic_cross_vector" />
30+
android:src="@drawable/ic_cross_vector"
31+
app:layout_constraintBottom_toBottomOf="parent"
32+
app:layout_constraintEnd_toStartOf="@+id/checklist_drag_handle"
33+
app:layout_constraintTop_toTopOf="parent" />
3434

35-
</RelativeLayout>
35+
<ImageView
36+
android:id="@+id/checklist_drag_handle"
37+
android:layout_width="@dimen/checklist_image_size"
38+
android:layout_height="@dimen/checklist_image_size"
39+
android:padding="@dimen/normal_margin"
40+
android:src="@drawable/ic_drag_handle_vector"
41+
android:visibility="gone"
42+
app:layout_constraintBottom_toBottomOf="parent"
43+
app:layout_constraintEnd_toEndOf="parent"
44+
app:layout_constraintTop_toTopOf="parent" />
45+
46+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)