Omnipod -> jetpack
This commit is contained in:
parent
02d43f4e92
commit
32637b97e0
10 changed files with 76 additions and 60 deletions
|
@ -1,6 +1,5 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
|
|
|
@ -2,13 +2,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.activation.fra
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.InfoFragmentBase
|
||||
import kotlinx.android.synthetic.main.omnipod_wizard_nav_buttons.*
|
||||
|
||||
class AttachPodInfoFragment : InfoFragmentBase() {
|
||||
|
||||
|
@ -26,7 +26,7 @@ class AttachPodInfoFragment : InfoFragmentBase() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
omnipod_wizard_button_next.setOnClickListener {
|
||||
view.findViewById<Button>(R.id.button_next).setOnClickListener {
|
||||
context?.let {
|
||||
AlertDialog.Builder(it)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
|
|
|
@ -3,22 +3,28 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.activation.fra
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
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.manager.PodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment.ActionFragmentBase
|
||||
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
|
||||
|
||||
abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
|
||||
|
||||
@Inject
|
||||
protected lateinit var podStateManager: PodStateManager
|
||||
@Inject protected lateinit var podStateManager: PodStateManager
|
||||
|
||||
private lateinit var buttonDeactivatePod: Button
|
||||
private lateinit var buttonRetry: Button
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
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 {
|
||||
startActivity(Intent(it, PodDeactivationWizardActivity::class.java))
|
||||
it.finish()
|
||||
|
@ -28,8 +34,8 @@ abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
|
|||
|
||||
override fun onActionFailure() {
|
||||
if ((podStateManager.isPodActivationTimeExceeded && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) || podStateManager.isPodFaulted) {
|
||||
omnipod_wizard_button_retry.visibility = View.GONE
|
||||
omnipod_wizard_button_deactivate_pod.visibility = View.VISIBLE
|
||||
buttonRetry.visibility = View.GONE
|
||||
buttonDeactivatePod.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +1,52 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.lifecycle.Observer
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
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() {
|
||||
|
||||
protected lateinit var viewModel: ActionViewModelBase
|
||||
|
||||
@SuppressLint("CutPasteId")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
omnipod_wizard_button_next.isEnabled = false
|
||||
omnipod_wizard_action_page_text.setText(getTextId())
|
||||
binding.navButtonsLayout.buttonNext.isEnabled = false
|
||||
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) {
|
||||
omnipod_wizard_action_error.visibility = View.GONE
|
||||
omnipod_wizard_button_deactivate_pod.visibility = View.GONE
|
||||
omnipod_wizard_button_discard_pod.visibility = View.GONE
|
||||
omnipod_wizard_button_retry.visibility = View.GONE
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_error).visibility = View.GONE
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_deactivate_pod).visibility = View.GONE
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_discard_pod).visibility = View.GONE
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = View.GONE
|
||||
}
|
||||
omnipod_wizard_action_progress_indication.visibility = isExecuting.toVisibility()
|
||||
omnipod_wizard_button_cancel.isEnabled = !isExecuting
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_progress_indication).visibility = isExecuting.toVisibility()
|
||||
view.findViewById<Button>(R.id.button_cancel).isEnabled = !isExecuting
|
||||
})
|
||||
|
||||
viewModel.actionResultLiveData.observe(viewLifecycleOwner, Observer { result ->
|
||||
viewModel.actionResultLiveData.observe(viewLifecycleOwner, { result ->
|
||||
result?.let {
|
||||
val isExecuting = isActionExecuting()
|
||||
|
||||
omnipod_wizard_button_next.isEnabled = result.success
|
||||
omnipod_wizard_action_success.visibility = result.success.toVisibility()
|
||||
omnipod_wizard_action_error.visibility = (!isExecuting && !result.success).toVisibility()
|
||||
omnipod_wizard_button_retry.visibility = (!isExecuting && !result.success).toVisibility()
|
||||
view.findViewById<Button>(R.id.button_next).isEnabled = result.success
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_success).visibility = result.success.toVisibility()
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_error).visibility = (!isExecuting && !result.success).toVisibility()
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = (!isExecuting && !result.success).toVisibility()
|
||||
|
||||
if (result.success) {
|
||||
onActionSuccess()
|
||||
} else {
|
||||
omnipod_wizard_action_error.text = result.comment
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_error).text = result.comment
|
||||
onActionFailure()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,17 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.common.fragmen
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.StringRes
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.R
|
||||
import kotlinx.android.synthetic.main.omnipod_wizard_info_page_fragment.*
|
||||
|
||||
abstract class InfoFragmentBase : WizardFragmentBase() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
omnipod_wizard_info_page_text.setText(getTextId())
|
||||
view.findViewById<TextView>(R.id.omnipod_wizard_info_page_text).setText(getTextId())
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
@ -22,5 +22,4 @@ abstract class InfoFragmentBase : WizardFragmentBase() {
|
|||
override fun getLayoutId(): Int {
|
||||
return R.layout.omnipod_wizard_info_page_fragment
|
||||
}
|
||||
|
||||
}
|
|
@ -5,50 +5,49 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewStub
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import dagger.android.support.DaggerFragment
|
||||
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 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
|
||||
|
||||
abstract class WizardFragmentBase : DaggerFragment() {
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val baseView = inflater.inflate(R.layout.omnipod_wizard_base_fragment, container, false)
|
||||
val contentView = baseView.findViewById<ViewStub>(R.id.omnipod_wizard_base_fragment_content)
|
||||
contentView?.let {
|
||||
var _binding: OmnipodWizardBaseFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
_binding = OmnipodWizardBaseFragmentBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.fragmentContent.let {
|
||||
it.layoutResource = getLayoutId()
|
||||
it.inflate()
|
||||
}
|
||||
return baseView
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
omnipod_wizard_base_fragment_title.setText(getTitleId())
|
||||
binding.fragmentTitle.setText(getTitleId())
|
||||
|
||||
val nextPage = getNextPageActionId()
|
||||
|
||||
if (nextPage == null) {
|
||||
omnipod_wizard_button_next.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.text = getString(R.string.omnipod_wizard_button_finish)
|
||||
binding.navButtonsLayout.buttonNext.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.omnipod_wizard_finish_button, context?.theme))
|
||||
}
|
||||
|
||||
updateProgressIndication()
|
||||
|
||||
omnipod_wizard_button_next.setOnClickListener {
|
||||
binding.navButtonsLayout.buttonNext.setOnClickListener {
|
||||
if (nextPage == null) {
|
||||
activity?.finish()
|
||||
} else {
|
||||
|
@ -56,11 +55,17 @@ abstract class WizardFragmentBase : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
omnipod_wizard_button_cancel.setOnClickListener {
|
||||
binding.navButtonsLayout.buttonCancel.setOnClickListener {
|
||||
(activity as? OmnipodWizardActivityBase)?.exitActivityAfterConfirmation()
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
private fun updateProgressIndication() {
|
||||
(activity as? OmnipodWizardActivityBase)?.let {
|
||||
val numberOfSteps = it.getActualNumberOfSteps()
|
||||
|
@ -68,7 +73,7 @@ abstract class WizardFragmentBase : DaggerFragment() {
|
|||
val currentFragment = getIndex() - (it.getTotalDefinedNumberOfSteps() - numberOfSteps)
|
||||
val progressPercentage = (currentFragment / numberOfSteps.toDouble() * 100).roundToInt()
|
||||
|
||||
omnipod_wizard_progress_indication.progress = progressPercentage
|
||||
binding.progressIndicationLayout.progressIndication.progress = progressPercentage
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.deactivation.f
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.StringRes
|
||||
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.deactivation.viewmodel.DeactivatePodActionViewModel
|
||||
import info.nightscout.androidaps.utils.extensions.toVisibility
|
||||
import kotlinx.android.synthetic.main.omnipod_wizard_action_page_fragment.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeactivatePodActionFragment : ActionFragmentBase() {
|
||||
|
@ -26,6 +26,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
@Inject
|
||||
lateinit var aapsOmnipodManager: AapsOmnipodManager
|
||||
|
||||
private lateinit var buttonDiscardPod: Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
@ -35,7 +37,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
omnipod_wizard_button_discard_pod.setOnClickListener {
|
||||
buttonDiscardPod = view.findViewById(R.id.button_discard_pod)
|
||||
buttonDiscardPod.setOnClickListener {
|
||||
context?.let {
|
||||
AlertDialog.Builder(it)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
|
@ -52,7 +55,7 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
}
|
||||
|
||||
override fun onActionFailure() {
|
||||
omnipod_wizard_button_discard_pod.visibility = (!isActionExecuting()).toVisibility()
|
||||
buttonDiscardPod.visibility = (!isActionExecuting()).toVisibility()
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/omnipod_wizard_progress_indication" />
|
||||
<include
|
||||
android:id="@+id/progress_indication_layout"
|
||||
layout="@layout/omnipod_wizard_progress_indication" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_wizard_base_fragment_title"
|
||||
android:id="@+id/fragment_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
|
@ -21,10 +23,12 @@
|
|||
android:layout_weight="1">
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/omnipod_wizard_base_fragment_content"
|
||||
android:id="@+id/fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</ScrollView>
|
||||
|
||||
<include layout="@layout/omnipod_wizard_nav_buttons" />
|
||||
<include
|
||||
android:id="@+id/nav_buttons_layout"
|
||||
layout="@layout/omnipod_wizard_nav_buttons" />
|
||||
</LinearLayout>
|
|
@ -5,14 +5,14 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/omnipod_wizard_button_cancel"
|
||||
android:id="@+id/button_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/omnipod_wizard_button_cancel" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/omnipod_wizard_button_next"
|
||||
android:id="@+id/button_next"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/omnipod_wizard_progress_indication"
|
||||
android:id="@+id/progress_indication"
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in a new issue