transforming RepeatRule into a database table

This commit is contained in:
tibbi 2018-11-13 20:07:37 +01:00
parent 0d7d4efc97
commit d9fae609ac
3 changed files with 17 additions and 10 deletions

View File

@ -5,21 +5,18 @@ import com.simplemobiletools.calendar.pro.extensions.isXWeeklyRepetition
import com.simplemobiletools.calendar.pro.extensions.isXYearlyRepetition
import com.simplemobiletools.calendar.pro.extensions.seconds
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.RepeatRule
import com.simplemobiletools.calendar.pro.models.EventRepetition
import com.simplemobiletools.commons.helpers.*
import org.joda.time.DateTimeZone
import org.joda.time.format.DateTimeFormat
class Parser {
// from RRULE:FREQ=DAILY;COUNT=5 to Daily, 5x...
fun parseRepeatInterval(fullString: String, startTS: Int): RepeatRule {
val parts = fullString.split(";")
fun parseRepeatInterval(fullString: String, startTS: Int): EventRepetition {
val parts = fullString.split(";").filter { it.isNotEmpty() }
var repeatInterval = 0
var repeatRule = 0
var repeatLimit = 0
if (fullString.isEmpty()) {
return RepeatRule(repeatInterval, repeatRule, repeatLimit)
}
for (part in parts) {
val keyValue = part.split("=")
@ -49,7 +46,7 @@ class Parser {
repeatRule = REPEAT_LAST_DAY
}
}
return RepeatRule(repeatInterval, repeatRule, repeatLimit)
return EventRepetition(null, repeatInterval, repeatRule, repeatLimit)
}
private fun getFrequencySeconds(interval: String) = when (interval) {

View File

@ -0,0 +1,13 @@
package com.simplemobiletools.calendar.pro.models
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
@Entity(tableName = "event_repetitions", indices = [(Index(value = ["id"], unique = true))])
data class EventRepetition(
@PrimaryKey(autoGenerate = true) var id: Long?,
@ColumnInfo(name = "repeat_interval") val repeatInterval: Int,
@ColumnInfo(name = "repeat_rule") val repeatRule: Int,
@ColumnInfo(name = "repeat_limit") val repeatLimit: Int)

View File

@ -1,3 +0,0 @@
package com.simplemobiletools.calendar.pro.models
data class RepeatRule(val repeatInterval: Int, val repeatRule: Int, val repeatLimit: Int)