allow adding new items to checklists

This commit is contained in:
tibbi
2018-12-07 23:37:03 +01:00
parent c0acb525ad
commit d021a9d0fd
30 changed files with 120 additions and 31 deletions

View File

@ -0,0 +1,36 @@
package com.simplemobiletools.notes.pro.dialogs
import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff
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.*
class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null)
AlertDialog.Builder(activity)
.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)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.checklist_item_title.value
when {
title.isEmpty() -> activity.toast(R.string.no_title)
else -> {
callback(title)
dismiss()
}
}
}
}
}
}
}

View File

@ -23,9 +23,9 @@ class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) {
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.new_note) {
showKeyboard(view.note_name)
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
val title = view.note_title.value
Thread {
when {
title.isEmpty() -> activity.toast(R.string.no_title)

View File

@ -15,16 +15,16 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val callbac
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null)
view.note_name.setText(note.title)
view.note_title.setText(note.title)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.rename_note) {
showKeyboard(view.note_name)
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
val title = view.note_title.value
Thread {
newTitleConfirmed(title, this)
}.start()

View File

@ -10,14 +10,18 @@ import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.fragment_checklist.view.*
class ChecklistFragment : NoteFragment() {
private var noteId = 0L
private var note: Note? = null
private var items = ArrayList<ChecklistItem>()
lateinit var view: ViewGroup
@ -44,7 +48,10 @@ class ChecklistFragment : NoteFragment() {
setImageDrawable(plusIcon)
background.applyColorFilter(context!!.getAdjustedPrimaryColor())
setOnClickListener {
NewChecklistItemDialog(activity as SimpleActivity) {
val checklistItem = ChecklistItem(it, false)
items.add(checklistItem)
}
}
}
}

View File

@ -0,0 +1,3 @@
package com.simplemobiletools.notes.pro.models
data class ChecklistItem(val title: String, val isDone: Boolean)