ManageAutoBackupsDialog and DateTimePatternInfoDialog added

This commit is contained in:
merkost 2023-07-28 17:30:50 +10:00
parent 1fb1afe23d
commit c93e7fe063
4 changed files with 180 additions and 0 deletions

View File

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

View File

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

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/date_time_pattern_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="@dimen/big_margin"
android:paddingTop="@dimen/big_margin"
android:text="@string/date_time_pattern_info"
android:textIsSelectable="true" />

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/backup_notes_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/backup_notes_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextInputLayout
android:id="@+id/backup_notes_folder_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/activity_margin"
android:hint="@string/folder">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/backup_notes_folder"
style="@style/UnclickableEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.simplemobiletools.commons.views.MyTextInputLayout>
<com.simplemobiletools.commons.views.MyTextInputLayout
android:id="@+id/backup_notes_filename_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:hint="@string/filename_without_json"
app:endIconDrawable="@drawable/ic_info_vector"
app:endIconMode="custom">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/backup_notes_filename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size" />
</com.simplemobiletools.commons.views.MyTextInputLayout>
</LinearLayout>
</ScrollView>