mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fill event repeat interval
This commit is contained in:
@ -5,6 +5,7 @@ import com.simplemobiletools.calendar.extensions.dbHelper
|
|||||||
import com.simplemobiletools.calendar.extensions.writeLn
|
import com.simplemobiletools.calendar.extensions.writeLn
|
||||||
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 java.io.BufferedWriter
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class IcsExporter {
|
class IcsExporter {
|
||||||
@ -33,8 +34,10 @@ class IcsExporter {
|
|||||||
event.startTS.let { out.writeLn("$DTSTART:${Formatter.getExportedTime(it)}") }
|
event.startTS.let { out.writeLn("$DTSTART:${Formatter.getExportedTime(it)}") }
|
||||||
event.endTS.let { out.writeLn("$DTEND:${Formatter.getExportedTime(it)}") }
|
event.endTS.let { out.writeLn("$DTEND:${Formatter.getExportedTime(it)}") }
|
||||||
}
|
}
|
||||||
out.writeLn("$STATUS$CONFIRMED")
|
|
||||||
|
|
||||||
|
fillRepeatInterval(event.repeatInterval, out)
|
||||||
|
|
||||||
|
out.writeLn("$STATUS$CONFIRMED")
|
||||||
out.writeLn(END_EVENT)
|
out.writeLn(END_EVENT)
|
||||||
}
|
}
|
||||||
out.writeLn(END_CALENDAR)
|
out.writeLn(END_CALENDAR)
|
||||||
@ -48,4 +51,32 @@ class IcsExporter {
|
|||||||
EXPORT_OK
|
EXPORT_OK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fillRepeatInterval(repeatInterval: Int, out: BufferedWriter) {
|
||||||
|
if (repeatInterval == 0)
|
||||||
|
return
|
||||||
|
|
||||||
|
val freq = getFreq(repeatInterval)
|
||||||
|
val interval = getInterval(repeatInterval)
|
||||||
|
val rrule = "$RRULE=$FREQ=$freq;$INTERVAL=$interval"
|
||||||
|
out.writeLn(rrule)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getFreq(interval: Int) = when (interval) {
|
||||||
|
DAY -> DAILY
|
||||||
|
WEEK -> WEEKLY
|
||||||
|
MONTH -> MONTHLY
|
||||||
|
else -> YEARLY
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getInterval(interval: Int): Int {
|
||||||
|
return if (interval % YEAR == 0)
|
||||||
|
interval / YEAR
|
||||||
|
else if (interval % MONTH == 0)
|
||||||
|
interval / MONTH
|
||||||
|
else if (interval % WEEK == 0)
|
||||||
|
interval / WEEK
|
||||||
|
else
|
||||||
|
interval / DAY
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user