lets remove the EventRepetition table, we dont even neede it

This commit is contained in:
tibbi 2018-11-16 13:11:24 +01:00
parent b00d7366d9
commit c372eda2ac
8 changed files with 7 additions and 55 deletions

View File

@ -9,24 +9,20 @@ import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
import com.simplemobiletools.calendar.pro.interfaces.EventRepetitionExceptionsDao
import com.simplemobiletools.calendar.pro.interfaces.EventRepetitionsDao
import com.simplemobiletools.calendar.pro.interfaces.EventTypesDao
import com.simplemobiletools.calendar.pro.interfaces.EventsDao
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventRepetition
import com.simplemobiletools.calendar.pro.models.EventRepetitionException
import com.simplemobiletools.calendar.pro.models.EventType
import java.util.concurrent.Executors
@Database(entities = [Event::class, EventType::class, EventRepetition::class, EventRepetitionException::class], version = 1)
@Database(entities = [Event::class, EventType::class, EventRepetitionException::class], version = 1)
abstract class EventsDatabase : RoomDatabase() {
abstract fun EventsDao(): EventsDao
abstract fun EventTypesDao(): EventTypesDao
abstract fun EventRepetitionsDao(): EventRepetitionsDao
abstract fun EventRepetitionExceptionsDao(): EventRepetitionExceptionsDao
companion object {

View File

@ -29,7 +29,6 @@ import com.simplemobiletools.calendar.pro.databases.EventsDatabase
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.interfaces.EventRepetitionExceptionsDao
import com.simplemobiletools.calendar.pro.interfaces.EventRepetitionsDao
import com.simplemobiletools.calendar.pro.interfaces.EventTypesDao
import com.simplemobiletools.calendar.pro.interfaces.EventsDao
import com.simplemobiletools.calendar.pro.models.*
@ -49,7 +48,6 @@ import java.util.*
val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.eventsDB: EventsDao get() = EventsDatabase.getInstance(applicationContext).EventsDao()
val Context.eventTypesDB: EventTypesDao get() = EventsDatabase.getInstance(applicationContext).EventTypesDao()
val Context.eventRepetitionsDB: EventRepetitionsDao get() = EventsDatabase.getInstance(applicationContext).EventRepetitionsDao()
val Context.eventRepetitionExceptionsDB: EventRepetitionExceptionsDao get() = EventsDatabase.getInstance(applicationContext).EventRepetitionExceptionsDao()
val Context.eventsHelper: EventsHelper get() = EventsHelper(this)
val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this)

View File

@ -14,7 +14,6 @@ class EventsHelper(val context: Context) {
private val config = context.config
private val eventsDB = context.eventsDB
private val eventTypesDB = context.eventTypesDB
private val eventRepetitionsDB = context.eventRepetitionsDB
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
Thread {
@ -88,10 +87,6 @@ class EventsHelper(val context: Context) {
event.updateIsEventRepeatable()
event.id = eventsDB.insertOrUpdate(event)
if (event.repeatInterval != 0 && event.parentId == 0L) {
eventRepetitionsDB.insertOrUpdate(event.getEventRepetition())
}
context.updateWidgets()
context.scheduleNextEventReminder(event, activity)
@ -112,10 +107,6 @@ class EventsHelper(val context: Context) {
event.updateIsEventRepeatable()
event.id = eventsDB.insertOrUpdate(event)
if (event.repeatInterval != 0 && event.parentId == 0L) {
eventRepetitionsDB.insertOrUpdate(event.getEventRepetition())
}
context.scheduleNextEventReminder(event)
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && config.caldavSync) {
context.calDAVHelper.insertCalDAVEvent(event)
@ -130,12 +121,6 @@ class EventsHelper(val context: Context) {
event.updateIsEventRepeatable()
eventsDB.insertOrUpdate(event)
if (event.repeatInterval == 0) {
eventRepetitionsDB.deleteEventRepetitionsOfEvent(event.id!!)
} else {
eventRepetitionsDB.insertOrUpdate(event.getEventRepetition())
}
context.updateWidgets()
context.scheduleNextEventReminder(event, activity)
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {
@ -185,7 +170,7 @@ class EventsHelper(val context: Context) {
fun addEventRepeatLimit(eventId: Long, limitTS: Long) {
val time = Formatter.getDateTimeFromTS(limitTS)
eventRepetitionsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
eventsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
if (config.caldavSync) {
val event = eventsDB.getEventWithId(eventId)

View File

@ -46,7 +46,7 @@ class Parser {
repeatRule = REPEAT_LAST_DAY
}
}
return EventRepetition(null, 0, repeatInterval, repeatRule, repeatLimit)
return EventRepetition(repeatInterval, repeatRule, repeatLimit)
}
private fun getFrequencySeconds(interval: String) = when (interval) {

View File

@ -1,19 +0,0 @@
package com.simplemobiletools.calendar.pro.interfaces
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.simplemobiletools.calendar.pro.models.EventRepetition
@Dao
interface EventRepetitionsDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(eventRepetition: EventRepetition)
@Query("DELETE FROM event_repetitions WHERE event_id = :eventId")
fun deleteEventRepetitionsOfEvent(eventId: Long)
@Query("UPDATE event_repetitions SET repeat_limit = :repeatLimit WHERE event_id = :eventId")
fun updateEventRepetitionLimit(repeatLimit: Long, eventId: Long)
}

View File

@ -74,6 +74,9 @@ interface EventsDao {
@Query("UPDATE events SET import_id = :importId AND source = :source WHERE id = :id")
fun updateEventImportIdAndSource(importId: String, source: String, id: Long)
@Query("UPDATE events SET repeat_limit = :repeatLimit WHERE id = :id")
fun updateEventRepetitionLimit(repeatLimit: Long, id: Long)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(event: Event): Long

View File

@ -135,8 +135,6 @@ data class Event(
fun getCalDAVCalendarId() = if (source.startsWith(CALDAV)) (source.split("-").lastOrNull() ?: "0").toString().toInt() else 0
fun getEventRepetition() = EventRepetition(null, id!!, repeatInterval, repeatRule, repeatLimit)
// check if its the proper week, for events repeating every x weeks
fun isOnProperWeek(startTimes: LongSparseArray<Long>): Boolean {
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[id!!]!!).weekOfWeekyear

View File

@ -1,12 +1,3 @@
package com.simplemobiletools.calendar.pro.models
import androidx.room.*
@Entity(tableName = "event_repetitions", indices = [(Index(value = ["id"], unique = true))],
foreignKeys = [ForeignKey(entity = Event::class, onDelete = ForeignKey.CASCADE, parentColumns = ["id"], childColumns = ["event_id"])])
data class EventRepetition(
@PrimaryKey(autoGenerate = true) var id: Long?,
@ColumnInfo(name = "event_id") val eventId: Long,
@ColumnInfo(name = "repeat_interval") val repeatInterval: Int,
@ColumnInfo(name = "repeat_rule") val repeatRule: Int,
@ColumnInfo(name = "repeat_limit") val repeatLimit: Long)
data class EventRepetition(val repeatInterval: Int, val repeatRule: Int, val repeatLimit: Long)