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()
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/delete_note_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/delete_note_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/delete_note_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:checked="true"
android:paddingBottom="@dimen/small_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/small_margin"
android:text="@string/delete_file_itself"
android:visibility="gone"/>
</LinearLayout>

View File

@ -21,9 +21,8 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="note_saved_successfully">Note saved successfully</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>
<!-- Settings -->

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>

View File

@ -21,8 +21,7 @@
<string name="file_too_large">File too large, the limit is 10MB</string>
<string name="only_import_file_content">Only import the file content</string>
<string name="update_file_at_note">Update the file itself at updating the note</string>
<string name="delete_note_only">This will delete the note only.</string>
<string name="delete_file_itself">Delete the file itself too</string>
<string name="delete_file_itself">Also delete file \"%1$s\"</string>
<string name="note_saved_successfully">Note \"%1$s\" saved successfully</string>
<string name="display_success_message">Display save success messages</string>