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()) { 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

View File

@ -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)
} }

View File

@ -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)