mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Use Downloads folder by default for automatic backups
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.simplemobiletools.calendar.pro.dialogs
|
package com.simplemobiletools.calendar.pro.dialogs
|
||||||
|
|
||||||
|
import android.os.Environment
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
@@ -9,23 +10,23 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
|||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.*
|
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
|
class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
|
||||||
|
private val EVENTS_DIR = "Events"
|
||||||
|
|
||||||
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
|
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
|
||||||
private val config = activity.config
|
private val config = activity.config
|
||||||
private var backupFolder = config.autoBackupFolder
|
private var backupFolder = config.autoBackupFolder.ifEmpty {
|
||||||
|
val downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
File(downloadDir, EVENTS_DIR).absolutePath
|
||||||
|
}
|
||||||
|
|
||||||
private var selectedEventTypes = config.autoBackupEventTypes.ifEmpty { config.displayEventTypes }
|
private var selectedEventTypes = config.autoBackupEventTypes.ifEmpty { config.displayEventTypes }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
view.apply {
|
view.apply {
|
||||||
backup_events_folder.setText(
|
backup_events_folder.setText(activity.humanizePath(backupFolder))
|
||||||
if (backupFolder.isEmpty()) {
|
|
||||||
activity.getString(R.string.select_folder)
|
|
||||||
} else {
|
|
||||||
activity.humanizePath(backupFolder)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
val filename = config.autoBackupFilename.ifEmpty {
|
val filename = config.autoBackupFilename.ifEmpty {
|
||||||
"${activity.getString(R.string.events)}_%Y%M%D_%h%m%s"
|
"${activity.getString(R.string.events)}_%Y%M%D_%h%m%s"
|
||||||
}
|
}
|
||||||
@@ -71,12 +72,6 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
|||||||
.apply {
|
.apply {
|
||||||
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
|
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
if (backupFolder.isEmpty()) {
|
|
||||||
activity.toast(R.string.select_folder)
|
|
||||||
selectBackupFolder()
|
|
||||||
return@setOnClickListener
|
|
||||||
}
|
|
||||||
|
|
||||||
val filename = view.backup_events_filename.value
|
val filename = view.backup_events_filename.value
|
||||||
when {
|
when {
|
||||||
filename.isEmpty() -> activity.toast(R.string.empty_name)
|
filename.isEmpty() -> activity.toast(R.string.empty_name)
|
||||||
@@ -116,9 +111,8 @@ class ManageAutomaticBackupsDialog(private val activity: SimpleActivity, onSucce
|
|||||||
|
|
||||||
private fun selectBackupFolder() {
|
private fun selectBackupFolder() {
|
||||||
activity.hideKeyboard(view.backup_events_filename)
|
activity.hideKeyboard(view.backup_events_filename)
|
||||||
FilePickerDialog(activity, backupFolder, false, showFAB = true) {
|
FilePickerDialog(activity, backupFolder, false, showFAB = true) { path ->
|
||||||
val path = it
|
activity.handleSAFDialog(path) { grantedSAF ->
|
||||||
activity.handleSAFDialog(it) { grantedSAF ->
|
|
||||||
if (!grantedSAF) {
|
if (!grantedSAF) {
|
||||||
return@handleSAFDialog
|
return@handleSAFDialog
|
||||||
}
|
}
|
||||||
|
@@ -252,7 +252,11 @@ fun Context.backupEventsAndTasks() {
|
|||||||
.replace("%m", minutes, false)
|
.replace("%m", minutes, false)
|
||||||
.replace("%s", seconds, false)
|
.replace("%s", seconds, false)
|
||||||
|
|
||||||
val exportPath = File(config.autoBackupFolder, "$filename.ics")
|
val outputFolder = File(config.autoBackupFolder).apply {
|
||||||
|
mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
val exportPath = File(outputFolder, "$filename.ics")
|
||||||
val outputStream = try {
|
val outputStream = try {
|
||||||
exportPath.outputStream()
|
exportPath.outputStream()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Reference in New Issue
Block a user