Skip to content

Commit 39e48b8

Browse files
authored
Merge pull request #393 from tanvir-ahmod/feature_#370
Add option to move checklist item all the way top or bottom #370
2 parents a64eabd + e6e1df7 commit 39e48b8

File tree

41 files changed

+117
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+117
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
6060
}
6161

6262
when (id) {
63+
R.id.cab_move_to_top -> moveSelectedItemsToTop()
64+
R.id.cab_move_to_bottom -> moveSelectedItemsToBottom()
6365
R.id.cab_rename -> renameChecklistItem()
6466
R.id.cab_delete -> deleteSelection()
6567
}
@@ -145,6 +147,31 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
145147
}
146148
}
147149

150+
private fun moveSelectedItemsToTop() {
151+
selectedKeys.withIndex()
152+
.reversed()
153+
.forEach { keys ->
154+
val position = items.indexOfFirst { it.id == keys.value }
155+
val tempItem = items[position]
156+
items.removeAt(position)
157+
items.add(0, tempItem)
158+
}
159+
notifyDataSetChanged()
160+
listener?.saveChecklist()
161+
}
162+
163+
private fun moveSelectedItemsToBottom() {
164+
selectedKeys.withIndex()
165+
.forEach { keys ->
166+
val position = items.indexOfFirst { it.id == keys.value }
167+
val tempItem = items[position]
168+
items.removeAt(position)
169+
items.add(items.size, tempItem)
170+
}
171+
notifyDataSetChanged()
172+
listener?.saveChecklist()
173+
}
174+
148175
private fun getItemWithKey(key: Int): ChecklistItem? = items.firstOrNull { it.id == key }
149176

150177
private fun getSelectedItems() = items.filter { selectedKeys.contains(it.id) } as ArrayList<ChecklistItem>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="#FFFFFF"
7+
android:alpha="0.8">
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M16,13h-3V3h-2v10H8l4,4 4,-4zM4,19v2h16v-2H4z"/>
11+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="#FFFFFF"
7+
android:alpha="0.8">
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M8,11h3v10h2V11h3l-4,-4 -4,4zM4,3v2h16V3H4z"/>
11+
</vector>
188 Bytes
182 Bytes
119 Bytes
116 Bytes
162 Bytes
161 Bytes
205 Bytes

0 commit comments

Comments
 (0)