diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/databases/EventsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/databases/EventsDatabase.kt index 35cd91fdc..654aa4d5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/databases/EventsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/databases/EventsDatabase.kt @@ -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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 3fe7fe3ee..eed93940a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt index 2a6d5df8c..550c03544 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt @@ -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) -> 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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt index 32353d180..a0bf1b1ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventRepetitionsDao.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventRepetitionsDao.kt deleted file mode 100644 index 2584b1089..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventRepetitionsDao.kt +++ /dev/null @@ -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) -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt index 4e5e6dd74..6184e8c38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt index 71ae4a682..d71f31309 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt @@ -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): Boolean { val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[id!!]!!).weekOfWeekyear diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/EventRepetition.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/EventRepetition.kt index 0e94ba01d..7af651fc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/EventRepetition.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/EventRepetition.kt @@ -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)