Skip to content

Commit 622778e

Browse files
committed
allow adding 3 checklist items at once
1 parent 02c73cd commit 622778e

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ import com.simplemobiletools.commons.extensions.value
1010
import com.simplemobiletools.notes.pro.R
1111
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
1212

13-
class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -> Unit) {
13+
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
1414
init {
1515
val view = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null)
1616

1717
AlertDialog.Builder(activity)
1818
.setPositiveButton(R.string.ok, null)
1919
.setNegativeButton(R.string.cancel, null)
2020
.create().apply {
21-
activity.setupDialogStuff(view, this, R.string.add_new_checklist_item) {
22-
showKeyboard(view.checklist_item_title)
21+
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) {
22+
showKeyboard(view.checklist_item_title_1)
2323
getButton(BUTTON_POSITIVE).setOnClickListener {
24-
val title = view.checklist_item_title.value
24+
val title1 = view.checklist_item_title_1.value
25+
val title2 = view.checklist_item_title_2.value
26+
val title3 = view.checklist_item_title_3.value
2527
when {
26-
title.isEmpty() -> activity.toast(R.string.empty_name)
28+
title1.isEmpty() && title2.isEmpty() && title3.isEmpty() -> activity.toast(R.string.empty_name)
2729
else -> {
28-
callback(title)
30+
val titles = arrayListOf(title1, title2, title3).filter { it.isNotEmpty() }.toMutableList() as ArrayList<String>
31+
callback(titles)
2932
dismiss()
3033
}
3134
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.simplemobiletools.commons.extensions.showKeyboard
88
import com.simplemobiletools.commons.extensions.toast
99
import com.simplemobiletools.commons.extensions.value
1010
import com.simplemobiletools.notes.pro.R
11-
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
11+
import kotlinx.android.synthetic.main.dialog_rename_checklist_item.view.*
1212

1313
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
1414
init {

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
8080

8181
private fun showNewItemDialog() {
8282
NewChecklistItemDialog(activity as SimpleActivity) {
83-
val currentMaxId = items.maxBy { it.id }?.id ?: 0
84-
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
85-
items.add(checklistItem)
83+
var currentMaxId = items.maxBy { it.id }?.id ?: 0
84+
it.forEach {
85+
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
86+
items.add(checklistItem)
87+
currentMaxId++
88+
}
8689
saveNote()
8790
if (items.size == 1) {
8891
setupAdapter()
92+
} else {
93+
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
8994
}
9095
}
9196
}

app/src/main/res/layout/dialog_new_checklist_item.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@
1010
android:paddingRight="@dimen/activity_margin">
1111

1212
<com.simplemobiletools.commons.views.MyEditText
13-
android:id="@+id/checklist_item_title"
13+
android:id="@+id/checklist_item_title_1"
1414
android:layout_width="match_parent"
1515
android:layout_height="wrap_content"
16-
android:layout_marginBottom="@dimen/activity_margin"
16+
android:layout_marginBottom="@dimen/medium_margin"
17+
android:inputType="textCapSentences"
18+
android:textCursorDrawable="@null"
19+
android:textSize="@dimen/normal_text_size"/>
20+
21+
<com.simplemobiletools.commons.views.MyEditText
22+
android:id="@+id/checklist_item_title_2"
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:layout_marginBottom="@dimen/medium_margin"
26+
android:inputType="textCapSentences"
27+
android:textCursorDrawable="@null"
28+
android:textSize="@dimen/normal_text_size"/>
29+
30+
<com.simplemobiletools.commons.views.MyEditText
31+
android:id="@+id/checklist_item_title_3"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:layout_marginBottom="@dimen/medium_margin"
1735
android:inputType="textCapSentences"
1836
android:textCursorDrawable="@null"
1937
android:textSize="@dimen/normal_text_size"/>

0 commit comments

Comments
 (0)