Skip to content

Commit 02c73cd

Browse files
committed
fix #249, allow renaming checklist items
1 parent aedf7b7 commit 02c73cd

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.simplemobiletools.commons.extensions.beVisibleIf
1111
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
1212
import com.simplemobiletools.commons.views.MyRecyclerView
1313
import com.simplemobiletools.notes.pro.R
14+
import com.simplemobiletools.notes.pro.dialogs.RenameChecklistItemDialog
1415
import com.simplemobiletools.notes.pro.helpers.DONE_CHECKLIST_ITEM_ALPHA
1516
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
1617
import com.simplemobiletools.notes.pro.models.ChecklistItem
@@ -77,7 +78,14 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
7778
}
7879

7980
private fun renameChecklistItem() {
80-
81+
val item = getSelectedItems().first()
82+
RenameChecklistItemDialog(activity, item.title) {
83+
val position = getSelectedItemPositions().first()
84+
item.title = it
85+
listener?.saveChecklist()
86+
notifyItemChanged(position)
87+
finishActMode()
88+
}
8189
}
8290

8391
private fun deleteSelection() {

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -
2323
getButton(BUTTON_POSITIVE).setOnClickListener {
2424
val title = view.checklist_item_title.value
2525
when {
26-
title.isEmpty() -> activity.toast(R.string.no_title)
26+
title.isEmpty() -> activity.toast(R.string.empty_name)
2727
else -> {
2828
callback(title)
2929
dismiss()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.simplemobiletools.notes.pro.dialogs
2+
3+
import android.app.Activity
4+
import android.content.DialogInterface.BUTTON_POSITIVE
5+
import androidx.appcompat.app.AlertDialog
6+
import com.simplemobiletools.commons.extensions.setupDialogStuff
7+
import com.simplemobiletools.commons.extensions.showKeyboard
8+
import com.simplemobiletools.commons.extensions.toast
9+
import com.simplemobiletools.commons.extensions.value
10+
import com.simplemobiletools.notes.pro.R
11+
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
12+
13+
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
14+
init {
15+
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_checklist_item, null).apply {
16+
checklist_item_title.setText(oldTitle)
17+
}
18+
19+
AlertDialog.Builder(activity)
20+
.setPositiveButton(R.string.ok, null)
21+
.setNegativeButton(R.string.cancel, null)
22+
.create().apply {
23+
activity.setupDialogStuff(view, this) {
24+
showKeyboard(view.checklist_item_title)
25+
getButton(BUTTON_POSITIVE).setOnClickListener {
26+
val newTitle = view.checklist_item_title.value
27+
when {
28+
newTitle.isEmpty() -> activity.toast(R.string.empty_name)
29+
else -> {
30+
callback(newTitle)
31+
dismiss()
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/dialog_holder"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:orientation="vertical"
8+
android:paddingLeft="@dimen/activity_margin"
9+
android:paddingTop="@dimen/activity_margin"
10+
android:paddingRight="@dimen/activity_margin">
11+
12+
<com.simplemobiletools.commons.views.MyEditText
13+
android:id="@+id/checklist_item_title"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:layout_marginTop="@dimen/small_margin"
17+
android:layout_marginBottom="@dimen/small_margin"
18+
android:inputType="textCapSentences"
19+
android:textCursorDrawable="@null"
20+
android:textSize="@dimen/bigger_text_size"/>
21+
22+
</LinearLayout>

0 commit comments

Comments
 (0)