PodManagementActivity -> jetpack

This commit is contained in:
Milos Kozak 2021-02-03 23:29:03 +01:00
parent a401f49bce
commit 02d43f4e92
2 changed files with 55 additions and 52 deletions

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.R import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.databinding.OmnipodPodManagementBinding
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
@ -33,7 +34,6 @@ import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.ui.UIRunnable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.omnipod_pod_management.*
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -54,26 +54,29 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
private var disposables: CompositeDisposable = CompositeDisposable() private var disposables: CompositeDisposable = CompositeDisposable()
private lateinit var binding: OmnipodPodManagementBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.omnipod_pod_management) binding = OmnipodPodManagementBinding.inflate(layoutInflater)
setContentView(binding.root)
omnipod_pod_management_button_activate_pod.setOnClickListener { binding.buttonActivatePod.setOnClickListener {
startActivity(Intent(this, PodActivationWizardActivity::class.java)) startActivity(Intent(this, PodActivationWizardActivity::class.java))
} }
omnipod_pod_management_button_deactivate_pod.setOnClickListener { binding.buttonDeactivatePod.setOnClickListener {
startActivity(Intent(this, PodDeactivationWizardActivity::class.java)) startActivity(Intent(this, PodDeactivationWizardActivity::class.java))
} }
omnipod_pod_management_button_discard_pod.setOnClickListener { binding.buttonDiscardPod.setOnClickListener {
OKDialog.showConfirmation(this, OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.omnipod_pod_management_discard_pod_confirmation), Thread { resourceHelper.gs(R.string.omnipod_pod_management_discard_pod_confirmation), Thread {
aapsOmnipodManager.discardPodState() aapsOmnipodManager.discardPodState()
}) })
} }
omnipod_pod_management_button_rileylink_stats.setOnClickListener { binding.buttonRileylinkStats.setOnClickListener {
if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) { if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, RileyLinkStatusActivity::class.java)) startActivity(Intent(context, RileyLinkStatusActivity::class.java))
} else { } else {
@ -81,14 +84,14 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
} }
} }
omnipod_pod_management_button_reset_rileylink_config.setOnClickListener { binding.buttonResetRileylinkConfig.setOnClickListener {
// TODO improvement: properly disable button until task is finished // TODO improvement: properly disable button until task is finished
serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector)) serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector))
} }
omnipod_pod_management_button_play_test_beep.setOnClickListener { binding.buttonPlayTestBeep.setOnClickListener {
omnipod_pod_management_button_play_test_beep.isEnabled = false binding.buttonPlayTestBeep.isEnabled = false
omnipod_pod_management_button_play_test_beep.setText(R.string.omnipod_pod_management_button_playing_test_beep) binding.buttonPlayTestBeep.setText(R.string.omnipod_pod_management_button_playing_test_beep)
commandQueue.customCommand(CommandPlayTestBeep(BeepConfigType.BEEEP), object : Callback() { commandQueue.customCommand(CommandPlayTestBeep(BeepConfigType.BEEEP), object : Callback() {
override fun run() { override fun run() {
@ -99,9 +102,9 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}) })
} }
omnipod_pod_management_button_pulse_log.setOnClickListener { binding.buttonPulseLog.setOnClickListener {
omnipod_pod_management_button_pulse_log.isEnabled = false binding.buttonPulseLog.isEnabled = false
omnipod_pod_management_button_pulse_log.setText(R.string.omnipod_pod_management_button_reading_pulse_log) binding.buttonPulseLog.setText(R.string.omnipod_pod_management_button_reading_pulse_log)
commandQueue.customCommand(CommandReadPulseLog(), object : Callback() { commandQueue.customCommand(CommandReadPulseLog(), object : Callback() {
override fun run() { override fun run() {
@ -112,7 +115,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}) })
} }
omnipod_pod_management_button_pod_history.setOnClickListener { binding.buttonPodHistory.setOnClickListener {
startActivity(Intent(this, PodHistoryActivity::class.java)) startActivity(Intent(this, PodHistoryActivity::class.java))
} }
} }
@ -145,65 +148,65 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
// Otherwise, users should use the Deactivate Pod Wizard. In case proper deactivation fails, // Otherwise, users should use the Deactivate Pod Wizard. In case proper deactivation fails,
// they will get an option to discard the Pod state there // they will get an option to discard the Pod state there
val discardButtonEnabled = podStateManager.hasPodState() && !podStateManager.isPodInitialized val discardButtonEnabled = podStateManager.hasPodState() && !podStateManager.isPodInitialized
omnipod_pod_management_button_discard_pod.visibility = discardButtonEnabled.toVisibility() binding.buttonDiscardPod.visibility = discardButtonEnabled.toVisibility()
val pulseLogButtonEnabled = aapsOmnipodManager.isPulseLogButtonEnabled val pulseLogButtonEnabled = aapsOmnipodManager.isPulseLogButtonEnabled
omnipod_pod_management_button_pulse_log.visibility = pulseLogButtonEnabled.toVisibility() binding.buttonPulseLog.visibility = pulseLogButtonEnabled.toVisibility()
omnipod_pod_management_button_rileylink_stats.visibility = aapsOmnipodManager.isRileylinkStatsButtonEnabled.toVisibility() binding.buttonRileylinkStats.visibility = aapsOmnipodManager.isRileylinkStatsButtonEnabled.toVisibility()
omnipod_pod_management_waiting_for_rl_layout.visibility = (!rileyLinkServiceData.rileyLinkServiceState.isReady).toVisibility() binding.waitingForRlLayout.visibility = (!rileyLinkServiceData.rileyLinkServiceState.isReady).toVisibility()
if (rileyLinkServiceData.rileyLinkServiceState.isReady) { if (rileyLinkServiceData.rileyLinkServiceState.isReady) {
omnipod_pod_management_button_activate_pod.isEnabled = !podStateManager.isPodActivationCompleted binding.buttonActivatePod.isEnabled = !podStateManager.isPodActivationCompleted
omnipod_pod_management_button_deactivate_pod.isEnabled = podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED) binding.buttonDeactivatePod.isEnabled = podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)
if (podStateManager.isPodInitialized && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) { if (podStateManager.isPodInitialized && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) {
if (commandQueue.isCustomCommandInQueue(CommandPlayTestBeep::class.java)) { if (commandQueue.isCustomCommandInQueue(CommandPlayTestBeep::class.java)) {
omnipod_pod_management_button_play_test_beep.isEnabled = false binding.buttonPlayTestBeep.isEnabled = false
omnipod_pod_management_button_play_test_beep.setText(R.string.omnipod_pod_management_button_playing_test_beep) binding.buttonPlayTestBeep.setText(R.string.omnipod_pod_management_button_playing_test_beep)
} else { } else {
omnipod_pod_management_button_play_test_beep.isEnabled = true binding.buttonPlayTestBeep.isEnabled = true
omnipod_pod_management_button_play_test_beep.setText(R.string.omnipod_pod_management_button_play_test_beep) binding.buttonPlayTestBeep.setText(R.string.omnipod_pod_management_button_play_test_beep)
} }
} else { } else {
omnipod_pod_management_button_play_test_beep.isEnabled = false binding.buttonPlayTestBeep.isEnabled = false
omnipod_pod_management_button_play_test_beep.setText(R.string.omnipod_pod_management_button_play_test_beep) binding.buttonPlayTestBeep.setText(R.string.omnipod_pod_management_button_play_test_beep)
} }
if (discardButtonEnabled) { if (discardButtonEnabled) {
omnipod_pod_management_button_discard_pod.isEnabled = true binding.buttonDiscardPod.isEnabled = true
} }
if (pulseLogButtonEnabled) { if (pulseLogButtonEnabled) {
if (podStateManager.isPodActivationCompleted) { if (podStateManager.isPodActivationCompleted) {
if (commandQueue.isCustomCommandInQueue(CommandReadPulseLog::class.java)) { if (commandQueue.isCustomCommandInQueue(CommandReadPulseLog::class.java)) {
omnipod_pod_management_button_pulse_log.isEnabled = false binding.buttonPulseLog.isEnabled = false
omnipod_pod_management_button_pulse_log.setText(R.string.omnipod_pod_management_button_reading_pulse_log) binding.buttonPulseLog.setText(R.string.omnipod_pod_management_button_reading_pulse_log)
} else { } else {
omnipod_pod_management_button_pulse_log.isEnabled = true binding.buttonPulseLog.isEnabled = true
omnipod_pod_management_button_pulse_log.setText(R.string.omnipod_pod_management_button_read_pulse_log) binding.buttonPulseLog.setText(R.string.omnipod_pod_management_button_read_pulse_log)
} }
} else { } else {
omnipod_pod_management_button_pulse_log.isEnabled = false binding.buttonPulseLog.isEnabled = false
omnipod_pod_management_button_pulse_log.setText(R.string.omnipod_pod_management_button_read_pulse_log) binding.buttonPulseLog.setText(R.string.omnipod_pod_management_button_read_pulse_log)
} }
} }
} else { } else {
omnipod_pod_management_button_play_test_beep.setText(R.string.omnipod_pod_management_button_play_test_beep) binding.buttonPlayTestBeep.setText(R.string.omnipod_pod_management_button_play_test_beep)
omnipod_pod_management_button_activate_pod.isEnabled = false binding.buttonActivatePod.isEnabled = false
omnipod_pod_management_button_deactivate_pod.isEnabled = false binding.buttonDeactivatePod.isEnabled = false
omnipod_pod_management_button_play_test_beep.isEnabled = false binding.buttonPlayTestBeep.isEnabled = false
if (discardButtonEnabled) { if (discardButtonEnabled) {
omnipod_pod_management_button_discard_pod.isEnabled = false binding.buttonDiscardPod.isEnabled = false
} }
if (pulseLogButtonEnabled) { if (pulseLogButtonEnabled) {
omnipod_pod_management_button_pulse_log.isEnabled = false binding.buttonPulseLog.isEnabled = false
omnipod_pod_management_button_pulse_log.setText(R.string.omnipod_pod_management_button_read_pulse_log) binding.buttonPulseLog.setText(R.string.omnipod_pod_management_button_read_pulse_log)
} }
} }
} }
private fun displayErrorDialog(title: String, message: String, withSound: Boolean) { private fun displayErrorDialog(title: String, message: String, @Suppress("SameParameterValue") withSound: Boolean) {
context.let { context.let {
val i = Intent(it, ErrorHelperActivity::class.java) val i = Intent(it, ErrorHelperActivity::class.java)
i.putExtra("soundid", if (withSound) R.raw.boluserror else 0) i.putExtra("soundid", if (withSound) R.raw.boluserror else 0)
@ -216,10 +219,10 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
private fun displayNotConfiguredDialog() { private fun displayNotConfiguredDialog() {
context.let { context.let {
UIRunnable(Runnable { UIRunnable {
OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning), OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning),
resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null) resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null)
}).run() }.run()
} }
} }
} }

