From dff96b04f179a4d1d2609b8b3267665b32a2320e Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Mar 2017 22:27:08 +0100 Subject: [PATCH] create a special confirmation dialog for note deletion --- .../notes/activities/MainActivity.kt | 8 ++-- .../notes/dialogs/DeleteNoteDialog.kt | 37 +++++++++++++++++++ .../main/res/layout/dialog_delete_note.xml | 30 +++++++++++++++ app/src/main/res/values-de/strings.xml | 5 +-- app/src/main/res/values-es/strings.xml | 3 +- app/src/main/res/values-fr/strings.xml | 3 +- app/src/main/res/values-hu/strings.xml | 3 +- app/src/main/res/values-it/strings.xml | 3 +- app/src/main/res/values-ja/strings.xml | 3 +- app/src/main/res/values-pt-rPT/strings.xml | 3 +- app/src/main/res/values-sv/strings.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- 12 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt create mode 100644 app/src/main/res/layout/dialog_delete_note.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index 581d8306..2ff577d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt new file mode 100644 index 00000000..d4f38262 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt @@ -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() + } +} diff --git a/app/src/main/res/layout/dialog_delete_note.xml b/app/src/main/res/layout/dialog_delete_note.xml new file mode 100644 index 00000000..114651e7 --- /dev/null +++ b/app/src/main/res/layout/dialog_delete_note.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 31a69355..441950e1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -21,9 +21,8 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too - Note saved successfully + Also delete file \"%1$s\" + Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index c4216019..3053bb3c 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9e7ec632..98e68139 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index dd59ff2c..6a9b4062 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 89e9fe28..e560f802 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 0122c628..20adbf10 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 6a92b9ec..1495623f 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b76afb0e..5ef5ac9d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f7fcfc5..81e2ebd7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,8 +21,7 @@ File too large, the limit is 10MB Only import the file content Update the file itself at updating the note - This will delete the note only. - Delete the file itself too + Also delete file \"%1$s\" Note \"%1$s\" saved successfully Display save success messages