Skip to content

Commit

Permalink
https://github.com/Co-Epi/app-android/issues/95
Browse files Browse the repository at this point in the history
  • Loading branch information
tneagu committed Apr 21, 2020
1 parent cecd5c4 commit 8c8edd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/src/main/java/org/coepi/android/cen/RealmCenDao.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.coepi.android.cen

import io.realm.kotlin.createObject
import io.realm.kotlin.delete
import io.realm.kotlin.oneOf
import io.realm.kotlin.where
import org.coepi.android.domain.CoEpiDate
Expand Down Expand Up @@ -32,12 +33,18 @@ class RealmCenDao(private val realmProvider: RealmProvider) {
return false
}
realm.executeTransaction {
val realmObj = realm.createObject<RealmReceivedCen>(cen.cen.toHex()) // Create a new object
val realmObj =
realm.createObject<RealmReceivedCen>(cen.cen.toHex()) // Create a new object
realmObj.timestamp = cen.date.unixTime
}
return true
}

// @Delete("DELETE FROM cen where :timeStamp > timeStamp")
// fun cleanCENs(timeStamp : Int)
// @Delete("DELETE FROM cen where :timeStamp > timeStamp")
fun cleanCENs(timeStamp: Long) =
realm.where<RealmReceivedCen>()
.lessThan("timestamp", timeStamp)
.findAll()
.deleteAllFromRealm()

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.work.ListenableWorker.Result.success
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import kotlinx.coroutines.delay
import org.coepi.android.cen.RealmCenDao
import org.coepi.android.cen.RealmCenReportDao
import org.coepi.android.cen.ReceivedCenReport
import org.coepi.android.common.doIfSuccess
Expand All @@ -29,6 +30,7 @@ class ContactsFetchWorker(

private val coEpiRepo: CoEpiRepo by inject()
private val reportsDao: RealmCenReportDao by inject()
private val cenDao: RealmCenDao by inject()
private val preferences: Preferences by inject()

override suspend fun doWork(): Result {
Expand All @@ -40,6 +42,9 @@ class ContactsFetchWorker(

val nowBeforeRequest: CoEpiDate = now()

//delete old CENs
cenDao.cleanCENs(nowBeforeRequest.unixTime)

val reportsResult =
coEpiRepo.reports(fromDate)
val reports: List<ReceivedCenReport> = reportsResult.successOrNull() ?: emptyList()
Expand Down

0 comments on commit 8c8edd6

Please sign in to comment.