Fix permission issue with export files
This commit is contained in:
parent
002b058a5e
commit
7ec164ae42
|
@ -50,6 +50,7 @@ import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
import org.joda.time.LocalDate
|
import org.joda.time.LocalDate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
|
@ -222,6 +223,7 @@ fun Context.checkAndBackupEventsOnBoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.backupEventsAndTasks() {
|
fun Context.backupEventsAndTasks() {
|
||||||
|
require(isRPlus())
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val config = config
|
val config = config
|
||||||
val events = eventsHelper.getEventsToExport(
|
val events = eventsHelper.getEventsToExport(
|
||||||
|
@ -258,8 +260,17 @@ fun Context.backupEventsAndTasks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val exportFile = File(outputFolder, "$filename.ics")
|
val exportFile = File(outputFolder, "$filename.ics")
|
||||||
|
val exportFilePath = exportFile.absolutePath
|
||||||
val outputStream = try {
|
val outputStream = try {
|
||||||
exportFile.outputStream()
|
if (hasProperStoredFirstParentUri(exportFilePath)) {
|
||||||
|
val exportFileUri = createDocumentUriUsingFirstParentTreeUri(exportFilePath)
|
||||||
|
if (!getDoesFilePathExist(exportFilePath)) {
|
||||||
|
createSAFFileSdk30(exportFilePath)
|
||||||
|
}
|
||||||
|
applicationContext.contentResolver.openOutputStream(exportFileUri, "wt") ?: FileOutputStream(exportFile)
|
||||||
|
} else {
|
||||||
|
FileOutputStream(exportFile)
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
null
|
null
|
||||||
|
@ -273,8 +284,8 @@ fun Context.backupEventsAndTasks() {
|
||||||
}
|
}
|
||||||
MediaScannerConnection.scanFile(
|
MediaScannerConnection.scanFile(
|
||||||
this,
|
this,
|
||||||
arrayOf(exportFile.absolutePath),
|
arrayOf(exportFilePath),
|
||||||
arrayOf(exportFile.getMimeType())
|
arrayOf(exportFilePath.getMimeType())
|
||||||
) { _, _ -> }
|
) { _, _ -> }
|
||||||
|
|
||||||
config.lastAutoBackupTime = getNowSeconds()
|
config.lastAutoBackupTime = getNowSeconds()
|
||||||
|
@ -522,6 +533,7 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
|
||||||
val currMinutes = calendar.get(Calendar.MINUTE)
|
val currMinutes = calendar.get(Calendar.MINUTE)
|
||||||
dateTime.withMinuteOfHour(currMinutes).seconds()
|
dateTime.withMinuteOfHour(currMinutes).seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
|
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
|
||||||
else -> {
|
else -> {
|
||||||
val hours = defaultStartTime / 60
|
val hours = defaultStartTime / 60
|
||||||
|
@ -682,11 +694,13 @@ fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Long>, ac
|
||||||
eventsHelper.addEventRepetitionException(value, timestamps[index], true)
|
eventsHelper.addEventRepetitionException(value, timestamps[index], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DELETE_FUTURE_OCCURRENCES -> {
|
DELETE_FUTURE_OCCURRENCES -> {
|
||||||
eventIds.forEachIndexed { index, value ->
|
eventIds.forEachIndexed { index, value ->
|
||||||
eventsHelper.addEventRepeatLimit(value, timestamps[index])
|
eventsHelper.addEventRepeatLimit(value, timestamps[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DELETE_ALL_OCCURRENCES -> {
|
DELETE_ALL_OCCURRENCES -> {
|
||||||
eventsHelper.deleteEvents(eventIds.toMutableList(), true)
|
eventsHelper.deleteEvents(eventIds.toMutableList(), true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue