MedtronicFragment -> jetpack

This commit is contained in:
Milos Kozak 2021-02-03 23:02:14 +01:00
parent 0054fce4d9
commit ee6cd22d24
8 changed files with 582 additions and 582 deletions

View file

@ -504,7 +504,7 @@
android:drawableTop="@drawable/ic_actions_refill"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:text="@string/combo_refresh" />
android:text="@string/refresh" />
</LinearLayout>
</LinearLayout>

View file

@ -649,7 +649,6 @@
<string name="maxiobset">Maximal IOB set properly</string>
<string name="hasbgdata">BG available from selected source</string>
<string name="combo_programming_bolus">Programming pump for bolusing</string>
<string name="combo_refresh">Refresh</string>
<string name="combo_pump_state_label">State</string>
<string name="combo_pump_activity_label">Activity</string>
<string name="combo_no_pump_connection">No connection for %1$d min</string>
@ -1000,7 +999,6 @@
<string name="eb_formatter">%1$.2f / %2$.2f U for %3$d min</string>
<string name="enable_tbr_over_notification">Enable notification of TBR end\n(pump setting)</string>
<string name="disable_tbr_over_notification">Disable notification of TBR end\n(pump setting)</string>
<string name="refresh">Refresh</string>
<string name="description_pump_insight_local">Pump integration for Accu-Chek Insight pumps</string>
<string name="not_inserted">Not inserted</string>
<string name="short_status_last_connected">Last conn: %1$d min ago</string>

View file

@ -31,6 +31,7 @@
<string name="key_quickwizard" translatable="false">QuickWizard</string>
<!-- General-->
<string name="refresh">Refresh</string>
<string name="error">Error</string>
<string name="not_set_short">Not set</string>
<string name="failedupdatebasalprofile">Failed to update basal profile</string>

View file

