create a special confirmation dialog for note deletion

This commit is contained in:
tibbi
2017-03-09 22:27:08 +01:00
parent 4420dc0b60
commit dff96b04f1
12 changed files with 80 additions and 24 deletions

View File

@ -11,7 +11,6 @@ import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
@ -235,13 +234,12 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun saveCurrentNote() = (view_pager.adapter as NotesPagerAdapter).saveCurrentNote(view_pager.currentItem)
private fun displayDeleteNotePrompt() {
val message = String.format(getString(R.string.delete_note_prompt_message), mCurrentNote.title)
ConfirmationDialog(this, message) {
deleteNote()
DeleteNoteDialog(this, mCurrentNote) {
deleteNote(it)
}
}
private fun deleteNote() {
private fun deleteNote(deleteFile: Boolean) {
if (mNotes.size <= 1)
return

View File

@ -0,0 +1,37 @@
package com.simplemobiletools.notes.dialogs
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.activities.SimpleActivity
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.dialog_delete_note.view.*
class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callback: (deleteFile: Boolean) -> Unit) {
var dialog: AlertDialog? = null
init {
val message = String.format(activity.getString(R.string.delete_note_prompt_message), note.title)
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_note, null).apply {
if (note.path.isNotEmpty()) {
delete_note_checkbox.text = String.format(activity.getString(R.string.delete_file_itself), note.path)
delete_note_checkbox.beVisible()
}
delete_note_description.text = message
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) })
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun dialogConfirmed(deleteFile: Boolean) {
callback.invoke(deleteFile && note.path.isNotEmpty())
dialog?.dismiss()
}
}