allow adding 3 checklist items at once

This commit is contained in:
tibbi 2018-12-26 23:50:41 +01:00
parent 02c73cdec0
commit 622778e882
4 changed files with 38 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -> Unit) {
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null)
@ -18,14 +18,17 @@ class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.add_new_checklist_item) {
showKeyboard(view.checklist_item_title)
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) {
showKeyboard(view.checklist_item_title_1)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.checklist_item_title.value
val title1 = view.checklist_item_title_1.value
val title2 = view.checklist_item_title_2.value
val title3 = view.checklist_item_title_3.value
when {
title.isEmpty() -> activity.toast(R.string.empty_name)
title1.isEmpty() && title2.isEmpty() && title3.isEmpty() -> activity.toast(R.string.empty_name)
else -> {
callback(title)
val titles = arrayListOf(title1, title2, title3).filter { it.isNotEmpty() }.toMutableList() as ArrayList<String>
callback(titles)
dismiss()
}
}

View File

@ -8,7 +8,7 @@ import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
import kotlinx.android.synthetic.main.dialog_rename_checklist_item.view.*
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
init {

View File

@ -80,12 +80,17 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
private fun showNewItemDialog() {
NewChecklistItemDialog(activity as SimpleActivity) {
val currentMaxId = items.maxBy { it.id }?.id ?: 0
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
items.add(checklistItem)
var currentMaxId = items.maxBy { it.id }?.id ?: 0
it.forEach {
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
items.add(checklistItem)
currentMaxId++
}
saveNote()
if (items.size == 1) {
setupAdapter()
} else {
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
}
}
}

View File

@ -10,10 +10,28 @@
android:paddingRight="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/checklist_item_title"
android:id="@+id/checklist_item_title_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:inputType="textCapSentences"
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/checklist_item_title_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin"
android:inputType="textCapSentences"
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/checklist_item_title_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin"
android:inputType="textCapSentences"
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>