diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java
deleted file mode 100644
index f76e6a0471..0000000000
--- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package info.nightscout.androidaps.plugins.pump.omnipod.common.definition;
-
-import info.nightscout.androidaps.plugins.pump.omnipod.common.R;
-
-/**
- * Created by andy on 4.8.2019
- */
-public enum OmnipodCommandType {
- INITIALIZE_POD(R.string.omnipod_common_cmd_initialize_pod), // First step of Pod activation
- INSERT_CANNULA(R.string.omnipod_common_cmd_insert_cannula), // Second step of Pod activation
- DEACTIVATE_POD(R.string.omnipod_common_cmd_deactivate_pod), //
- SET_BASAL_PROFILE(R.string.omnipod_common_cmd_set_basal_schedule), //
- SET_BOLUS(R.string.omnipod_common_cmd_set_bolus), //
- CANCEL_BOLUS(R.string.omnipod_common_cmd_cancel_bolus), //
- SET_TEMPORARY_BASAL(R.string.omnipod_common_cmd_set_tbr), //
- CANCEL_TEMPORARY_BASAL(R.string.omnipod_common_cmd_cancel_tbr_by_driver), //
- DISCARD_POD(R.string.omnipod_common_cmd_discard_pod), //
- GET_POD_STATUS(R.string.omnipod_common_cmd_get_pod_status), //
- SET_TIME(R.string.omnipod_common_cmd_set_time), //
- CONFIGURE_ALERTS(R.string.omnipod_common_cmd_configure_alerts), //
- ACKNOWLEDGE_ALERTS(R.string.omnipod_common_cmd_silence_alerts), //
- READ_POD_PULSE_LOG(R.string.omnipod_common_cmd_read_pulse_log), //
- SUSPEND_DELIVERY(R.string.omnipod_common_cmd_suspend_delivery),
- RESUME_DELIVERY(R.string.omnipod_common_cmd_resume_delivery),
- PLAY_TEST_BEEP(R.string.omnipod_common_cmd_play_test_beep);
-
- private final int resourceId;
-
- OmnipodCommandType(int resourceId) {
- this.resourceId = resourceId;
- }
-
- public int getResourceId() {
- return resourceId;
- }
-}
diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt
new file mode 100644
index 0000000000..333faef1e9
--- /dev/null
+++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.omnipod.common.definition
+
+import info.nightscout.androidaps.plugins.pump.omnipod.common.R
+
+/**
+ * Created by andy on 4.8.2019
+ */
+enum class OmnipodCommandType(val resourceId: Int) {
+
+ INITIALIZE_POD(R.string.omnipod_common_cmd_initialize_pod), // First step of Pod activation
+ INSERT_CANNULA(R.string.omnipod_common_cmd_insert_cannula), // Second step of Pod activation
+ DEACTIVATE_POD(R.string.omnipod_common_cmd_deactivate_pod), //
+ SET_BASAL_PROFILE(R.string.omnipod_common_cmd_set_basal_schedule), //
+ SET_BOLUS(R.string.omnipod_common_cmd_set_bolus), //
+ CANCEL_BOLUS(R.string.omnipod_common_cmd_cancel_bolus), //
+ SET_TEMPORARY_BASAL(R.string.omnipod_common_cmd_set_tbr), //
+ CANCEL_TEMPORARY_BASAL(R.string.omnipod_common_cmd_cancel_tbr_by_driver), //
+ DISCARD_POD(R.string.omnipod_common_cmd_discard_pod), //
+ GET_POD_STATUS(R.string.omnipod_common_cmd_get_pod_status), //
+ SET_TIME(R.string.omnipod_common_cmd_set_time), //
+ CONFIGURE_ALERTS(R.string.omnipod_common_cmd_configure_alerts), //
+ ACKNOWLEDGE_ALERTS(R.string.omnipod_common_cmd_silence_alerts), //
+ READ_POD_PULSE_LOG(R.string.omnipod_common_cmd_read_pulse_log), //
+ SUSPEND_DELIVERY(R.string.omnipod_common_cmd_suspend_delivery), RESUME_DELIVERY(R.string.omnipod_common_cmd_resume_delivery), PLAY_TEST_BEEP(R.string.omnipod_common_cmd_play_test_beep);
+
+}
\ No newline at end of file
diff --git a/omnipod-dash/build.gradle b/omnipod-dash/build.gradle
index b9dd868a07..7ed945c1aa 100644
--- a/omnipod-dash/build.gradle
+++ b/omnipod-dash/build.gradle
@@ -22,10 +22,12 @@ detekt { // TODO move to `subprojects` section in global build.gradle
dependencies {
implementation project(':core')
+ implementation project(':pump-common')
implementation project(':omnipod-common')
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
+ implementation project(path: ':pump-common')
kapt "androidx.room:room-compiler:$room_version"
implementation 'com.github.guepardoapps:kulid:2.0.0.0'
}
diff --git a/omnipod-dash/src/main/AndroidManifest.xml b/omnipod-dash/src/main/AndroidManifest.xml
index 180d3b98ce..4f6d8178c6 100644
--- a/omnipod-dash/src/main/AndroidManifest.xml
+++ b/omnipod-dash/src/main/AndroidManifest.xml
@@ -11,5 +11,6 @@
+
\ No newline at end of file
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt
index 15b53ed2e5..4db2aa2bc1 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt
@@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmed
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
@@ -363,8 +364,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
return PumpEnactResult(injector).success(true).enacted(true)
}
aapsLogger.debug(LTag.PUMP, "setNewBasalProfile profile=$profile")
- val basalProgram = mapProfileToBasalProgram(profile)
+ return setNewBasalProfile(profile, OmnipodCommandType.SET_BASAL_PROFILE)
+ }
+
+ private fun setNewBasalProfile(profile: Profile, historyType: OmnipodCommandType): PumpEnactResult {
var deliverySuspended = false
+ val basalProgram = mapProfileToBasalProgram(profile)
return executeProgrammingCommand(
pre = suspendDeliveryIfActive().doOnComplete {
if (podStateManager.activeCommand == null) {
@@ -372,7 +377,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
deliverySuspended = true
}
},
- historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE),
+ historyEntry = history.createRecord(
+ commandType = historyType,
+ basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList())
+ ),
activeCommandEntry = { historyId ->
podStateManager.createActiveCommand(historyId, basalProgram = basalProgram)
},
@@ -1139,7 +1147,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
return profileFunction.getProfile()?.let {
executeProgrammingCommand(
pre = observeDeliverySuspended(),
- historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY),
+ historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY, basalProfileRecord = BasalValuesRecord(it.getBasalValues().toList())),
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(it), hasBasalBeepEnabled())
.ignoreElements()
).doFinally {
@@ -1153,16 +1161,20 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
private fun deactivatePod(): PumpEnactResult {
+ var success = true
val ret = executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.DEACTIVATE_POD),
command = omnipodManager.deactivatePod().ignoreElements(),
checkNoActiveCommand = false,
post = createFakeTBRWhenNoActivePod(),
).doOnComplete {
+ if (podStateManager.activeCommand != null) {
+ success = false
+ }
+ podStateManager.reset()
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_FAULT))
}.toPumpEnactResult()
-
- if (podStateManager.activeCommand != null) {
+ if (!success) {
ret.success(false)
}
return ret
@@ -1170,7 +1182,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
private fun handleTimeChange(): PumpEnactResult {
return profileFunction.getProfile()?.let {
- setNewBasalProfile(it)
+ setNewBasalProfile(it, OmnipodCommandType.SET_TIME)
} ?: PumpEnactResult(injector).success(true).enacted(false).comment("No profile active")
}
@@ -1181,7 +1193,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
val lowReservoirAlertEnabled = sp.getBoolean(R.string.key_omnipod_common_low_reservoir_alert_enabled, true)
val lowReservoirAlertUnits = sp.getInt(R.string.key_omnipod_common_low_reservoir_alert_units, 10)
- if (!podStateManager.differentAlertSettings(
+ if (podStateManager.sameAlertSettings(
expirationReminderEnabled,
expirationHours,
lowReservoirAlertEnabled,
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt
index cbd7e42804..c565d67abc 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt
@@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodD
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManagerImpl
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManagerImpl
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.DashPodHistoryActivity
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.DashPodManagementActivity
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.activation.DashPodActivationWizardActivity
@@ -21,6 +22,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.deactivati
abstract class OmnipodDashModule {
// ACTIVITIES
+ @ContributesAndroidInjector
+ abstract fun contributesDashPodHistoryActivity(): DashPodHistoryActivity
+
@ContributesAndroidInjector
abstract fun contributesDashPodManagementActivity(): DashPodManagementActivity
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt
index 923109c5c1..2a88cc2d0d 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt
@@ -641,7 +641,6 @@ class OmnipodDashManagerImpl @Inject constructor(
observeConnectToPod,
observeSendDeactivateCommand
).interceptPodEvents()
- .doOnComplete(podStateManager::reset)
}
inner class PodEventInterceptor : Consumer {
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt
index d27a3b28c4..6f5ab0ee62 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt
@@ -105,7 +105,7 @@ interface OmnipodDashPodStateManager {
- after getPodStatus was successful(we have an up-to-date podStatus)
*/
fun recoverActivationFromPodStatus(): String?
- fun differentAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean
+ fun sameAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean
fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int): Completable
fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Completable
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt
index 899f94d386..07404b8607 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt
@@ -435,7 +435,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
}
}
- override fun differentAlertSettings(
+ override fun sameAlertSettings(
expirationReminderEnabled: Boolean,
expirationHours: Int,
lowReservoirAlertEnabled: Boolean,
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt
index f1e91651f7..637d3c383f 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt
@@ -7,11 +7,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.Omnipod
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_BOLUS
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_TEMPORARY_BASAL
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.*
-import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
-import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord
-import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
-import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
-import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.*
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordDao
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper.HistoryMapper
@@ -40,19 +36,18 @@ class DashHistory @Inject constructor(
fun getById(id: String): HistoryRecord {
val entry = dao.byIdBlocking(id)
- if (entry == null) {
- throw java.lang.IllegalArgumentException("history entry [$id] not found")
- }
+ ?: throw java.lang.IllegalArgumentException("history entry [$id] not found")
return historyMapper.entityToDomain(entry)
}
@Suppress("ReturnCount")
fun createRecord(
commandType: OmnipodCommandType,
- date: Long = System.currentTimeMillis(),
+ date: Long = currentTimeMillis(),
initialResult: InitialResult = InitialResult.NOT_SENT,
tempBasalRecord: TempBasalRecord? = null,
bolusRecord: BolusRecord? = null,
+ basalProfileRecord: BasalValuesRecord? = null,
resolveResult: ResolvedResult? = null,
resolvedAt: Long? = null
): Single = Single.defer {
@@ -72,6 +67,7 @@ class DashHistory @Inject constructor(
commandType = commandType,
tempBasalRecord = tempBasalRecord,
bolusRecord = bolusRecord,
+ basalProfileRecord = basalProfileRecord,
initialResult = initialResult,
resolvedResult = resolveResult,
resolvedAt = resolvedAt
@@ -83,7 +79,8 @@ class DashHistory @Inject constructor(
fun getRecords(): Single> =
dao.all().map { list -> list.map(historyMapper::entityToDomain) }
- fun getRecordsAfter(time: Long): Single> = dao.allSince(time)
+ fun getRecordsAfter(time: Long): Single> =
+ dao.allSince(time).map { list -> list.map(historyMapper::entityToDomain) }
fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer {
val historyId = podState.activeCommand?.historyId
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt
index f7510c40b1..baef277087 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt
@@ -18,4 +18,12 @@ data class HistoryRecord(
val entropy = ULID.getEntropy(id)
return ByteBuffer.wrap(entropy).long
}
+
+ fun displayTimestamp(): Long {
+ return date
+ }
+
+ fun isSuccess(): Boolean {
+ return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS
+ }
}
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt
index c5ea0ab4b3..f129ab292d 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt
@@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data
import info.nightscout.androidaps.data.DetailedBolusInfo
+import info.nightscout.androidaps.interfaces.Profile
sealed class Record
@@ -8,6 +9,8 @@ data class BolusRecord(val amout: Double, val bolusType: BolusType) : Record()
data class TempBasalRecord(val duration: Int, val rate: Double) : Record()
+data class BasalValuesRecord(val segments: List) : Record()
+
enum class BolusType {
DEFAULT, SMB;
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt
index ee92d9ed78..676ba33168 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt
@@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data
enum class InitialResult {
- NOT_SENT, FAILURE_SENDING, UNCONFIRMED, SENT
+ NOT_SENT, FAILURE_SENDING, SENT
}
enum class ResolvedResult {
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt
index 8d21ea751a..5f90d9b7c8 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt
@@ -1,6 +1,8 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database
import androidx.room.TypeConverter
+import com.google.gson.GsonBuilder
+import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
@@ -31,4 +33,17 @@ class Converters {
@TypeConverter
fun fromOmnipodCommandType(omnipodCommandType: OmnipodCommandType) = omnipodCommandType.name
+
+ @TypeConverter
+ fun toSegments(s: String?): List {
+ s ?: return emptyList()
+ val gson = GsonBuilder().create()
+ return gson.fromJson(s, Array::class.java).toList()
+ }
+
+ @TypeConverter
+ fun fromBasalValues(segments: List): String {
+ val gson = GsonBuilder().create()
+ return gson.toJson(segments)
+ }
}
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt
index 3014f3eba0..993d49d564 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt
@@ -18,13 +18,13 @@ abstract class DashHistoryDatabase : RoomDatabase() {
companion object {
- const val VERSION = 1
+ const val VERSION = 2
fun build(context: Context) =
Room.databaseBuilder(
context.applicationContext,
DashHistoryDatabase::class.java,
- "omnipod_dash_history_database.db"
+ "omnipod_dash_history_database.db",
)
.fallbackToDestructiveMigration()
.build()
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt
index a91a838d1d..1beaab6bca 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt
@@ -19,7 +19,7 @@ abstract class HistoryRecordDao {
@Query("SELECT * from historyrecords")
abstract fun allBlocking(): List
- @Query("SELECT * from historyrecords WHERE createdAt >= :since")
+ @Query("SELECT * from historyrecords WHERE createdAt >= :since ORDER BY createdAt DESC")
abstract fun allSince(since: Long): Single>
@Query("SELECT * FROM historyrecords WHERE id = :id LIMIT 1")
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt
index 18ff9c14d2..c135e24cd5 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt
@@ -4,6 +4,7 @@ import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
@@ -18,6 +19,7 @@ data class HistoryRecordEntity(
val initialResult: InitialResult,
@Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?,
@Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?,
+ @Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?,
val resolvedResult: ResolvedResult?,
val resolvedAt: Long?
)
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt
index 5266924514..765c538ee6 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt
@@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
@@ -17,7 +18,8 @@ class HistoryMapper {
tempBasalRecord = historyRecord.record as? TempBasalRecord,
bolusRecord = historyRecord.record as? BolusRecord,
resolvedResult = historyRecord.resolvedResult,
- resolvedAt = historyRecord.resolvedAt
+ resolvedAt = historyRecord.resolvedAt,
+ basalProfileRecord = historyRecord.record as? BasalValuesRecord
)
fun entityToDomain(entity: HistoryRecordEntity): HistoryRecord =
@@ -27,7 +29,7 @@ class HistoryMapper {
date = entity.date,
initialResult = entity.initialResult,
commandType = entity.commandType,
- record = entity.bolusRecord ?: entity.tempBasalRecord,
+ record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord,
resolvedResult = entity.resolvedResult,
resolvedAt = entity.resolvedAt
)
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt
new file mode 100644
index 0000000000..fba505ffaa
--- /dev/null
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt
@@ -0,0 +1,279 @@
+package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui
+// import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType;
+// import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil;
+import android.os.Bundle
+import android.os.SystemClock
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.AdapterView
+import android.widget.ArrayAdapter
+import android.widget.Spinner
+import android.widget.TextView
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
+import info.nightscout.androidaps.logging.AAPSLogger
+import info.nightscout.androidaps.logging.LTag
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
+import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
+import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil
+import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.*
+import info.nightscout.androidaps.utils.rx.AapsSchedulers
+import java.util.*
+import javax.inject.Inject
+
+class DashPodHistoryActivity : NoSplashAppCompatActivity() {
+
+ @Inject lateinit var aapsLogger: AAPSLogger
+ @Inject lateinit var dashHistory: DashHistory
+ @Inject lateinit var aapsSchedulers: AapsSchedulers
+
+ private var historyTypeSpinner: Spinner? = null
+ private var statusView: TextView? = null
+ private var recyclerView: RecyclerView? = null
+ private var linearLayoutManager: LinearLayoutManager? = null
+ private val fullHistoryList: MutableList = ArrayList()
+ private val filteredHistoryList: MutableList = ArrayList()
+ private var recyclerViewAdapter: RecyclerViewAdapter? = null
+ private var manualChange = false
+ private var typeListFull: List? = null
+
+ private fun prepareData() {
+ val gc = GregorianCalendar()
+ gc.add(Calendar.DAY_OF_MONTH, -DAYS_TO_DISPLAY)
+
+ val since = gc.timeInMillis
+ val records = dashHistory.getRecordsAfter(since)
+ .subscribeOn(aapsSchedulers.io)
+ .blockingGet()
+ fullHistoryList.addAll(records)
+ }
+
+ private fun groupForCommandType(type: OmnipodCommandType): PumpHistoryEntryGroup {
+ return when (type) {
+ OmnipodCommandType.INITIALIZE_POD ->
+ PumpHistoryEntryGroup.Prime
+ OmnipodCommandType.INSERT_CANNULA ->
+ PumpHistoryEntryGroup.Prime
+ OmnipodCommandType.DEACTIVATE_POD ->
+ PumpHistoryEntryGroup.Prime
+ OmnipodCommandType.DISCARD_POD ->
+ PumpHistoryEntryGroup.Prime
+
+ OmnipodCommandType.CANCEL_TEMPORARY_BASAL ->
+ PumpHistoryEntryGroup.Basal
+ OmnipodCommandType.SET_BASAL_PROFILE ->
+ PumpHistoryEntryGroup.Basal
+ OmnipodCommandType.SET_TEMPORARY_BASAL ->
+ PumpHistoryEntryGroup.Basal
+ OmnipodCommandType.RESUME_DELIVERY ->
+ PumpHistoryEntryGroup.Basal
+ OmnipodCommandType.SUSPEND_DELIVERY ->
+ PumpHistoryEntryGroup.Basal
+
+ OmnipodCommandType.SET_BOLUS ->
+ PumpHistoryEntryGroup.Bolus
+ OmnipodCommandType.CANCEL_BOLUS ->
+ PumpHistoryEntryGroup.Bolus
+
+ OmnipodCommandType.ACKNOWLEDGE_ALERTS ->
+ PumpHistoryEntryGroup.Alarm
+ OmnipodCommandType.CONFIGURE_ALERTS ->
+ PumpHistoryEntryGroup.Alarm
+ OmnipodCommandType.PLAY_TEST_BEEP ->
+ PumpHistoryEntryGroup.Alarm
+
+ OmnipodCommandType.GET_POD_STATUS ->
+ PumpHistoryEntryGroup.Configuration
+ OmnipodCommandType.SET_TIME ->
+ PumpHistoryEntryGroup.Configuration
+
+ OmnipodCommandType.READ_POD_PULSE_LOG ->
+ PumpHistoryEntryGroup.Unknown
+ }
+ }
+ private fun filterHistory(group: PumpHistoryEntryGroup) {
+ filteredHistoryList.clear()
+ aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size)
+ if (group === PumpHistoryEntryGroup.All) {
+ filteredHistoryList.addAll(fullHistoryList)
+ } else {
+ filteredHistoryList.addAll(fullHistoryList.filter { groupForCommandType(it.commandType) == group })
+ }
+ recyclerViewAdapter?.let {
+ it.historyList = filteredHistoryList
+ it.notifyDataSetChanged()
+ }
+ aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ filterHistory(selectedGroup)
+ setHistoryTypeSpinner()
+ }
+
+ private fun setHistoryTypeSpinner() {
+ manualChange = true
+ val typeList = typeListFull
+ typeList?.let {
+ for (i in it.indices) {
+ if (it[i].entryGroup === selectedGroup) {
+ historyTypeSpinner!!.setSelection(i)
+ break
+ }
+ }
+ }
+ SystemClock.sleep(200)
+ manualChange = false
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ setContentView(R.layout.omnipod_dash_pod_history_activity)
+ prepareData()
+
+ recyclerView = findViewById(R.id.omnipod_history_recyclerview)
+ recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList)
+ linearLayoutManager = LinearLayoutManager(this)
+ recyclerView?.run {
+ setHasFixedSize(true)
+ layoutManager = linearLayoutManager
+ adapter = recyclerViewAdapter
+ }
+
+ statusView = findViewById(R.id.omnipod_historystatus)
+ statusView?.run { visibility = View.GONE }
+
+ historyTypeSpinner = findViewById(R.id.omnipod_historytype)
+ typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper))
+ val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!)
+ historyTypeSpinner?.run {
+ adapter = spinnerAdapter
+ onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+ override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
+ if (manualChange) return
+ val selected = selectedItem as TypeList
+ selectedGroup = selected.entryGroup
+ filterHistory(selectedGroup)
+ }
+
+ override fun onNothingSelected(parent: AdapterView<*>?) {
+ if (manualChange) return
+ filterHistory(PumpHistoryEntryGroup.All)
+ }
+ }
+ }
+ }
+
+ private fun getTypeList(list: List): List {
+ val typeList = ArrayList()
+ for (pumpHistoryEntryGroup in list) {
+ typeList.add(TypeList(pumpHistoryEntryGroup))
+ }
+ return typeList
+ }
+
+ internal class TypeList(entryGroup: PumpHistoryEntryGroup) {
+
+ val entryGroup: PumpHistoryEntryGroup = entryGroup
+ val name: String = entryGroup.translated ?: "XXX TODO"
+
+ override fun toString(): String {
+ return name
+ }
+ }
+
+ inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() {
+
+ var historyList: List = historyList
+
+ override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder {
+ val v: View = LayoutInflater.from(viewGroup.context).inflate(
+ R.layout.omnipod_dash_pod_history_item,
+ viewGroup, false
+ )
+ return HistoryViewHolder(v)
+ }
+
+ override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) {
+ val record: HistoryRecord = historyList[position]
+ record?.let {
+ holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(it.displayTimestamp())
+ setValue(it, holder.valueView)
+ setType(it, holder.typeView)
+ }
+ }
+
+ private fun setType(record: HistoryRecord, typeView: TextView) {
+ typeView.text = resourceHelper.gs(record.commandType.resourceId)
+ }
+
+ private fun setValue(historyEntry: HistoryRecord, valueView: TextView) {
+ valueView.text = historyEntry.toString()
+ // val entryType = historyEntry.commandType
+ if (!historyEntry.isSuccess()) {
+ valueView.text = resourceHelper.gs(translatedFailure(historyEntry))
+ return
+ }
+ valueView.text = when (historyEntry.commandType) {
+ OmnipodCommandType.SET_TEMPORARY_BASAL -> {
+ val tbr = historyEntry.record as TempBasalRecord
+ tbr?.let {
+ resourceHelper.gs(R.string.omnipod_common_history_tbr_value, it.rate, it.duration)
+ } ?: "n/a"
+ }
+ OmnipodCommandType.SET_BOLUS -> {
+ val bolus = historyEntry.record as BolusRecord
+ bolus?.let {
+ resourceHelper.gs(R.string.omnipod_common_history_bolus_value, it.amout)
+ } ?: "n/a"
+ }
+ OmnipodCommandType.SET_BASAL_PROFILE,
+ OmnipodCommandType.SET_TIME,
+ OmnipodCommandType.INSERT_CANNULA,
+ OmnipodCommandType.RESUME_DELIVERY -> {
+ val basal = historyEntry.record as BasalValuesRecord
+ ProfileUtil.getBasalProfilesDisplayable(basal.segments.toTypedArray(), PumpType.OMNIPOD_DASH)
+ }
+ else ->
+ ""
+ }
+ }
+
+ override fun getItemCount(): Int {
+ return historyList.size
+ }
+
+ inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time)
+ val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source)
+ val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description)
+ }
+ }
+
+ private fun translatedFailure(historyEntry: HistoryRecord): Int {
+ return when {
+ historyEntry.initialResult == InitialResult.FAILURE_SENDING ->
+ R.string.omnipod_dash_failed_to_send
+ historyEntry.initialResult == InitialResult.NOT_SENT ->
+ R.string.omnipod_dash_command_not_sent
+ historyEntry.initialResult == InitialResult.SENT &&
+ historyEntry.resolvedResult == ResolvedResult.FAILURE ->
+ R.string.omnipod_dash_command_not_received_by_the_pod
+ else ->
+ R.string.omnipod_dash_unknown
+ }
+ }
+
+ companion object {
+ private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All
+ const val DAYS_TO_DISPLAY = 5
+ }
+}
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt
index 9ac1a1ec3f..c2bb6240ea 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt
@@ -96,6 +96,10 @@ class DashPodManagementActivity : NoSplashAppCompatActivity() {
}
)
}
+
+ binding.buttonPodHistory.setOnClickListener {
+ startActivity(Intent(this, DashPodHistoryActivity::class.java))
+ }
}
override fun onResume() {
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt
index 715387abeb..dc0a36d920 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt
@@ -5,11 +5,15 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
+import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@@ -24,7 +28,9 @@ class DashInitializePodViewModel @Inject constructor(
logger: AAPSLogger,
private val sp: SP,
private val podStateManager: OmnipodDashPodStateManager,
- private val resourceHelper: ResourceHelper
+ private val resourceHelper: ResourceHelper,
+ private val history: DashHistory,
+
) : InitializePodViewModel(injector, logger) {
override fun isPodInAlarm(): Boolean = false // TODO
@@ -41,27 +47,31 @@ class DashInitializePodViewModel @Inject constructor(
} else
null
- super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
- onNext = { podEvent ->
- logger.debug(
- LTag.PUMP,
- "Received PodEvent in Pod activation part 1: $podEvent"
- )
- },
- onError = { throwable ->
- logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable)
- source.onSuccess(
- PumpEnactResult(injector)
- .success(false)
- .comment(I8n.textFromException(throwable, resourceHelper))
- )
- },
- onComplete = {
- logger.debug("Pod activation part 1 completed")
- podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits)
- source.onSuccess(PumpEnactResult(injector).success(true))
- }
- )
+ super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger)
+ .ignoreElements()
+ .andThen(podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits))
+ .andThen(
+ history.createRecord(
+ OmnipodCommandType.INITIALIZE_POD,
+ initialResult = InitialResult.SENT,
+ resolveResult = ResolvedResult.SUCCESS,
+ resolvedAt = System.currentTimeMillis(),
+ ).ignoreElement()
+ )
+ .subscribeBy(
+ onError = { throwable ->
+ logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable)
+ source.onSuccess(
+ PumpEnactResult(injector)
+ .success(false)
+ .comment(I8n.textFromException(throwable, resourceHelper))
+ )
+ },
+ onComplete = {
+ logger.debug("Pod activation part 1 completed")
+ source.onSuccess(PumpEnactResult(injector).success(true))
+ }
+ )
}
@StringRes
diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt
index 2e3e979f8e..8ba1aa41ab 100644
--- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt
+++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt
@@ -12,10 +12,15 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
+import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
+import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
@@ -36,6 +41,7 @@ class DashInsertCannulaViewModel @Inject constructor(
private val sp: SP,
private val resourceHelper: ResourceHelper,
private val fabricPrivacy: FabricPrivacy,
+ private val history: DashHistory,
injector: HasAndroidInjector,
logger: AAPSLogger
@@ -69,6 +75,15 @@ class DashInsertCannulaViewModel @Inject constructor(
super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown)
.ignoreElements()
.andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours))
+ .andThen(
+ history.createRecord(
+ OmnipodCommandType.INSERT_CANNULA,
+ basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList()),
+ initialResult = InitialResult.SENT,
+ resolveResult = ResolvedResult.SUCCESS,
+ resolvedAt = System.currentTimeMillis(),
+ ).ignoreElement()
+ )
.subscribeBy(
onError = { throwable ->
logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable)
@@ -100,7 +115,6 @@ class DashInsertCannulaViewModel @Inject constructor(
pumpType = PumpType.OMNIPOD_DASH,
pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a"
)
-
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED))
fabricPrivacy.logCustom("OmnipodDashPodActivated")
source.onSuccess(PumpEnactResult(injector).success(true))
diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml
new file mode 100644
index 0000000000..be8a49d07a
--- /dev/null
+++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml
new file mode 100644
index 0000000000..93b4bee75a
--- /dev/null
+++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml
index 4ea9533d45..c9d97e870c 100644
--- a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml
+++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml
@@ -111,6 +111,20 @@
app:layout_constraintRight_toLeftOf="@+id/Actions_Col_1_Row_2_vertical_guideline"
app:layout_constraintTop_toTopOf="parent" />
+
+
AAPS.OmnipodDash.pod_state
+
+ Pod History
+ Description
+ Source
+ Date
+ Type:
+ %1$.2f U
+ %1$.2f U, CH=%2$.1f g
+ Rate: %1$.2f U, duration: %2$d minutes
+
Bluetooth Status
Bluetooth Address
@@ -30,4 +40,10 @@
Found too many pods for activation
Could not find an available pod for activation
Generic error: %1$s
+ Failed to send the command
+ Command not sent
+ Command not received by the pod
+ Unknown state for the command
+ Rate: %1$.2f U, duration: %2$d minutes
+ %1$.2f U
diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt
index 8997e02482..f5100096dc 100644
--- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt
+++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt
@@ -25,8 +25,9 @@ object ProfileUtil {
val basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value)
val hour = basalValue.timeAsSeconds / (60 * 60)
stringBuilder.append((if (hour < 10) "0" else "") + hour + ":00")
+ stringBuilder.append(" ")
stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValueValue))
- stringBuilder.append(", ")
+ stringBuilder.append(",\n")
}
return if (stringBuilder.length > 3) stringBuilder.substring(0, stringBuilder.length - 2) else stringBuilder.toString()
}