forked from github/szkolny
[DataRemoveModel/Events] Add removing future except list of types.
This commit is contained in:
parent
e9ca109c57
commit
3cca5e8e9a
@ -70,7 +70,10 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
))
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Events.futureExceptType(Event.TYPE_HOMEWORK))
|
||||
data.toRemove.add(DataRemoveModel.Events.futureExceptTypes(listOf(
|
||||
Event.TYPE_HOMEWORK,
|
||||
Event.TYPE_PT_MEETING
|
||||
)))
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_EVENTS, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
|
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_PT_MEETINGS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
@ -61,6 +62,8 @@ class LibrusApiPtMeetings(override val data: DataLibrus,
|
||||
))
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_PT_MEETING))
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_PT_MEETINGS, 12*HOUR)
|
||||
onSuccess()
|
||||
}
|
||||
|
@ -47,15 +47,17 @@ open class DataRemoveModel {
|
||||
}
|
||||
}
|
||||
|
||||
class Events(private val type: Int?, private val exceptType: Int?) : DataRemoveModel() {
|
||||
class Events(private val type: Int?, private val exceptType: Int?, private val exceptTypes: List<Int>?) : DataRemoveModel() {
|
||||
companion object {
|
||||
fun futureExceptType(exceptType: Int) = Events(null, exceptType)
|
||||
fun futureWithType(type: Int) = Events(type, null)
|
||||
fun futureExceptType(exceptType: Int) = Events(null, exceptType, null)
|
||||
fun futureExceptTypes(exceptTypes: List<Int>) = Events(null, null, exceptTypes)
|
||||
fun futureWithType(type: Int) = Events(type, null, null)
|
||||
}
|
||||
|
||||
fun commit(profileId: Int, dao: EventDao) {
|
||||
type?.let { dao.removeFutureWithType(profileId, Date.getToday(), it) }
|
||||
exceptType?.let { dao.removeFutureExceptType(profileId, Date.getToday(), it) }
|
||||
exceptTypes?.let { dao.removeFutureExceptTypes(profileId, Date.getToday(), it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,8 +130,14 @@ public abstract class EventDao {
|
||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0")
|
||||
public abstract void removeNotManual(int profileId);
|
||||
|
||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate")
|
||||
public abstract void removeFuture(int profileId, Date todayDate);
|
||||
@RawQuery
|
||||
abstract long removeFuture(SupportSQLiteQuery query);
|
||||
@Transaction
|
||||
public void removeFuture(int profileId, Date todayDate, String filter) {
|
||||
removeFuture(new SimpleSQLiteQuery("DELETE FROM events WHERE profileId = " + profileId
|
||||
+ " AND eventAddedManually = 0 AND eventDate >= '" + todayDate.getStringY_m_d() + "'" +
|
||||
" AND " + filter));
|
||||
}
|
||||
|
||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType = :type")
|
||||
public abstract void removeFutureWithType(int profileId, Date todayDate, int type);
|
||||
@ -139,6 +145,11 @@ public abstract class EventDao {
|
||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType != :exceptType")
|
||||
public abstract void removeFutureExceptType(int profileId, Date todayDate, int exceptType);
|
||||
|
||||
@Transaction
|
||||
public void removeFutureExceptTypes(int profileId, Date todayDate, List<Integer> exceptTypes) {
|
||||
removeFuture(profileId, todayDate, "eventType NOT IN " + exceptTypes.toString().replace('[', '(').replace(']', ')'));
|
||||
}
|
||||
|
||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND (thingType = "+TYPE_EVENT+" OR thingType = "+TYPE_LESSON_CHANGE+" OR thingType = "+TYPE_HOMEWORK+") AND thingId IN (SELECT eventId FROM events WHERE profileId = :profileId AND eventDate = :date)")
|
||||
public abstract void setSeenByDate(int profileId, Date date, boolean seen);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user