From 66145391866e9352ed8e3326ed3d789ffc359e75 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 10 Jul 2023 12:51:20 +1000 Subject: [PATCH] Added ExportNotesDialog --- .../notes/pro/activities/SettingsActivity.kt | 6 ++- .../notes/pro/dialogs/ExportNotesDialog.kt | 42 +++++++++++++++++++ .../main/res/layout/dialog_export_notes.xml | 34 +++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportNotesDialog.kt create mode 100644 app/src/main/res/layout/dialog_export_notes.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt index 5b8ee9f9..ce5e5eb0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.notes.pro.R +import com.simplemobiletools.notes.pro.dialogs.ExportNotesDialog import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.requestUnlockNotes import com.simplemobiletools.notes.pro.extensions.updateWidgets @@ -290,8 +291,9 @@ class SettingsActivity : SimpleActivity() { private fun setupNotesExport() { settings_export_notes_holder.setOnClickListener { - val fileName = "${getString(R.string.notes)}_${getCurrentFormattedDateTime()}" - saveDocument.launch(fileName) + ExportNotesDialog(this) { filename -> + saveDocument.launch(filename) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportNotesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportNotesDialog.kt new file mode 100644 index 00000000..e5218c0b --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportNotesDialog.kt @@ -0,0 +1,42 @@ +package com.simplemobiletools.notes.pro.dialogs + +import android.view.ViewGroup +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.notes.pro.R +import com.simplemobiletools.notes.pro.activities.SimpleActivity +import kotlinx.android.synthetic.main.dialog_export_notes.view.export_notes_filename + +class ExportNotesDialog(val activity: SimpleActivity, callback: (filename: String) -> Unit) { + + init { + val view = (activity.layoutInflater.inflate(R.layout.dialog_export_notes, null) as ViewGroup).apply { + export_notes_filename.setText( + buildString { + append(context.getString(R.string.notes)) + append("_") + append(context.getCurrentFormattedDateTime()) + } + ) + } + + activity.getAlertDialogBuilder().setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null).apply { + activity.setupDialogStuff(view, this, R.string.export_notes) { alertDialog -> + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + + val filename = view.export_notes_filename.value + when { + filename.isEmpty() -> activity.toast(R.string.empty_name) + filename.isAValidFilename() -> { + callback(filename) + alertDialog.dismiss() + } + + else -> activity.toast(R.string.invalid_name) + } + } + } + } + } +} + diff --git a/app/src/main/res/layout/dialog_export_notes.xml b/app/src/main/res/layout/dialog_export_notes.xml new file mode 100644 index 00000000..7e354d38 --- /dev/null +++ b/app/src/main/res/layout/dialog_export_notes.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + +