Omnipod -> jetpack

This commit is contained in:
Milos Kozak 2021-02-03 23:58:57 +01:00
parent 02d43f4e92
commit 32637b97e0
10 changed files with 76 additions and 60 deletions

View file

@ -1,6 +1,5 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
android { android {

View file

@ -2,13 +2,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.activation.fra
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Button
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import info.nightscout.androidaps.plugins.pump.omnipod.R import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.InfoFragmentBase import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.InfoFragmentBase
import kotlinx.android.synthetic.main.omnipod_wizard_nav_buttons.*
class AttachPodInfoFragment : InfoFragmentBase() { class AttachPodInfoFragment : InfoFragmentBase() {
@ -26,7 +26,7 @@ class AttachPodInfoFragment : InfoFragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_button_next.setOnClickListener { view.findViewById<Button>(R.id.button_next).setOnClickListener {
context?.let { context?.let {
AlertDialog.Builder(it) AlertDialog.Builder(it)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)

View file

@ -3,22 +3,28 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.activation.fra
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Button
import info.nightscout.androidaps.plugins.pump.omnipod.R
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.manager.PodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.ActionFragmentBase import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.ActionFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.PodDeactivationWizardActivity import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.PodDeactivationWizardActivity
import kotlinx.android.synthetic.main.omnipod_wizard_action_page_fragment.*
import javax.inject.Inject import javax.inject.Inject
abstract class PodActivationActionFragmentBase : ActionFragmentBase() { abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
@Inject @Inject protected lateinit var podStateManager: PodStateManager
protected lateinit var podStateManager: PodStateManager
private lateinit var buttonDeactivatePod: Button
private lateinit var buttonRetry: Button
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_button_deactivate_pod.setOnClickListener { buttonDeactivatePod = view.findViewById(R.id.omnipod_wizard_button_deactivate_pod)
buttonRetry = view.findViewById(R.id.omnipod_wizard_button_retry)
buttonDeactivatePod.setOnClickListener {
activity?.let { activity?.let {
startActivity(Intent(it, PodDeactivationWizardActivity::class.java)) startActivity(Intent(it, PodDeactivationWizardActivity::class.java))
it.finish() it.finish()
@ -28,8 +34,8 @@ abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
override fun onActionFailure() { override fun onActionFailure() {
if ((podStateManager.isPodActivationTimeExceeded && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) || podStateManager.isPodFaulted) { if ((podStateManager.isPodActivationTimeExceeded && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) || podStateManager.isPodFaulted) {
omnipod_wizard_button_retry.visibility = View.GONE buttonRetry.visibility = View.GONE
omnipod_wizard_button_deactivate_pod.visibility = View.VISIBLE buttonDeactivatePod.visibility = View.VISIBLE
} }
} }
} }

View file

@ -1,52 +1,52 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Button
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.lifecycle.Observer
import info.nightscout.androidaps.plugins.pump.omnipod.R import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.viewmodel.ActionViewModelBase import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.viewmodel.ActionViewModelBase
import info.nightscout.androidaps.utils.extensions.toVisibility import info.nightscout.androidaps.utils.extensions.toVisibility
import kotlinx.android.synthetic.main.omnipod_wizard_action_page_fragment.*
import kotlinx.android.synthetic.main.omnipod_wizard_nav_buttons.*
abstract class ActionFragmentBase : WizardFragmentBase() { abstract class ActionFragmentBase : WizardFragmentBase() {
protected lateinit var viewModel: ActionViewModelBase protected lateinit var viewModel: ActionViewModelBase
@SuppressLint("CutPasteId")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_button_next.isEnabled = false binding.navButtonsLayout.buttonNext.isEnabled = false
omnipod_wizard_action_page_text.setText(getTextId()) view.findViewById<Button>(R.id.omnipod_wizard_action_page_text).setText(getTextId())
omnipod_wizard_button_retry.setOnClickListener { viewModel.executeAction() } view.findViewById<Button>(R.id.omnipod_wizard_button_retry).setOnClickListener { viewModel.executeAction() }
viewModel.isActionExecutingLiveData.observe(viewLifecycleOwner, Observer { isExecuting -> viewModel.isActionExecutingLiveData.observe(viewLifecycleOwner, { isExecuting ->
if (isExecuting) { if (isExecuting) {
omnipod_wizard_action_error.visibility = View.GONE view.findViewById<Button>(R.id.omnipod_wizard_action_error).visibility = View.GONE
omnipod_wizard_button_deactivate_pod.visibility = View.GONE view.findViewById<Button>(R.id.omnipod_wizard_button_deactivate_pod).visibility = View.GONE
omnipod_wizard_button_discard_pod.visibility = View.GONE view.findViewById<Button>(R.id.omnipod_wizard_button_discard_pod).visibility = View.GONE
omnipod_wizard_button_retry.visibility = View.GONE view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = View.GONE
} }
omnipod_wizard_action_progress_indication.visibility = isExecuting.toVisibility() view.findViewById<Button>(R.id.omnipod_wizard_action_progress_indication).visibility = isExecuting.toVisibility()
omnipod_wizard_button_cancel.isEnabled = !isExecuting view.findViewById<Button>(R.id.button_cancel).isEnabled = !isExecuting
}) })
viewModel.actionResultLiveData.observe(viewLifecycleOwner, Observer { result -> viewModel.actionResultLiveData.observe(viewLifecycleOwner, { result ->
result?.let { result?.let {
val isExecuting = isActionExecuting() val isExecuting = isActionExecuting()
omnipod_wizard_button_next.isEnabled = result.success view.findViewById<Button>(R.id.button_next).isEnabled = result.success
omnipod_wizard_action_success.visibility = result.success.toVisibility() view.findViewById<Button>(R.id.omnipod_wizard_action_success).visibility = result.success.toVisibility()
omnipod_wizard_action_error.visibility = (!isExecuting && !result.success).toVisibility() view.findViewById<Button>(R.id.omnipod_wizard_action_error).visibility = (!isExecuting && !result.success).toVisibility()
omnipod_wizard_button_retry.visibility = (!isExecuting && !result.success).toVisibility() view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = (!isExecuting && !result.success).toVisibility()
if (result.success) { if (result.success) {
onActionSuccess() onActionSuccess()
} else { } else {
omnipod_wizard_action_error.text = result.comment view.findViewById<Button>(R.id.omnipod_wizard_action_error).text = result.comment
onActionFailure() onActionFailure()
} }
} }

View file

@ -2,17 +2,17 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragmen
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.TextView
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import info.nightscout.androidaps.plugins.pump.omnipod.R import info.nightscout.androidaps.plugins.pump.omnipod.R
import kotlinx.android.synthetic.main.omnipod_wizard_info_page_fragment.*
abstract class InfoFragmentBase : WizardFragmentBase() { abstract class InfoFragmentBase : WizardFragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_info_page_text.setText(getTextId()) view.findViewById<TextView>(R.id.omnipod_wizard_info_page_text).setText(getTextId())
} }
@StringRes @StringRes
@ -22,5 +22,4 @@ abstract class InfoFragmentBase : WizardFragmentBase() {
override fun getLayoutId(): Int { override fun getLayoutId(): Int {
return R.layout.omnipod_wizard_info_page_fragment return R.layout.omnipod_wizard_info_page_fragment
} }
} }

View file

@ -5,50 +5,49 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewStub
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.plugins.pump.omnipod.R import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.databinding.OmnipodWizardBaseFragmentBinding
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.activity.OmnipodWizardActivityBase import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.activity.OmnipodWizardActivityBase
import kotlinx.android.synthetic.main.omnipod_wizard_base_fragment.*
import kotlinx.android.synthetic.main.omnipod_wizard_nav_buttons.*
import kotlinx.android.synthetic.main.omnipod_wizard_progress_indication.*
import kotlin.math.roundToInt import kotlin.math.roundToInt
abstract class WizardFragmentBase : DaggerFragment() { abstract class WizardFragmentBase : DaggerFragment() {
override fun onCreateView( var _binding: OmnipodWizardBaseFragmentBinding? = null
inflater: LayoutInflater,
container: ViewGroup?, // This property is only valid between onCreateView and
savedInstanceState: Bundle? // onDestroyView.
): View { val binding get() = _binding!!
val baseView = inflater.inflate(R.layout.omnipod_wizard_base_fragment, container, false)
val contentView = baseView.findViewById<ViewStub>(R.id.omnipod_wizard_base_fragment_content) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
contentView?.let { _binding = OmnipodWizardBaseFragmentBinding.inflate(inflater, container, false)
binding.fragmentContent.let {
it.layoutResource = getLayoutId() it.layoutResource = getLayoutId()
it.inflate() it.inflate()
} }
return baseView return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_base_fragment_title.setText(getTitleId()) binding.fragmentTitle.setText(getTitleId())
val nextPage = getNextPageActionId() val nextPage = getNextPageActionId()
if (nextPage == null) { if (nextPage == null) {
omnipod_wizard_button_next.text = getString(R.string.omnipod_wizard_button_finish) binding.navButtonsLayout.buttonNext.text = getString(R.string.omnipod_wizard_button_finish)
omnipod_wizard_button_next.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.omnipod_wizard_finish_button, context?.theme)) binding.navButtonsLayout.buttonNext.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.omnipod_wizard_finish_button, context?.theme))
} }
updateProgressIndication() updateProgressIndication()
omnipod_wizard_button_next.setOnClickListener { binding.navButtonsLayout.buttonNext.setOnClickListener {
if (nextPage == null) { if (nextPage == null) {
activity?.finish() activity?.finish()
} else { } else {
@ -56,11 +55,17 @@ abstract class WizardFragmentBase : DaggerFragment() {
} }
} }
omnipod_wizard_button_cancel.setOnClickListener { binding.navButtonsLayout.buttonCancel.setOnClickListener {
(activity as? OmnipodWizardActivityBase)?.exitActivityAfterConfirmation() (activity as? OmnipodWizardActivityBase)?.exitActivityAfterConfirmation()
} }
} }
@Synchronized
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun updateProgressIndication() { private fun updateProgressIndication() {
(activity as? OmnipodWizardActivityBase)?.let { (activity as? OmnipodWizardActivityBase)?.let {
val numberOfSteps = it.getActualNumberOfSteps() val numberOfSteps = it.getActualNumberOfSteps()
@ -68,7 +73,7 @@ abstract class WizardFragmentBase : DaggerFragment() {
val currentFragment = getIndex() - (it.getTotalDefinedNumberOfSteps() - numberOfSteps) val currentFragment = getIndex() - (it.getTotalDefinedNumberOfSteps() - numberOfSteps)
val progressPercentage = (currentFragment / numberOfSteps.toDouble() * 100).roundToInt() val progressPercentage = (currentFragment / numberOfSteps.toDouble() * 100).roundToInt()
omnipod_wizard_progress_indication.progress = progressPercentage binding.progressIndicationLayout.progressIndication.progress = progressPercentage
} }
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.f
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Button
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
@ -14,7 +15,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManage
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.ActionFragmentBase import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.ActionFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.viewmodel.DeactivatePodActionViewModel import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.viewmodel.DeactivatePodActionViewModel
import info.nightscout.androidaps.utils.extensions.toVisibility import info.nightscout.androidaps.utils.extensions.toVisibility
import kotlinx.android.synthetic.main.omnipod_wizard_action_page_fragment.*
import javax.inject.Inject import javax.inject.Inject
class DeactivatePodActionFragment : ActionFragmentBase() { class DeactivatePodActionFragment : ActionFragmentBase() {
@ -26,6 +26,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
@Inject @Inject
lateinit var aapsOmnipodManager: AapsOmnipodManager lateinit var aapsOmnipodManager: AapsOmnipodManager
private lateinit var buttonDiscardPod: Button
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -35,7 +37,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_wizard_button_discard_pod.setOnClickListener { buttonDiscardPod = view.findViewById(R.id.button_discard_pod)
buttonDiscardPod.setOnClickListener {
context?.let { context?.let {
AlertDialog.Builder(it) AlertDialog.Builder(it)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
@ -52,7 +55,7 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
} }
override fun onActionFailure() { override fun onActionFailure() {
omnipod_wizard_button_discard_pod.visibility = (!isActionExecuting()).toVisibility() buttonDiscardPod.visibility = (!isActionExecuting()).toVisibility()
} }
@StringRes @StringRes

View file

@ -5,10 +5,12 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/omnipod_wizard_progress_indication" /> <include
android:id="@+id/progress_indication_layout"
layout="@layout/omnipod_wizard_progress_indication" />
<TextView <TextView
android:id="@+id/omnipod_wizard_base_fragment_title" android:id="@+id/fragment_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
@ -21,10 +23,12 @@
android:layout_weight="1"> android:layout_weight="1">
<ViewStub <ViewStub
android:id="@+id/omnipod_wizard_base_fragment_content" android:id="@+id/fragment_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</ScrollView> </ScrollView>
<include layout="@layout/omnipod_wizard_nav_buttons" /> <include
android:id="@+id/nav_buttons_layout"
layout="@layout/omnipod_wizard_nav_buttons" />
</LinearLayout> </LinearLayout>

View file

@ -5,14 +5,14 @@
android:orientation="horizontal"> android:orientation="horizontal">
<Button <Button
android:id="@+id/omnipod_wizard_button_cancel" android:id="@+id/button_cancel"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/omnipod_wizard_button_cancel" /> android:text="@string/omnipod_wizard_button_cancel" />
<Button <Button
android:id="@+id/omnipod_wizard_button_next" android:id="@+id/button_next"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"

View file

@ -5,7 +5,7 @@
android:orientation="horizontal"> android:orientation="horizontal">
<ProgressBar <ProgressBar
android:id="@+id/omnipod_wizard_progress_indication" android:id="@+id/progress_indication"
style="@android:style/Widget.ProgressBar.Horizontal" style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="200dp" android:layout_width="200dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"