allow sharing individual events by creating temp .ics files, fix #14
This commit is contained in:
parent
1e70eb1cd8
commit
73bfc28523
|
@ -130,5 +130,15 @@
|
|||
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="com.simplemobiletools.calendar.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths"/>
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.simplemobiletools.commons.models.RadioItem
|
|||
import com.simplemobiletools.commons.models.Release
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import org.joda.time.DateTime
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), NavigationListener {
|
||||
|
@ -269,7 +270,9 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
toast(R.string.no_events_for_exporting)
|
||||
}
|
||||
} else {
|
||||
val result = IcsExporter().exportEvents(this, path, events)
|
||||
val filename = "events_${System.currentTimeMillis() / 1000}.ics"
|
||||
val file = File(path, filename)
|
||||
val result = IcsExporter().exportEvents(this, file, events)
|
||||
runOnUiThread {
|
||||
toast(when (result) {
|
||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.events_exported_successfully
|
||||
|
|
|
@ -1,7 +1,41 @@
|
|||
package com.simplemobiletools.calendar.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.support.v4.content.FileProvider
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.helpers.IcsExporter
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import java.io.File
|
||||
|
||||
fun Activity.shareEvents(ids: List<Int>) {
|
||||
val folder = File(cacheDir, "events")
|
||||
if (!folder.exists()) {
|
||||
if (!folder.mkdir()) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val file = File(folder, "events.ics")
|
||||
val events = dbHelper.getEventsWithIds(ids)
|
||||
|
||||
val result = IcsExporter().exportEvents(this, file, events)
|
||||
if (result == IcsExporter.ExportResult.EXPORT_OK) {
|
||||
val uri = FileProvider.getUriForFile(this, "com.simplemobiletools.calendar.fileprovider", file)
|
||||
val shareTitle = resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
setDataAndType(uri, contentResolver.getType(uri))
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
type = "text/calendar"
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(Intent.createChooser(this, shareTitle))
|
||||
} else {
|
||||
toast(R.string.no_app_for_ics)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,10 +443,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return events
|
||||
}
|
||||
|
||||
fun getEventsWithIds(ids: List<Int>): List<Event> {
|
||||
fun getEventsWithIds(ids: List<Int>): ArrayList<Event> {
|
||||
val args = TextUtils.join(", ", ids)
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
|
||||
return getEvents(selection)
|
||||
return getEvents(selection) as ArrayList<Event>
|
||||
}
|
||||
|
||||
fun getEventsAtReboot(): List<Event> {
|
||||
|
|
|
@ -16,9 +16,8 @@ class IcsExporter {
|
|||
var eventsExported = 0
|
||||
var eventsFailed = 0
|
||||
|
||||
fun exportEvents(context: Context, path: String, events: ArrayList<Event>): ExportResult {
|
||||
val filename = "events_${System.currentTimeMillis() / 1000}.ics"
|
||||
File(path, filename).bufferedWriter().use { out ->
|
||||
fun exportEvents(context: Context, file: File, events: ArrayList<Event>): ExportResult {
|
||||
file.bufferedWriter().use { out ->
|
||||
out.writeLn(BEGIN_CALENDAR)
|
||||
for (event in events) {
|
||||
out.writeLn(BEGIN_EVENT)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Du kannst neue Termine mit dem Plus Button unten rechts erstellen.</string>
|
||||
<string name="details">Details</string>
|
||||
<string name="go_to_today">Gehe zu Heute</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Monatskalender</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">Detalles</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Vous pouvez ajouter des évènements avec le bouton Plus en bas.</string>
|
||||
<string name="details">Détails</string>
|
||||
<string name="go_to_today">Aller à aujourd\'hui</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendrier mensuel</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">विवरण</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">Részletek</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Havi naptár</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">Dettagli</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">ניתן להוסיף אירועים בעזרת כפתור הפלוס למטה.</string>
|
||||
<string name="details">פרטים</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">לוח השנה חודשית</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">詳細</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">カレンダー月</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Pode-se adicionar um evento através do botão existente na base da tela.</string>
|
||||
<string name="details">Detalhes</string>
|
||||
<string name="go_to_today">Ir para hoje</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendário mensal</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Pode adicionar um evento através do botão existente na base do ecrã.</string>
|
||||
<string name="details">Detalhes</string>
|
||||
<string name="go_to_today">Ir para hoje</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendário mensal</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Вы можете их добавить, нажав на кнопку с плюсом внизу.</string>
|
||||
<string name="details">Подробности</string>
|
||||
<string name="go_to_today">Сегодня</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Календарь на месяц</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Viete ich pridať pomocou tlačidla Plus v pravom dolnom rohu.</string>
|
||||
<string name="details">Detaily</string>
|
||||
<string name="go_to_today">Prejsť na dnešok</string>
|
||||
<string name="no_app_for_ics">Nenašla sa žiadna aplikácia schopná spracovania .ics súboru</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Kalendár mesačný</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">Du kan lägga till händelser via plus-knappen som du ser längst ner.</string>
|
||||
<string name="details">Detaljer</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Kalender månadsvis</string>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_some_events">You can add some with the Plus button at the bottom.</string>
|
||||
<string name="details">Details</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
<string name="no_app_for_ics">No app capable of handling .ics files has been found</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path
|
||||
name="shared_events"
|
||||
path="events/"/>
|
||||
</paths>
|
Loading…
Reference in New Issue