Merge pull request #753 from samspycher/feature/eros-history
Fix for DB access on main thread for eros history module
This commit is contained in:
commit
5cf325056d
4 changed files with 16 additions and 23 deletions
|
@ -34,7 +34,7 @@ class ErosHistoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testInsertionAndRetrieval() {
|
fun testInsertionAndRetrieval() {
|
||||||
var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
|
var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L);
|
||||||
assert(history.isEmpty())
|
assert(history.isEmpty())
|
||||||
|
|
||||||
val type = PodHistoryEntryType.SET_BOLUS.code.toLong()
|
val type = PodHistoryEntryType.SET_BOLUS.code.toLong()
|
||||||
|
@ -42,14 +42,10 @@ class ErosHistoryTest {
|
||||||
erosHistory.create(entity)
|
erosHistory.create(entity)
|
||||||
erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong()))
|
erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong()))
|
||||||
|
|
||||||
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
|
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L);
|
||||||
assert(history.size == 2)
|
assert(history.size == 2)
|
||||||
assert(type.equals(history.first().podEntryTypeCode))
|
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)
|
val returnedEntity = erosHistory.findErosHistoryRecordByPumpId(entity.pumpId)
|
||||||
assertNotNull(returnedEntity)
|
assertNotNull(returnedEntity)
|
||||||
assert(type.equals(returnedEntity.podEntryTypeCode))
|
assert(type.equals(returnedEntity.podEntryTypeCode))
|
||||||
|
|
|
@ -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.ErosHistoryRecordDao;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity;
|
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
|
||||||
public class ErosHistory
|
public class ErosHistory
|
||||||
{
|
{
|
||||||
private ErosHistoryRecordDao dao;
|
private final ErosHistoryRecordDao dao;
|
||||||
|
|
||||||
public ErosHistory(ErosHistoryRecordDao dao) {
|
public ErosHistory(ErosHistoryRecordDao dao) {
|
||||||
this.dao = dao;
|
this.dao = dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ErosHistoryRecordEntity> getAllErosHistoryRecordsFromTimestamp(long timeInMillis, boolean ascending) {
|
public List<ErosHistoryRecordEntity> getAllErosHistoryRecordsFromTimestamp(long timeInMillis) {
|
||||||
if (ascending){
|
return dao.allSinceAsc(timeInMillis).blockingGet();
|
||||||
return dao.allSinceAsc(timeInMillis);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return dao.allSinceDesc(timeInMillis);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErosHistoryRecordEntity findErosHistoryRecordByPumpId(long pumpId) {
|
public ErosHistoryRecordEntity findErosHistoryRecordByPumpId(long pumpId) {
|
||||||
return dao.byId(pumpId);
|
Single<ErosHistoryRecordEntity> entity = dao.byId(pumpId);
|
||||||
|
return (entity == null) ? null: entity.blockingGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(ErosHistoryRecordEntity historyRecord){
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,18 @@ import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.Transaction
|
import androidx.room.Transaction
|
||||||
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ErosHistoryRecordDao {
|
interface ErosHistoryRecordDao {
|
||||||
|
|
||||||
@Query("SELECT * from historyrecords WHERE date >= :since order by date asc")
|
@Query("SELECT * from historyrecords WHERE date >= :since order by date asc")
|
||||||
fun allSinceAsc(since: Long): List<ErosHistoryRecordEntity>
|
fun allSinceAsc(since: Long): Single<List<ErosHistoryRecordEntity>>
|
||||||
|
|
||||||
@Query("SELECT * from historyrecords WHERE date >= :since order by date desc")
|
|
||||||
fun allSinceDesc(since: Long): List<ErosHistoryRecordEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1")
|
@Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1")
|
||||||
fun byId(id: Long): ErosHistoryRecordEntity?
|
fun byId(id: Long): Single<ErosHistoryRecordEntity>?
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity)
|
fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity): Long
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
|
||||||
GregorianCalendar gc = new GregorianCalendar();
|
GregorianCalendar gc = new GregorianCalendar();
|
||||||
gc.add(Calendar.HOUR_OF_DAY, -24);
|
gc.add(Calendar.HOUR_OF_DAY, -24);
|
||||||
|
|
||||||
fullHistoryList.addAll(erosHistory.getAllErosHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true));
|
fullHistoryList.addAll(erosHistory.getAllErosHistoryRecordsFromTimestamp(gc.getTimeInMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue