fix #383, allow exporting files in an SD card

This commit is contained in:
tibbi
2018-04-13 10:12:52 +02:00
parent 15719b6430
commit 18d2a4fb13
3 changed files with 10 additions and 5 deletions

View File

@ -662,8 +662,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
if (events.isEmpty()) {
toast(R.string.no_entries_for_exporting)
} else {
toast(R.string.exporting)
IcsExporter().exportEvents(this, file, events as ArrayList<Event>) {
IcsExporter().exportEvents(this, file, events as ArrayList<Event>, true) {
toast(when (it) {
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed

View File

@ -23,7 +23,7 @@ fun BaseSimpleActivity.shareEvents(ids: List<Int>) {
}
val events = dbHelper.getEventsWithIds(ids)
IcsExporter().exportEvents(this, file, events) {
IcsExporter().exportEvents(this, file, events, false) {
if (it == IcsExporter.ExportResult.EXPORT_OK) {
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)
}

View File

@ -1,10 +1,12 @@
package com.simplemobiletools.calendar.helpers
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.getFileOutputStream
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.writeLn
import com.simplemobiletools.commons.models.FileDirItem
import java.io.BufferedWriter
@ -18,14 +20,18 @@ class IcsExporter {
private var eventsExported = 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)
activity.getFileOutputStream(fileDirItem) {
activity.getFileOutputStream(fileDirItem, true) {
if (it == null) {
callback(EXPORT_FAIL)
return@getFileOutputStream
}
if (showExportingToast) {
activity.toast(R.string.exporting)
}
it.bufferedWriter().use { out ->
out.writeLn(BEGIN_CALENDAR)
out.writeLn(CALENDAR_PRODID)