Added ExportNotesDialog

This commit is contained in:
merkost
2023-07-10 12:51:20 +10:00
parent 5e0d4a512e
commit 6614539186
3 changed files with 80 additions and 2 deletions

View File

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

View File

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