View file

@ -19,7 +19,7 @@
android:textStyle="bold" /> android:textStyle="bold" />
<LinearLayout <LinearLayout
android:id="@+id/omnipod_pod_management_waiting_for_rl_layout" android:id="@+id/waiting_for_rl_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -62,7 +62,7 @@
android:paddingEnd="10dp"> android:paddingEnd="10dp">
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_activate_pod" android:id="@+id/button_activate_pod"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -74,7 +74,7 @@
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_deactivate_pod" android:id="@+id/button_deactivate_pod"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -94,7 +94,7 @@
android:paddingEnd="10dp"> android:paddingEnd="10dp">
<Button <Button
android:id="@+id/omnipod_pod_management_button_play_test_beep" android:id="@+id/button_play_test_beep"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -106,7 +106,7 @@
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_discard_pod" android:id="@+id/button_discard_pod"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -135,7 +135,7 @@
android:paddingEnd="10dp"> android:paddingEnd="10dp">
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_pod_history" android:id="@+id/button_pod_history"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -146,7 +146,7 @@
android:textAllCaps="false" /> android:textAllCaps="false" />
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_rileylink_stats" android:id="@+id/button_rileylink_stats"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -167,7 +167,7 @@
android:paddingEnd="10dp"> android:paddingEnd="10dp">
<Button <Button
android:id="@+id/omnipod_pod_management_button_pulse_log" android:id="@+id/button_pulse_log"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -179,7 +179,7 @@
android:visibility="gone" /> android:visibility="gone" />
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/omnipod_pod_management_button_reset_rileylink_config" android:id="@+id/button_reset_rileylink_config"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"