This commit is contained in:
Milos Kozak 2021-10-19 12:06:04 +02:00
commit 8631ab12de
11 changed files with 31 additions and 44 deletions

View file

@ -412,6 +412,7 @@ class LoopDialog : DaggerDialogFragment() {
loopPlugin.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) loopPlugin.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
rxBus.send(EventRefreshOverview("suspend_menu")) rxBus.send(EventRefreshOverview("suspend_menu"))
} }
sp.putBoolean(R.string.key_objectiveusedisconnect, true)
return true return true
} }

View file

@ -185,6 +185,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
ValueWithUnit.Percent(percent), ValueWithUnit.Percent(percent),
ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 }, ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 },
ValueWithUnit.Minute(duration).takeIf { duration != 0 }) ValueWithUnit.Minute(duration).takeIf { duration != 0 })
if (percent == 90 && duration == 10) sp.putBoolean(R.string.key_objectiveuseprofileswitch, true)
if (isTT) { if (isTT) {
disposable += repository.runTransactionForResult( disposable += repository.runTransactionForResult(
InsertAndCancelCurrentTemporaryTargetTransaction( InsertAndCancelCurrentTemporaryTargetTransaction(

View file

@ -86,10 +86,10 @@ abstract class Objective(injector: HasAndroidInjector, spName: String, @StringRe
abstract fun isCompleted(): Boolean abstract fun isCompleted(): Boolean
open fun isCompleted(trueTime: Long): Boolean = isCompleted open fun isCompleted(trueTime: Long): Boolean = isCompleted()
open val progress: String open val progress: String
get() = resourceHelper.gs(if (isCompleted) R.string.completed_well_done else R.string.not_completed_yet) get() = resourceHelper.gs(if (isCompleted()) R.string.completed_well_done else R.string.not_completed_yet)
fun hint(hint: Hint): Task { fun hint(hint: Hint): Task {
hints.add(hint) hints.add(hint)

View file

@ -200,11 +200,11 @@ class SafetyPlugin @Inject constructor(
JSONObject() JSONObject()
.putString(R.string.key_age, sp, resourceHelper) .putString(R.string.key_age, sp, resourceHelper)
.putDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper) .putDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
.putDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper) .putInt(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
override fun applyConfiguration(configuration: JSONObject) { override fun applyConfiguration(configuration: JSONObject) {
configuration.storeString(R.string.key_age, sp, resourceHelper) configuration.storeString(R.string.key_age, sp, resourceHelper)
configuration.storeDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper) configuration.storeDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
configuration.storeDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper) configuration.storeInt(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
} }
} }

View file

@ -507,11 +507,6 @@ class ActionStringHandler @Inject constructor(
val duration = SafeParse.stringToInt(act[2]) val duration = SafeParse.stringToInt(act[2])
var low = SafeParse.stringToDouble(act[3]) var low = SafeParse.stringToDouble(act[3])
var high = SafeParse.stringToDouble(act[4]) var high = SafeParse.stringToDouble(act[4])
val isMGDL = java.lang.Boolean.parseBoolean(act[1])
if (!isMGDL) {
low *= Constants.MMOLL_TO_MGDL
high *= Constants.MMOLL_TO_MGDL
}
generateTempTarget(duration, low, high) generateTempTarget(duration, low, high)
} else if ("wizard2" == act[0]) { } else if ("wizard2" == act[0]) {
if (lastBolusWizard != null) { //use last calculation as confirmed string matches if (lastBolusWizard != null) { //use last calculation as confirmed string matches

View file

@ -240,7 +240,6 @@
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/cob_layout" app:layout_constraintEnd_toStartOf="@+id/cob_layout"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bg" app:layout_constraintTop_toBottomOf="@+id/bg"
@ -272,7 +271,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/basal_layout" app:layout_constraintEnd_toStartOf="@+id/basal_layout"
app:layout_constraintStart_toEndOf="@+id/iob_layout" app:layout_constraintStart_toEndOf="@+id/iob_layout"
app:layout_constraintTop_toTopOf="@+id/iob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout"
@ -305,7 +303,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/extended_layout" app:layout_constraintEnd_toStartOf="@+id/extended_layout"
app:layout_constraintStart_toEndOf="@+id/cob_layout" app:layout_constraintStart_toEndOf="@+id/cob_layout"
app:layout_constraintTop_toTopOf="@+id/iob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout"
@ -338,7 +335,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/as_layout" app:layout_constraintEnd_toStartOf="@+id/as_layout"
app:layout_constraintStart_toEndOf="@+id/basal_layout" app:layout_constraintStart_toEndOf="@+id/basal_layout"
app:layout_constraintTop_toTopOf="@+id/iob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout"
@ -370,7 +366,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/extended_layout" app:layout_constraintStart_toEndOf="@+id/extended_layout"
app:layout_constraintTop_toTopOf="@+id/iob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout"

View file

@ -77,7 +77,7 @@ class PumpSyncImplementation @Inject constructor(
} }
override fun expectedPumpState(): PumpSync.PumpState { override fun expectedPumpState(): PumpSync.PumpState {
val bolus = repository.getLastBolusRecord() val bolus = repository.getLastBolusRecordWrapped().blockingGet();
val temporaryBasal = repository.getTemporaryBasalActiveAt(dateUtil.now()).blockingGet() val temporaryBasal = repository.getTemporaryBasalActiveAt(dateUtil.now()).blockingGet()
val extendedBolus = repository.getExtendedBolusActiveAt(dateUtil.now()).blockingGet() val extendedBolus = repository.getExtendedBolusActiveAt(dateUtil.now()).blockingGet()
@ -104,12 +104,14 @@ class PumpSyncImplementation @Inject constructor(
) )
else null, else null,
bolus = bolus =
bolus?.let { if (bolus is ValueWrapper.Existing)
bolus.value.let {
PumpSync.PumpState.Bolus( PumpSync.PumpState.Bolus(
timestamp = bolus.timestamp, timestamp = bolus.value.timestamp,
amount = bolus.amount amount = bolus.value.amount
) )
}, }
else null,
profile = profileFunction.getProfile() profile = profileFunction.getProfile()
) )
} }

View file

@ -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))

View file

@ -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();
} }
} }

View file

@ -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
} }

View file

@ -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()));
} }