pass an OutputStream to exporter, not a file
This commit is contained in:
parent
21232c339b
commit
655d3eedcc
|
@ -796,7 +796,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
if (events.isEmpty()) {
|
||||
toast(R.string.no_entries_for_exporting)
|
||||
} else {
|
||||
IcsExporter().exportEvents(this, file, events, true) {
|
||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||
IcsExporter().exportEvents(this, it, events, true) {
|
||||
toast(when (it) {
|
||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||
|
@ -808,6 +809,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchSettings() {
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
|
|
|
@ -8,9 +8,7 @@ import com.simplemobiletools.calendar.pro.helpers.*
|
|||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.sharePathIntent
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import java.io.File
|
||||
|
@ -26,13 +24,15 @@ fun BaseSimpleActivity.shareEvents(ids: List<Long>) {
|
|||
}
|
||||
|
||||
val events = eventsDB.getEventsWithIds(ids) as ArrayList<Event>
|
||||
IcsExporter().exportEvents(this, file, events, false) {
|
||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||
IcsExporter().exportEvents(this, it, events, false) {
|
||||
if (it == IcsExporter.ExportResult.EXPORT_OK) {
|
||||
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.getTempFile(): File? {
|
||||
val folder = File(cacheDir, "events")
|
||||
|
|
|
@ -7,13 +7,11 @@ import com.simplemobiletools.calendar.pro.helpers.IcsExporter.ExportResult.*
|
|||
import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
|
||||
import com.simplemobiletools.calendar.pro.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.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
|
||||
class IcsExporter {
|
||||
enum class ExportResult {
|
||||
|
@ -24,12 +22,10 @@ class IcsExporter {
|
|||
private var eventsFailed = 0
|
||||
private var calendars = ArrayList<CalDAVCalendar>()
|
||||
|
||||
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, true) {
|
||||
if (it == null) {
|
||||
fun exportEvents(activity: BaseSimpleActivity, outputStream: OutputStream?, events: ArrayList<Event>, showExportingToast: Boolean, callback: (result: ExportResult) -> Unit) {
|
||||
if (outputStream == null) {
|
||||
callback(EXPORT_FAIL)
|
||||
return@getFileOutputStream
|
||||
return
|
||||
}
|
||||
|
||||
ensureBackgroundThread {
|
||||
|
@ -38,7 +34,7 @@ class IcsExporter {
|
|||
activity.toast(R.string.exporting)
|
||||
}
|
||||
|
||||
it.bufferedWriter().use { out ->
|
||||
outputStream.bufferedWriter().use { out ->
|
||||
out.writeLn(BEGIN_CALENDAR)
|
||||
out.writeLn(CALENDAR_PRODID)
|
||||
out.writeLn(CALENDAR_VERSION)
|
||||
|
@ -79,7 +75,6 @@ class IcsExporter {
|
|||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun fillReminders(event: Event, out: BufferedWriter) {
|
||||
event.getReminders().forEach {
|
||||
|
|
Loading…
Reference in New Issue