diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index 87664dd591..8542d3dcf6 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -412,6 +412,7 @@ class LoopDialog : DaggerDialogFragment() { loopPlugin.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } + sp.putBoolean(R.string.key_objectiveusedisconnect, true) return true } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index a2b109316d..77a2418cca 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -185,6 +185,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { ValueWithUnit.Percent(percent), ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 }, ValueWithUnit.Minute(duration).takeIf { duration != 0 }) + if (percent == 90 && duration == 10) sp.putBoolean(R.string.key_objectiveuseprofileswitch, true) if (isTT) { disposable += repository.runTransactionForResult( InsertAndCancelCurrentTemporaryTargetTransaction( diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt index 71f258781d..0a0e1477f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt @@ -86,10 +86,10 @@ abstract class Objective(injector: HasAndroidInjector, spName: String, @StringRe abstract fun isCompleted(): Boolean - open fun isCompleted(trueTime: Long): Boolean = isCompleted + open fun isCompleted(trueTime: Long): Boolean = isCompleted() 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 { hints.add(hint) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt index 473f92f080..e5652e31fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt @@ -200,11 +200,11 @@ class SafetyPlugin @Inject constructor( JSONObject() .putString(R.string.key_age, 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) { configuration.storeString(R.string.key_age, 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) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index 7708c382b8..72bcab6b7b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -507,11 +507,6 @@ class ActionStringHandler @Inject constructor( val duration = SafeParse.stringToInt(act[2]) var low = SafeParse.stringToDouble(act[3]) 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) } else if ("wizard2" == act[0]) { if (lastBolusWizard != null) { //use last calculation as confirmed string matches diff --git a/app/src/main/res/layout/overview_info_layout.xml b/app/src/main/res/layout/overview_info_layout.xml index 8d41ca1700..7ec4d562ee 100644 --- a/app/src/main/res/layout/overview_info_layout.xml +++ b/app/src/main/res/layout/overview_info_layout.xml @@ -240,7 +240,6 @@ android:layout_marginStart="5dp" android:gravity="center_horizontal" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/cob_layout" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/bg" @@ -272,7 +271,6 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/basal_layout" app:layout_constraintStart_toEndOf="@+id/iob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout" @@ -305,7 +303,6 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/extended_layout" app:layout_constraintStart_toEndOf="@+id/cob_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout" @@ -338,7 +335,6 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/as_layout" app:layout_constraintStart_toEndOf="@+id/basal_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout" @@ -370,7 +366,6 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/extended_layout" app:layout_constraintTop_toTopOf="@+id/iob_layout" diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt index fed920d7b4..1a92af8ae6 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt @@ -77,7 +77,7 @@ class PumpSyncImplementation @Inject constructor( } override fun expectedPumpState(): PumpSync.PumpState { - val bolus = repository.getLastBolusRecord() + val bolus = repository.getLastBolusRecordWrapped().blockingGet(); val temporaryBasal = repository.getTemporaryBasalActiveAt(dateUtil.now()).blockingGet() val extendedBolus = repository.getExtendedBolusActiveAt(dateUtil.now()).blockingGet() @@ -104,12 +104,14 @@ class PumpSyncImplementation @Inject constructor( ) else null, bolus = - bolus?.let { - PumpSync.PumpState.Bolus( - timestamp = bolus.timestamp, - amount = bolus.amount - ) - }, + if (bolus is ValueWrapper.Existing) + bolus.value.let { + PumpSync.PumpState.Bolus( + timestamp = bolus.value.timestamp, + amount = bolus.value.amount + ) + } + else null, profile = profileFunction.getProfile() ) } 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/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())); }