diff --git a/omnipod-eros/src/androidTest/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistoryTest.kt b/omnipod-eros/src/androidTest/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistoryTest.kt index 5e905de55f..b441accbc1 100644 --- a/omnipod-eros/src/androidTest/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistoryTest.kt +++ b/omnipod-eros/src/androidTest/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistoryTest.kt @@ -34,7 +34,7 @@ class ErosHistoryTest { @Test fun testInsertionAndRetrieval() { - var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true); + var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L); assert(history.isEmpty()) val type = PodHistoryEntryType.SET_BOLUS.code.toLong() @@ -42,14 +42,10 @@ class ErosHistoryTest { erosHistory.create(entity) erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong())) - history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true); + history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L); assert(history.size == 2) assert(type.equals(history.first().podEntryTypeCode)) - history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, false); - assert(history.size == 2) - assert(type.equals(history.last().podEntryTypeCode)) - val returnedEntity = erosHistory.findErosHistoryRecordByPumpId(entity.pumpId) assertNotNull(returnedEntity) assert(type.equals(returnedEntity.podEntryTypeCode)) diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java index 727296a8ac..f117643cbe 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java @@ -4,29 +4,28 @@ import java.util.List; import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao; import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity; +import io.reactivex.Single; public class ErosHistory { - private ErosHistoryRecordDao dao; + private final ErosHistoryRecordDao dao; public ErosHistory(ErosHistoryRecordDao dao) { this.dao = dao; } - public List getAllErosHistoryRecordsFromTimestamp(long timeInMillis, boolean ascending) { - if (ascending){ - return dao.allSinceAsc(timeInMillis); - } - else { - return dao.allSinceDesc(timeInMillis); - } + public List getAllErosHistoryRecordsFromTimestamp(long timeInMillis) { + return dao.allSinceAsc(timeInMillis).blockingGet(); + } public ErosHistoryRecordEntity findErosHistoryRecordByPumpId(long pumpId) { - return dao.byId(pumpId); + Single entity = dao.byId(pumpId); + return (entity == null) ? null: entity.blockingGet(); } public void create(ErosHistoryRecordEntity historyRecord){ - dao.insert(historyRecord); + // no need for rowId, but lose warnings in IDE and make sure transaction is completed. + long rowId = Single.just(dao.insert(historyRecord)).blockingGet(); } } diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryDatabase.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryDatabase.kt index a8cfef5b9b..2ee8b16f76 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryDatabase.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryDatabase.kt @@ -24,7 +24,6 @@ abstract class ErosHistoryDatabase : RoomDatabase() { ErosHistoryDatabase::class.java, "omnipod_eros_history_database.db" ) - .allowMainThreadQueries() .fallbackToDestructiveMigration() .build() } diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt index 2e80b6541d..7fc1ff18f5 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt @@ -5,20 +5,18 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.Transaction +import io.reactivex.Single @Dao interface ErosHistoryRecordDao { @Query("SELECT * from historyrecords WHERE date >= :since order by date asc") - fun allSinceAsc(since: Long): List - - @Query("SELECT * from historyrecords WHERE date >= :since order by date desc") - fun allSinceDesc(since: Long): List + fun allSinceAsc(since: Long): Single> @Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1") - fun byId(id: Long): ErosHistoryRecordEntity? + fun byId(id: Long): Single? @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity) + fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity): Long } diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodHistoryActivity.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodHistoryActivity.java index 18be1c92a7..ab3f39dd38 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodHistoryActivity.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodHistoryActivity.java @@ -68,7 +68,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity { GregorianCalendar gc = new GregorianCalendar(); gc.add(Calendar.HOUR_OF_DAY, -24); - fullHistoryList.addAll(erosHistory.getAllErosHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true)); + fullHistoryList.addAll(erosHistory.getAllErosHistoryRecordsFromTimestamp(gc.getTimeInMillis())); }