mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix #383, allow exporting files in an SD card
This commit is contained in:
@ -662,8 +662,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
toast(R.string.no_entries_for_exporting)
|
toast(R.string.no_entries_for_exporting)
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.exporting)
|
IcsExporter().exportEvents(this, file, events as ArrayList<Event>, true) {
|
||||||
IcsExporter().exportEvents(this, file, events as ArrayList<Event>) {
|
|
||||||
toast(when (it) {
|
toast(when (it) {
|
||||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||||
|
@ -23,7 +23,7 @@ fun BaseSimpleActivity.shareEvents(ids: List<Int>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val events = dbHelper.getEventsWithIds(ids)
|
val events = dbHelper.getEventsWithIds(ids)
|
||||||
IcsExporter().exportEvents(this, file, events) {
|
IcsExporter().exportEvents(this, file, events, false) {
|
||||||
if (it == IcsExporter.ExportResult.EXPORT_OK) {
|
if (it == IcsExporter.ExportResult.EXPORT_OK) {
|
||||||
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)
|
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.simplemobiletools.calendar.helpers
|
package com.simplemobiletools.calendar.helpers
|
||||||
|
|
||||||
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
|
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.extensions.writeLn
|
import com.simplemobiletools.commons.extensions.writeLn
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import java.io.BufferedWriter
|
import java.io.BufferedWriter
|
||||||
@ -18,14 +20,18 @@ class IcsExporter {
|
|||||||
private var eventsExported = 0
|
private var eventsExported = 0
|
||||||
private var eventsFailed = 0
|
private var eventsFailed = 0
|
||||||
|
|
||||||
fun exportEvents(activity: BaseSimpleActivity, file: File, events: ArrayList<Event>, callback: (result: ExportResult) -> Unit) {
|
fun exportEvents(activity: BaseSimpleActivity, file: File, events: ArrayList<Event>, showExportingToast: Boolean, callback: (result: ExportResult) -> Unit) {
|
||||||
val fileDirItem = FileDirItem(file.absolutePath, file.name)
|
val fileDirItem = FileDirItem(file.absolutePath, file.name)
|
||||||
activity.getFileOutputStream(fileDirItem) {
|
activity.getFileOutputStream(fileDirItem, true) {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
callback(EXPORT_FAIL)
|
callback(EXPORT_FAIL)
|
||||||
return@getFileOutputStream
|
return@getFileOutputStream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showExportingToast) {
|
||||||
|
activity.toast(R.string.exporting)
|
||||||
|
}
|
||||||
|
|
||||||
it.bufferedWriter().use { out ->
|
it.bufferedWriter().use { out ->
|
||||||
out.writeLn(BEGIN_CALENDAR)
|
out.writeLn(BEGIN_CALENDAR)
|
||||||
out.writeLn(CALENDAR_PRODID)
|
out.writeLn(CALENDAR_PRODID)
|
||||||
|
Reference in New Issue
Block a user