From ee6cd22d24424fd18f54820dbc06aae91b376620 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 3 Feb 2021 23:02:14 +0100 Subject: [PATCH] MedtronicFragment -> jetpack --- .../main/res/layout/combopump_fragment.xml | 2 +- app/src/main/res/values/strings.xml | 2 - core/src/main/res/values/strings.xml | 1 + medtronic/build.gradle | 4 +- .../pump/medtronic/MedtronicFragment.kt | 145 +-- .../main/res/layout/medtronic_fragment.xml | 1007 ++++++++--------- .../src/main/res/layout/omnipod_overview.xml | 2 +- omnipod/src/main/res/values/strings.xml | 1 - 8 files changed, 582 insertions(+), 582 deletions(-) diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index b96625fee5..8af1415688 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -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" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 406973b9fe..ac95477228 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -649,7 +649,6 @@ Maximal IOB set properly BG available from selected source Programming pump for bolusing - Refresh State Activity No connection for %1$d min @@ -1000,7 +999,6 @@ %1$.2f / %2$.2f U for %3$d min Enable notification of TBR end\n(pump setting) Disable notification of TBR end\n(pump setting) - Refresh Pump integration for Accu-Chek Insight pumps Not inserted Last conn: %1$d min ago diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 8a4d80bf2a..e42bd8e553 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -31,6 +31,7 @@ QuickWizard + Refresh Error Not set Failed to update basal profile diff --git a/medtronic/build.gradle b/medtronic/build.gradle index d45bced541..49e7df1c9b 100644 --- a/medtronic/build.gradle +++ b/medtronic/build.gradle @@ -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 { diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index cbea7e46ca..8dc971ff0d 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -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 } } diff --git a/medtronic/src/main/res/layout/medtronic_fragment.xml b/medtronic/src/main/res/layout/medtronic_fragment.xml index 83d3b9d683..a85dd40ad4 100644 --- a/medtronic/src/main/res/layout/medtronic_fragment.xml +++ b/medtronic/src/main/res/layout/medtronic_fragment.xml @@ -1,540 +1,527 @@ - - + android:layout_height="match_parent" + android:layout_above="@+id/buttons" + android:fillViewport="true"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + -