mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-07 05:52:06 +01:00
handle event exporting with Scoped Storage on Android 11
This commit is contained in:
parent
a9a2c22292
commit
97197435ae
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar.pro.activities
|
package com.simplemobiletools.calendar.pro.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@ -54,6 +55,8 @@ import java.util.*
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
private val PICK_EXPORT_FILE_INTENT = 2
|
||||||
|
|
||||||
private var showCalDAVRefreshToast = false
|
private var showCalDAVRefreshToast = false
|
||||||
private var mShouldFilterBeVisible = false
|
private var mShouldFilterBeVisible = false
|
||||||
private var mIsSearchOpen = false
|
private var mIsSearchOpen = false
|
||||||
@ -62,6 +65,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
private var shouldGoToTodayBeVisible = false
|
private var shouldGoToTodayBeVisible = false
|
||||||
private var goToTodayButton: MenuItem? = null
|
private var goToTodayButton: MenuItem? = null
|
||||||
private var currentFragments = ArrayList<MyFragmentHolder>()
|
private var currentFragments = ArrayList<MyFragmentHolder>()
|
||||||
|
private var eventTypesToExport = ArrayList<Long>()
|
||||||
|
|
||||||
private var mStoredTextColor = 0
|
private var mStoredTextColor = 0
|
||||||
private var mStoredBackgroundColor = 0
|
private var mStoredBackgroundColor = 0
|
||||||
@ -228,6 +232,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
checkIsViewIntent()
|
checkIsViewIntent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
|
if (requestCode == PICK_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||||
|
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
||||||
|
exportEventsTo(eventTypesToExport, outputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
config.apply {
|
config.apply {
|
||||||
mStoredIsSundayFirst = isSundayFirst
|
mStoredIsSundayFirst = isSundayFirst
|
||||||
@ -782,11 +794,25 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tryExportEvents() {
|
private fun tryExportEvents() {
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
if (isQPlus()) {
|
||||||
if (it) {
|
ExportEventsDialog(this, config.lastExportPath, true) { file, eventTypes ->
|
||||||
ExportEventsDialog(this, config.lastExportPath, false) { file, eventTypes ->
|
eventTypesToExport = eventTypes
|
||||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
|
||||||
exportEventsTo(eventTypes, it)
|
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||||
|
type = "text/calendar"
|
||||||
|
putExtra(Intent.EXTRA_TITLE, file.name)
|
||||||
|
addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
|
|
||||||
|
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
|
if (it) {
|
||||||
|
ExportEventsDialog(this, config.lastExportPath, false) { file, eventTypes ->
|
||||||
|
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||||
|
exportEventsTo(eventTypes, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -794,16 +820,18 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun exportEventsTo(eventTypes: ArrayList<Long>, outputStream: OutputStream?) {
|
private fun exportEventsTo(eventTypes: ArrayList<Long>, outputStream: OutputStream?) {
|
||||||
val events = eventsHelper.getEventsToExport(eventTypes)
|
ensureBackgroundThread {
|
||||||
if (events.isEmpty()) {
|
val events = eventsHelper.getEventsToExport(eventTypes)
|
||||||
toast(R.string.no_entries_for_exporting)
|
if (events.isEmpty()) {
|
||||||
} else {
|
toast(R.string.no_entries_for_exporting)
|
||||||
IcsExporter().exportEvents(this, outputStream, events, true) {
|
} else {
|
||||||
toast(when (it) {
|
IcsExporter().exportEvents(this, outputStream, events, true) {
|
||||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
toast(when (it) {
|
||||||
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
else -> R.string.exporting_failed
|
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||||
})
|
else -> R.string.exporting_failed
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user