mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-03-03 19:09:07 +01:00
Handle storage access framework permissions
This commit is contained in:
parent
6a94468e8f
commit
d4e5b57291
@ -13,16 +13,16 @@ import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.*
|
||||
class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSuccess: (() -> Unit)? = null, onCancel: (() -> Unit)? = null) {
|
||||
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
|
||||
private val config = activity.config
|
||||
private var realPath = config.autoBackupPath
|
||||
private var selectedEventTypes = config.autoBackupEventTypes
|
||||
private var backupFolder = config.autoBackupFolder
|
||||
private var selectedEventTypes = config.autoBackupEventTypes.ifEmpty { config.displayEventTypes }
|
||||
|
||||
init {
|
||||
view.apply {
|
||||
backup_events_folder.setText(
|
||||
if (realPath.isEmpty()) {
|
||||
if (backupFolder.isEmpty()) {
|
||||
activity.getString(R.string.select_folder)
|
||||
} else {
|
||||
activity.humanizePath(realPath)
|
||||
activity.humanizePath(backupFolder)
|
||||
}
|
||||
)
|
||||
|
||||
@ -65,9 +65,9 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { alertDialog ->
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
if (realPath.isEmpty()) {
|
||||
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
if (backupFolder.isEmpty()) {
|
||||
activity.toast(R.string.select_folder)
|
||||
selectBackupFolder()
|
||||
return@setOnClickListener
|
||||
@ -86,7 +86,7 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
||||
|
||||
ensureBackgroundThread {
|
||||
config.apply {
|
||||
autoBackupPath = realPath
|
||||
autoBackupFolder = backupFolder
|
||||
autoBackupFilename = filename
|
||||
autoBackupEvents = backupEventsChecked
|
||||
autoBackupTasks = backupTasksChecked
|
||||
@ -97,16 +97,16 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
||||
}
|
||||
|
||||
onSuccess?.invoke()
|
||||
alertDialog.dismiss()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
else -> activity.toast(R.string.invalid_name)
|
||||
}
|
||||
}
|
||||
|
||||
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener {
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener {
|
||||
onCancel?.invoke()
|
||||
alertDialog.dismiss()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,9 +114,22 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
||||
|
||||
private fun selectBackupFolder() {
|
||||
activity.hideKeyboard(view.backup_events_filename)
|
||||
FilePickerDialog(activity, realPath, false, showFAB = true) {
|
||||
view.backup_events_folder.setText(activity.humanizePath(it))
|
||||
realPath = it
|
||||
FilePickerDialog(activity, backupFolder, false, showFAB = true) {
|
||||
val path = it
|
||||
activity.handleSAFDialog(it) { grantedSAF ->
|
||||
if (!grantedSAF) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
activity.handleSAFDialogSdk30(path) { grantedSAF30 ->
|
||||
if (!grantedSAF30) {
|
||||
return@handleSAFDialogSdk30
|
||||
}
|
||||
|
||||
backupFolder = path
|
||||
view.backup_events_folder.setText(activity.humanizePath(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ fun Context.backupEventsAndTasks() {
|
||||
.replace("%m", minutes, false)
|
||||
.replace("%s", seconds, false)
|
||||
|
||||
val exportPath = File(config.autoBackupPath, "$filename.ics")
|
||||
val exportPath = File(config.autoBackupFolder, "$filename.ics")
|
||||
val outputStream = try {
|
||||
exportPath.outputStream()
|
||||
} catch (e: Exception) {
|
||||
|
@ -263,9 +263,9 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
get() = prefs.getBoolean(AUTO_BACKUP, false)
|
||||
set(enableAutomaticBackups) = prefs.edit().putBoolean(AUTO_BACKUP, enableAutomaticBackups).apply()
|
||||
|
||||
var autoBackupPath: String
|
||||
get() = prefs.getString(AUTO_BACKUP_PATH, "")!!
|
||||
set(autoBackupPath) = prefs.edit().putString(AUTO_BACKUP_PATH, autoBackupPath).apply()
|
||||
var autoBackupFolder: String
|
||||
get() = prefs.getString(AUTO_BACKUP_FOLDER, "")!!
|
||||
set(autoBackupPath) = prefs.edit().putString(AUTO_BACKUP_FOLDER, autoBackupPath).apply()
|
||||
|
||||
var autoBackupFilename: String
|
||||
get() = prefs.getString(AUTO_BACKUP_FILENAME, "")!!
|
||||
|
@ -131,7 +131,7 @@ const val LAST_USED_EVENT_SPAN = "last_used_event_span"
|
||||
const val ALLOW_CREATING_TASKS = "allow_creating_tasks"
|
||||
const val WAS_FILTERED_OUT_WARNING_SHOWN = "was_filtered_out_warning_shown"
|
||||
const val AUTO_BACKUP = "auto_backup"
|
||||
const val AUTO_BACKUP_PATH = "auto_backup_path"
|
||||
const val AUTO_BACKUP_FOLDER = "auto_backup_folder"
|
||||
const val AUTO_BACKUP_FILENAME = "auto_backup_filename"
|
||||
const val AUTO_BACKUP_EVENT_TYPES = "auto_backup_event_types"
|
||||
const val AUTO_BACKUP_EVENTS = "auto_backup_events"
|
||||
|
@ -19,7 +19,7 @@
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_marginEnd="@dimen/activity_margin"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:hint="@string/folder">
|
||||
android:hint="@string/select_folder">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/backup_events_folder"
|
||||
|
Loading…
x
Reference in New Issue
Block a user