Add lastConnection and expiry to overview
This commit is contained in:
parent
7b53630947
commit
c0138ffad8
4 changed files with 68 additions and 33 deletions
|
@ -132,16 +132,23 @@ class MedtrumPump @Inject constructor(
|
|||
sp.putString(R.string.key_actual_basal_profile, encodedString ?: "")
|
||||
}
|
||||
|
||||
private var _lastConnection = 0L // Time in ms!
|
||||
var lastConnection: Long
|
||||
get() = _lastConnection
|
||||
set(value) {
|
||||
_lastConnection = value
|
||||
sp.putLong(R.string.key_last_connection, value)
|
||||
}
|
||||
|
||||
private var _pumpSN = 0L
|
||||
val pumpSN: Long
|
||||
get() = _pumpSN
|
||||
|
||||
val pumpType: PumpType = PumpType.MEDTRUM_NANO // TODO, type based on pumpSN or pump activation/connection
|
||||
|
||||
var lastConnection = 0L // Time in ms!
|
||||
var lastTimeReceivedFromPump = 0L // Time in ms! // TODO: Consider removing as is not used?
|
||||
var suspendTime = 0L // Time in ms!
|
||||
var patchStartTime = 0L // Time in ms!
|
||||
var patchStartTime = 0L // Time in ms! // TODO: save in SP
|
||||
var patchAge = 0L // Time in seconds?! // TODO: Not used
|
||||
|
||||
var batteryVoltage_A = 0.0
|
||||
|
@ -186,6 +193,7 @@ class MedtrumPump @Inject constructor(
|
|||
init {
|
||||
// Load stuff from SP
|
||||
_patchSessionToken = sp.getLong(R.string.key_session_token, 0L)
|
||||
_lastConnection = sp.getLong(R.string.key_last_connection, 0L)
|
||||
_currentSequenceNumber = sp.getInt(R.string.key_current_sequence_number, 0)
|
||||
_patchId = sp.getLong(R.string.key_patch_id, 0L)
|
||||
_syncedSequenceNumber = sp.getInt(R.string.key_synced_sequence_number, 0)
|
||||
|
|
|
@ -1,27 +1,21 @@
|
|||
package info.nightscout.pump.medtrum.ui.viewmodel
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.pump.medtrum.code.EventType
|
||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
|
||||
import info.nightscout.pump.medtrum.ui.event.SingleLiveEvent
|
||||
import info.nightscout.pump.medtrum.ui.event.UIEvent
|
||||
import info.nightscout.pump.medtrum.ui.viewmodel.BaseViewModel
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
import info.nightscout.interfaces.queue.CommandQueue
|
||||
import info.nightscout.pump.medtrum.MedtrumPump
|
||||
import info.nightscout.pump.medtrum.R
|
||||
import info.nightscout.pump.medtrum.code.ConnectionState
|
||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.EventPumpStatusChanged
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.shared.utils.T
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
|
@ -31,11 +25,9 @@ import javax.inject.Inject
|
|||
class MedtrumOverviewViewModel @Inject constructor(
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val rh: ResourceHelper,
|
||||
private val rxBus: RxBus,
|
||||
private val aapsSchedulers: AapsSchedulers,
|
||||
private val fabricPrivacy: FabricPrivacy,
|
||||
private val profileFunction: ProfileFunction,
|
||||
private val commandQueue: CommandQueue,
|
||||
private val dateUtil: DateUtil,
|
||||
val medtrumPump: MedtrumPump
|
||||
) : BaseViewModel<MedtrumBaseNavigator>() {
|
||||
|
||||
|
@ -57,9 +49,9 @@ class MedtrumOverviewViewModel @Inject constructor(
|
|||
val bleStatus: LiveData<String>
|
||||
get() = _bleStatus
|
||||
|
||||
private val _lastConnected = SingleLiveEvent<String>()
|
||||
val lastConnected: LiveData<String>
|
||||
get() = _lastConnected
|
||||
private val _lastConnectionMinAgo = SingleLiveEvent<String>()
|
||||
val lastConnectionMinAgo: LiveData<String>
|
||||
get() = _lastConnectionMinAgo
|
||||
|
||||
private val _activeAlarms = SingleLiveEvent<String>()
|
||||
val activeAlarms: LiveData<String>
|
||||
|
@ -105,6 +97,7 @@ class MedtrumOverviewViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
updateGUI()
|
||||
}
|
||||
}
|
||||
scope.launch {
|
||||
|
@ -115,6 +108,14 @@ class MedtrumOverviewViewModel @Inject constructor(
|
|||
} else {
|
||||
_canDoResetAlarms.postValue(false)
|
||||
}
|
||||
updateGUI()
|
||||
}
|
||||
}
|
||||
// Periodically update gui
|
||||
scope.launch {
|
||||
while (true) {
|
||||
updateGUI()
|
||||
kotlinx.coroutines.delay(T.mins(1).msecs())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,5 +142,25 @@ class MedtrumOverviewViewModel @Inject constructor(
|
|||
_eventHandler.postValue(UIEvent(EventType.CHANGE_PATCH_CLICKED))
|
||||
}
|
||||
}
|
||||
|
||||
fun updateGUI() {
|
||||
// Update less dynamic values
|
||||
val agoMilliseconds = System.currentTimeMillis() - medtrumPump.lastConnection
|
||||
val agoMinutes = agoMilliseconds / 1000 / 60
|
||||
_lastConnectionMinAgo.postValue(rh.gs(info.nightscout.shared.R.string.minago, agoMinutes))
|
||||
|
||||
// TODO: Update these values
|
||||
// _activeAlarms.postValue(rh.gs(R.string.active_alarms, pump.activeAlarms))
|
||||
// _pumpType.postValue(rh.gs(R.string.pump_type, pump.pumpType))
|
||||
// _fwVersion.postValue(rh.gs(R.string.fw_version, pump.fwVersion))
|
||||
// _patchNo.postValue(rh.gs(R.string.patch_no, pump.patchNo))
|
||||
|
||||
if (medtrumPump.desiredPatchExpiration) {
|
||||
val expiry = medtrumPump.patchStartTime + T.hours(84).msecs()
|
||||
_patchExpiry.postValue(dateUtil.dateAndTimeString(expiry))
|
||||
} else {
|
||||
_patchExpiry.postValue(rh.gs(R.string.expiry_not_enabled))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="viewmodel"
|
||||
type="info.nightscout.pump.medtrum.ui.viewmodel.MedtrumOverviewViewModel" />
|
||||
|
@ -82,7 +81,7 @@
|
|||
android:gravity="end"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text="@string/last_connected_label"
|
||||
android:text="@string/last_connection_label"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
|
@ -96,14 +95,14 @@
|
|||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/last_connected"
|
||||
android:id="@+id/last_connection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text="@{viewmodel.lastConnected}"
|
||||
android:text="@{viewmodel.lastConnectionMinAgo}"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
@ -111,9 +110,11 @@
|
|||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:background="@color/list_delimiter" />
|
||||
android:background="?android:attr/dividerHorizontal" />
|
||||
|
||||
<!-- Pump State -->
|
||||
<LinearLayout
|
||||
|
@ -319,9 +320,11 @@
|
|||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:background="@color/list_delimiter" />
|
||||
android:background="?android:attr/dividerHorizontal" />
|
||||
|
||||
<!-- PumpType -->
|
||||
<LinearLayout
|
||||
|
@ -485,16 +488,17 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:background="?android:attr/dividerHorizontal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:background="@color/list_delimiter" />
|
||||
|
||||
<!-- Add other fields here as needed, like the ones above -->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
<string name="key_medtrumpump_settings" translatable="false">medtrumpump_settings</string>
|
||||
<string name="key_pump_state" translatable="false">pump_state</string>
|
||||
<string name="key_last_connection" translatable="false">last_connection</string>
|
||||
<string name="key_session_token" translatable="false">medtrum_session_token</string>
|
||||
<string name="key_patch_id" translatable="false">patch_id</string>
|
||||
<string name="key_actual_basal_profile" translatable="false">actual_basal_profile</string>
|
||||
|
@ -28,7 +29,7 @@
|
|||
|
||||
<!-- overview fragment -->
|
||||
<string name="ble_status_label">BLE Status</string>
|
||||
<string name="last_connected_label">Last connected</string>
|
||||
<string name="last_connection_label">Last connected</string>
|
||||
<string name="pump_state_label">Pump state</string>
|
||||
<string name="active_alarms_label">Active alarms</string>
|
||||
<string name="reservoir_label"> Reservoir</string>
|
||||
|
@ -44,6 +45,7 @@
|
|||
<string name="reset_alarms_label">Reset alarms</string>
|
||||
<string name="change_patch_label">Change patch</string>
|
||||
<string name="requested_by_user" comment="26 characters max for translation">Requested by user</string>
|
||||
<string name="expiry_not_enabled">Not enabled</string>
|
||||
|
||||
<!-- wizard-->
|
||||
<string name="string_change_patch">Discard/Change Patch</string> <!-- TODO check-->
|
||||
|
@ -66,7 +68,7 @@
|
|||
<string name="alarm_setting_title">Alarm Settings</string>
|
||||
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
|
||||
<string name="patch_expiration_title">Patch Expiration</string>
|
||||
<string name="patch_expiration_summary">Turn this on to get an alert 12 hours before the patch expiration. When enabled, the patch will expire after 3 days.</string>
|
||||
<string name="patch_expiration_summary">Turn this on to get an alert 12 hours before the patch expiration. When enabled, the patch will expire after 3.5 days.</string>
|
||||
<string name="hourly_max_insulin_title">Hourly Maximum Insulin</string>
|
||||
<string name="hourly_max_insulin_summary">Specify the maximum units of insulin allowed per hour. If exceeded, the pump will suspend.</string>
|
||||
<string name="daily_max_insulin_title">Daily Maximum Insulin</string>
|
||||
|
|
Loading…
Reference in a new issue