@ -1,6 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
@ -19,6 +18,9 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
buildTypes {
release {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.medtronic
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
@ -17,19 +18,20 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType
import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.common.events.EventRefreshButtonState
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData
import info.nightscout.androidaps.plugins.pump.medtronic.databinding.MedtronicFragmentBinding
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType
import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.events.EventQueueChanged
@ -42,10 +44,10 @@ import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.medtronic_fragment.*
import javax.inject.Inject
class MedtronicFragment : DaggerFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var resourceHelper: ResourceHelper
@ -71,21 +73,27 @@ class MedtronicFragment : DaggerFragment() {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.medtronic_fragment, container, false)
}
private var _binding: MedtronicFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
MedtronicFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
medtronic_pumpstatus.setBackgroundColor(resourceHelper.gc(R.color.colorInitializingBorder))
binding.pumpStatus.setBackgroundColor(resourceHelper.gc(R.color.colorInitializingBorder))
medtronic_rl_status.text = resourceHelper.gs(RileyLinkServiceState.NotStarted.resourceId)
binding.rlStatus.text = resourceHelper.gs(RileyLinkServiceState.NotStarted.resourceId)
medtronic_pump_status.setTextColor(Color.WHITE)
medtronic_pump_status.text = "{fa-bed}"
binding.pumpStatusIcon.setTextColor(Color.WHITE)
@SuppressLint("SetTextI18n")
binding.pumpStatusIcon.text = "{fa-bed}"
medtronic_history.setOnClickListener {
binding.history.setOnClickListener {
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
} else {
@ -93,21 +101,21 @@ class MedtronicFragment : DaggerFragment() {
}
}
medtronic_refresh.setOnClickListener {
binding.refresh.setOnClickListener {
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() != true) {
displayNotConfiguredDialog()
} else {
medtronic_refresh.isEnabled = false
binding.refresh.isEnabled = false
medtronicPumpPlugin.resetStatusState()
commandQueue.readStatus("Clicked refresh", object : Callback() {
override fun run() {
activity?.runOnUiThread { medtronic_refresh?.isEnabled = true }
activity?.runOnUiThread { if (_binding != null) binding.refresh.isEnabled = true }
}
})
}
}
medtronic_stats.setOnClickListener {
binding.stats.setOnClickListener {
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
} else {
@ -123,7 +131,7 @@ class MedtronicFragment : DaggerFragment() {
disposable += rxBus
.toObservable(EventRefreshButtonState::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ medtronic_refresh.isEnabled = it.newState }, { fabricPrivacy.logException(it) })
.subscribe({ binding.refresh.isEnabled = it.newState }, { fabricPrivacy.logException(it) })
disposable += rxBus
.toObservable(EventRileyLinkDeviceStatusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
@ -170,63 +178,70 @@ class MedtronicFragment : DaggerFragment() {
loopHandler.removeCallbacks(refreshLoop)
}
@Synchronized
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
@SuppressLint("SetTextI18n")
@Synchronized
private fun setDeviceStatus() {
val resourceId = rileyLinkServiceData.rileyLinkServiceState.resourceId
val rileyLinkError = medtronicPumpPlugin.rileyLinkService?.error
medtronic_rl_status.text =
binding.rlStatus.text =
when {
rileyLinkServiceData.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
}
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
binding.rlStatus.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
medtronic_errors.text =
binding.errors.text =
rileyLinkServiceData.rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump))
} ?: "-"
when (medtronicPumpStatus.pumpDeviceState) {
null,
PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
PumpDeviceState.Sleeping -> binding.pumpStatusIcon.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
PumpDeviceState.NeverContacted,
PumpDeviceState.WakingUp,
PumpDeviceState.PumpUnreachable,
PumpDeviceState.ErrorWhenCommunicating,
PumpDeviceState.TimeoutWhenCommunicating,
PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
PumpDeviceState.InvalidConfiguration -> binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
PumpDeviceState.Active -> {
PumpDeviceState.Active -> {
val cmd = medtronicUtil.currentCommand
if (cmd == null)
medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
else {
aapsLogger.debug(LTag.PUMP, "Command: " + cmd)
aapsLogger.debug(LTag.PUMP, "Command: $cmd")
val cmdResourceId = cmd.resourceId
if (cmd == MedtronicCommandType.GetHistoryData) {
medtronic_pump_status.text = medtronicUtil.frameNumber?.let {
binding.pumpStatusIcon.text = medtronicUtil.frameNumber?.let {
resourceHelper.gs(cmdResourceId, medtronicUtil.pageNumber, medtronicUtil.frameNumber)
}
?: resourceHelper.gs(R.string.medtronic_cmd_desc_get_history_request, medtronicUtil.pageNumber)
} else {
medtronic_pump_status.text = " " + (cmdResourceId?.let { resourceHelper.gs(it) }
binding.pumpStatusIcon.text = " " + (cmdResourceId?.let { resourceHelper.gs(it) }
?: cmd.getCommandDescription())
}
}
}
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState)
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState)
}
val status = commandQueue.spannedStatus()
if (status.toString() == "") {
medtronic_queue.visibility = View.GONE
binding.queue.visibility = View.GONE
} else {
medtronic_queue.visibility = View.VISIBLE
medtronic_queue.text = status
binding.queue.visibility = View.VISIBLE
binding.queue.text = status
}
}
@ -238,9 +253,10 @@ class MedtronicFragment : DaggerFragment() {
}
// GUI functions
@SuppressLint("SetTextI18n")
@Synchronized
fun updateGUI() {
if (medtronic_rl_status == null) return
if (_binding == null) return
setDeviceStatus()
@ -249,27 +265,27 @@ class MedtronicFragment : DaggerFragment() {
val minAgo = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastConnection)
val min = (System.currentTimeMillis() - medtronicPumpStatus.lastConnection) / 1000 / 60
if (medtronicPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
medtronic_lastconnection.setText(R.string.medtronic_pump_connected_now)
medtronic_lastconnection.setTextColor(Color.WHITE)
binding.lastConnection.setText(R.string.medtronic_pump_connected_now)
binding.lastConnection.setTextColor(Color.WHITE)
} else if (medtronicPumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
if (min < 60) {
medtronic_lastconnection.text = resourceHelper.gs(R.string.minago, min)
binding.lastConnection.text = resourceHelper.gs(R.string.minago, min)
} else if (min < 1440) {
val h = (min / 60).toInt()
medtronic_lastconnection.text = (resourceHelper.gq(R.plurals.duration_hours, h, h) + " "
binding.lastConnection.text = (resourceHelper.gq(R.plurals.duration_hours, h, h) + " "
+ resourceHelper.gs(R.string.ago))
} else {
val h = (min / 60).toInt()
val d = h / 24
// h = h - (d * 24);
medtronic_lastconnection.text = (resourceHelper.gq(R.plurals.duration_days, d, d) + " "
binding.lastConnection.text = (resourceHelper.gq(R.plurals.duration_days, d, d) + " "
+ resourceHelper.gs(R.string.ago))
}
medtronic_lastconnection.setTextColor(Color.RED)
binding.lastConnection.setTextColor(Color.RED)
} else {
medtronic_lastconnection.text = minAgo
medtronic_lastconnection.setTextColor(Color.WHITE)
binding.lastConnection.text = minAgo
binding.lastConnection.setTextColor(Color.WHITE)
}
}
@ -280,39 +296,36 @@ class MedtronicFragment : DaggerFragment() {
val agoMsc = System.currentTimeMillis() - medtronicPumpStatus.lastBolusTime.time
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
val ago: String
if (agoMsc < 60 * 1000) {
ago = resourceHelper.gs(R.string.medtronic_pump_connected_now)
} else if (bolusMinAgo < 60) {
ago = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime.time)
} else {
ago = DateUtil.hourAgo(medtronicPumpStatus.lastBolusTime.time, resourceHelper)
val ago = when {
agoMsc < 60 * 1000 -> resourceHelper.gs(R.string.medtronic_pump_connected_now)
bolusMinAgo < 60 -> DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime.time)
else -> DateUtil.hourAgo(medtronicPumpStatus.lastBolusTime.time, resourceHelper)
}
medtronic_lastbolus.text = resourceHelper.gs(R.string.mdt_last_bolus, bolus, unit, ago)
binding.lastBolus.text = resourceHelper.gs(R.string.mdt_last_bolus, bolus, unit, ago)
} else {
medtronic_lastbolus.text = ""
binding.lastBolus.text = ""
}
// base basal rate
medtronic_basabasalrate.text = ("(" + medtronicPumpStatus.activeProfileName + ") "
binding.baseBasalRate.text = ("(" + medtronicPumpStatus.activeProfileName + ") "
+ resourceHelper.gs(R.string.pump_basebasalrate, medtronicPumpPlugin.baseBasalRate))
medtronic_tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
binding.tempBasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
?: ""
// battery
if (medtronicPumpStatus.batteryType == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
binding.pumpStateBattery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
} else {
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
binding.pumpStateBattery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
}
warnColors.setColorInverse(medtronic_pumpstate_battery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
warnColors.setColorInverse(binding.pumpStateBattery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
// reservoir
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
warnColors.setColorInverse(medtronic_reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
binding.reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
warnColors.setColorInverse(binding.reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
medtronicPumpPlugin.rileyLinkService?.verifyConfiguration()
medtronic_errors.text = medtronicPumpStatus.errorInfo
binding.errors.text = medtronicPumpStatus.errorInfo
}
}

File diff suppressed because it is too large Load diff

View file

@ -789,7 +789,7 @@
android:layout_weight="1"
android:drawableTop="@drawable/ic_omnipod_overview_refresh_pod_status"
android:drawablePadding="@dimen/omnipod_icon_button_drawable_padding"
android:text="@string/omnipod_overview_button_refresh" />
android:text="@string/refresh" />
<Button
android:id="@+id/omnipod_overview_button_pod_management"

View file

@ -244,7 +244,6 @@
<!-- Omnipod - Overview -->
<string name="omnipod_overview_button_set_time">Set time</string>
<string name="omnipod_overview_button_suspend_delivery">Suspend</string>
<string name="omnipod_overview_button_refresh">Refresh</string>
<string name="omnipod_overview_button_resume_delivery">Resume Delivery</string>
<string name="omnipod_overview_button_pod_management">Pod Mgmt</string>
<string name="omnipod_overview_button_acknowledge_active_alerts">Ack Alerts</string>