mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
ManageAutoBackupsDialog and DateTimePatternInfoDialog added
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
|
||||
class DateTimePatternInfoDialog(activity: BaseSimpleActivity) {
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.datetime_pattern_info_layout, null)
|
||||
activity.getAlertDialogBuilder()
|
||||
.setPositiveButton(R.string.ok) { _, _ -> { } }
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename
|
||||
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename_hint
|
||||
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_folder
|
||||
import java.io.File
|
||||
|
||||
class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
|
||||
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
|
||||
private val config = activity.config
|
||||
private var backupFolder = config.autoBackupFolder
|
||||
|
||||
init {
|
||||
view.apply {
|
||||
backup_notes_folder.setText(activity.humanizePath(backupFolder))
|
||||
val filename = config.autoBackupFilename.ifEmpty {
|
||||
"${activity.getString(R.string.notes)}_%Y%M%D_%h%m%s"
|
||||
}
|
||||
|
||||
backup_notes_filename.setText(filename)
|
||||
backup_notes_filename_hint.setEndIconOnClickListener {
|
||||
DateTimePatternInfoDialog(activity)
|
||||
}
|
||||
|
||||
backup_notes_filename_hint.setEndIconOnLongClickListener {
|
||||
DateTimePatternInfoDialog(activity)
|
||||
true
|
||||
}
|
||||
|
||||
backup_notes_folder.setOnClickListener {
|
||||
selectBackupFolder()
|
||||
}
|
||||
}
|
||||
|
||||
activity.getAlertDialogBuilder()
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val filename = view.backup_notes_filename.value
|
||||
when {
|
||||
filename.isEmpty() -> activity.toast(R.string.empty_name)
|
||||
filename.isAValidFilename() -> {
|
||||
val file = File(backupFolder, "$filename.json")
|
||||
if (file.exists() && !file.canWrite()) {
|
||||
activity.toast(R.string.name_taken)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
ensureBackgroundThread {
|
||||
config.apply {
|
||||
autoBackupFolder = backupFolder
|
||||
autoBackupFilename = filename
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
onSuccess()
|
||||
}
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
else -> activity.toast(R.string.invalid_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectBackupFolder() {
|
||||
activity.hideKeyboard(view.backup_notes_filename)
|
||||
FilePickerDialog(activity, backupFolder, false, showFAB = true) { path ->
|
||||
activity.handleSAFDialog(path) { grantedSAF ->
|
||||
if (!grantedSAF) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
activity.handleSAFDialogSdk30(path) { grantedSAF30 ->
|
||||
if (!grantedSAF30) {
|
||||
return@handleSAFDialogSdk30
|
||||
}
|
||||
|
||||
backupFolder = path
|
||||
view.backup_notes_folder.setText(activity.humanizePath(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user