More WIP on moving parts of omnipod-eros to omnipod-common
This commit is contained in:
parent
87d4ba14cb
commit
eac0c9a224
17 changed files with 99 additions and 56 deletions
|
@ -4,16 +4,18 @@ import android.os.Bundle
|
|||
import androidx.annotation.IdRes
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.activity.OmnipodWizardActivityBase
|
||||
import javax.inject.Inject
|
||||
|
||||
class PodActivationWizardActivity : OmnipodWizardActivityBase() {
|
||||
companion object {
|
||||
|
||||
const val KEY_TYPE = "wizardType"
|
||||
const val KEY_START_DESTINATION = "startDestination"
|
||||
}
|
||||
|
||||
@Inject
|
||||
lateinit var podStateManager: PodStateManager
|
||||
enum class Type {
|
||||
SHORT,
|
||||
LONG
|
||||
}
|
||||
|
||||
@IdRes
|
||||
private var startDestination: Int = R.id.fillPodInfoFragment
|
||||
|
@ -24,7 +26,7 @@ class PodActivationWizardActivity : OmnipodWizardActivityBase() {
|
|||
setContentView(R.layout.omnipod_common_pod_activation_wizard_activity)
|
||||
|
||||
startDestination = savedInstanceState?.getInt(KEY_START_DESTINATION, R.id.fillPodInfoFragment)
|
||||
?: if (podStateManager.activationProgress.isBefore(ActivationProgress.PRIMING_COMPLETED)) {
|
||||
?: if (intent.getSerializableExtra(KEY_TYPE) as Type == Type.LONG) {
|
||||
R.id.fillPodInfoFragment
|
||||
} else {
|
||||
R.id.attachPodInfoFragment
|
||||
|
|
|
@ -1,17 +1,35 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.FillPodInfoViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
|
||||
import javax.inject.Inject
|
||||
|
||||
class FillPodInfoFragment : InfoFragmentBase() {
|
||||
@Inject
|
||||
@OmnipodPluginQualifier
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
private lateinit var viewModel: FillPodInfoViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val vm: FillPodInfoViewModel by viewModels { viewModelFactory }
|
||||
this.viewModel = vm
|
||||
}
|
||||
|
||||
@StringRes
|
||||
override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_fill_pod_title
|
||||
|
||||
@StringRes
|
||||
override fun getTextId(): Int = R.string.omnipod_pod_activation_wizard_fill_pod_text
|
||||
override fun getTextId(): Int = viewModel.getTextId()
|
||||
|
||||
@IdRes
|
||||
override fun getNextPageActionId(): Int = R.id.action_fillPodInfoFragment_to_initializePodActionFragment
|
||||
|
|
|
@ -27,7 +27,7 @@ class InitializePodActionFragment : PodActivationActionFragmentBase() {
|
|||
override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_initialize_pod_title
|
||||
|
||||
@StringRes
|
||||
override fun getTextId(): Int = R.string.omnipod_pod_activation_wizard_initialize_pod_text
|
||||
override fun getTextId(): Int = (viewModel as InitializePodActionViewModel).getTextId()
|
||||
|
||||
@IdRes
|
||||
override fun getNextPageActionId(): Int = R.id.action_initializePodActionFragment_to_attachPodInfoFragment
|
||||
|
|
|
@ -5,24 +5,16 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import android.widget.Button
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.PodActivationActionViewModelBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.ActionFragmentBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.PodDeactivationWizardActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
|
||||
|
||||
@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)
|
||||
|
||||
buttonDeactivatePod = view.findViewById(R.id.omnipod_wizard_button_deactivate_pod)
|
||||
buttonRetry = view.findViewById(R.id.omnipod_wizard_button_retry)
|
||||
|
||||
buttonDeactivatePod.setOnClickListener {
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_deactivate_pod).setOnClickListener {
|
||||
activity?.let {
|
||||
startActivity(Intent(it, PodDeactivationWizardActivity::class.java))
|
||||
it.finish()
|
||||
|
@ -30,10 +22,14 @@ abstract class PodActivationActionFragmentBase : ActionFragmentBase() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onActionFailure() {
|
||||
if ((podStateManager.isPodActivationTimeExceeded && podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)) || podStateManager.isPodFaulted) {
|
||||
buttonRetry.visibility = View.GONE
|
||||
buttonDeactivatePod.visibility = View.VISIBLE
|
||||
override fun onFailure() {
|
||||
(viewModel as? PodActivationActionViewModelBase)?.let { viewModel ->
|
||||
if (viewModel.isPodDeactivatable() and (viewModel.isPodInAlarm() or viewModel.isPodActivationTimeExceeded())) {
|
||||
view?.let {
|
||||
it.findViewById<Button>(R.id.omnipod_wizard_button_retry)?.visibility = View.GONE
|
||||
it.findViewById<Button>(R.id.omnipod_wizard_button_deactivate_pod)?.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.lifecycle.ViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
|
||||
class FillPodInfoViewModel : ViewModel() {
|
||||
|
||||
@StringRes fun getTextId(): Int = R.string.omnipod_pod_activation_wizard_fill_pod_text
|
||||
}
|
|
@ -1,11 +1,20 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class InitializePodActionViewModel @Inject constructor(private val aapsOmnipodManager: AapsOmnipodManager) : ActionViewModelBase() {
|
||||
class InitializePodActionViewModel @Inject constructor(private val aapsOmnipodManager: AapsOmnipodManager, private val podStateManager: AapsPodStateManager) : PodActivationActionViewModelBase() {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted
|
||||
|
||||
override fun isPodActivationTimeExceeded(): Boolean = podStateManager.isPodActivationTimeExceeded
|
||||
|
||||
override fun isPodDeactivatable(): Boolean = podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)
|
||||
|
||||
override fun doExecuteAction(): PumpEnactResult = aapsOmnipodManager.initializePod()
|
||||
|
||||
@StringRes fun getTextId() = R.string.omnipod_pod_activation_wizard_initialize_pod_text
|
||||
}
|
|
@ -2,11 +2,16 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
|
|||
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class InsertCannulaActionViewModel @Inject constructor(private val aapsOmnipodManager: AapsOmnipodManager, private val profileFunction: ProfileFunction) : ActionViewModelBase() {
|
||||
class InsertCannulaActionViewModel @Inject constructor(private val aapsOmnipodManager: AapsOmnipodManager, private val podStateManager: AapsPodStateManager, private val profileFunction: ProfileFunction) : PodActivationActionViewModelBase() {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted
|
||||
|
||||
override fun isPodActivationTimeExceeded(): Boolean = podStateManager.isPodActivationTimeExceeded
|
||||
|
||||
override fun isPodDeactivatable(): Boolean = podStateManager.activationProgress.isAtLeast(ActivationProgress.PAIRING_COMPLETED)
|
||||
|
||||
override fun doExecuteAction(): PumpEnactResult = aapsOmnipodManager.insertCannula(profileFunction.getProfile())
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
|
||||
abstract class PodActivationActionViewModelBase : ActionViewModelBase() {
|
||||
|
||||
abstract fun isPodInAlarm(): Boolean
|
||||
|
||||
abstract fun isPodActivationTimeExceeded(): Boolean
|
||||
|
||||
abstract fun isPodDeactivatable(): Boolean
|
||||
}
|
|
@ -8,9 +8,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
|||
|
||||
abstract class OmnipodWizardActivityBase : NoSplashAppCompatActivity() {
|
||||
|
||||
override fun onBackPressed() {
|
||||
exitActivityAfterConfirmation()
|
||||
}
|
||||
override fun onBackPressed() = exitActivityAfterConfirmation()
|
||||
|
||||
fun exitActivityAfterConfirmation() {
|
||||
if (getNavController().previousBackStackEntry == null) {
|
||||
|
|
|
@ -43,11 +43,9 @@ abstract class ActionFragmentBase : WizardFragmentBase() {
|
|||
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 {
|
||||
if (!result.success) {
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_action_error).text = result.comment
|
||||
onActionFailure()
|
||||
onFailure()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -66,15 +64,11 @@ abstract class ActionFragmentBase : WizardFragmentBase() {
|
|||
viewModel.actionResultLiveData.removeObservers(viewLifecycleOwner)
|
||||
}
|
||||
|
||||
fun onActionSuccess() {}
|
||||
|
||||
open fun onActionFailure() {}
|
||||
abstract fun onFailure()
|
||||
|
||||
@StringRes
|
||||
abstract fun getTextId(): Int
|
||||
|
||||
@LayoutRes
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.omnipod_common_wizard_action_page_fragment
|
||||
}
|
||||
override fun getLayoutId(): Int = R.layout.omnipod_common_wizard_action_page_fragment
|
||||
}
|
|
@ -19,7 +19,5 @@ abstract class InfoFragmentBase : WizardFragmentBase() {
|
|||
abstract fun getTextId(): Int
|
||||
|
||||
@LayoutRes
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.omnipod_common_wizard_info_page_fragment
|
||||
}
|
||||
override fun getLayoutId(): Int = R.layout.omnipod_common_wizard_info_page_fragment
|
||||
}
|
|
@ -11,19 +11,20 @@ import androidx.annotation.StringRes
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.databinding.OmnipodCommonWizardBaseFragmentBinding
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.activity.OmnipodWizardActivityBase
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
abstract class WizardFragmentBase : DaggerFragment() {
|
||||
|
||||
var _binding: OmnipodWizardBaseFragmentBinding? = null
|
||||
var _binding: OmnipodCommonWizardBaseFragmentBinding? = 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 = OmnipodCommonWizardBaseFragmentBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.fragmentContent.let {
|
||||
it.layoutResource = getLayoutId()
|
||||
|
|
|
@ -9,7 +9,7 @@ import io.reactivex.subjects.SingleSubject
|
|||
|
||||
abstract class ActionViewModelBase : ViewModel() {
|
||||
|
||||
private val _isActionExecutingLiveData = MutableLiveData<Boolean>(false)
|
||||
private val _isActionExecutingLiveData = MutableLiveData(false)
|
||||
val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData
|
||||
|
||||
private val _actionResultLiveData = MutableLiveData<PumpEnactResult?>(null)
|
||||
|
|
|
@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.R
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.ActionFragmentBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.DeactivatePodActionViewModel
|
||||
import info.nightscout.androidaps.utils.extensions.toVisibility
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeactivatePodActionFragment : ActionFragmentBase() {
|
||||
|
@ -22,9 +21,6 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
@OmnipodPluginQualifier
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
@Inject
|
||||
lateinit var aapsOmnipodManager: AapsOmnipodManager
|
||||
|
||||
private lateinit var buttonDiscardPod: Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -36,15 +32,14 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
buttonDiscardPod = view.findViewById(R.id.omnipod_wizard_button_discard_pod)
|
||||
buttonDiscardPod.setOnClickListener {
|
||||
view.findViewById<Button>(R.id.omnipod_wizard_button_discard_pod)?.setOnClickListener {
|
||||
context?.let {
|
||||
AlertDialog.Builder(it)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(getString(R.string.omnipod_common_pod_deactivation_wizard_discard_pod))
|
||||
.setMessage(getString(R.string.omnipod_common_pod_deactivation_wizard_discard_pod_confirmation))
|
||||
.setPositiveButton(getString(R.string.omnipod_common_yes)) { _, _ ->
|
||||
aapsOmnipodManager.discardPodState()
|
||||
(viewModel as DeactivatePodActionViewModel).discardPod()
|
||||
findNavController().navigate(R.id.action_deactivatePodActionFragment_to_podDiscardedInfoFragment)
|
||||
}
|
||||
.setNegativeButton(getString(R.string.omnipod_common_no), null)
|
||||
|
@ -53,8 +48,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onActionFailure() {
|
||||
buttonDiscardPod.visibility = (!isActionExecuting()).toVisibility()
|
||||
override fun onFailure() {
|
||||
buttonDiscardPod.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
|
|
@ -2,9 +2,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactiv
|
|||
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandDeactivatePod
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandDeactivatePod
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import io.reactivex.subjects.SingleSubject
|
||||
import javax.inject.Inject
|
||||
|
@ -20,4 +20,8 @@ class DeactivatePodActionViewModel @Inject constructor(private val aapsOmnipodMa
|
|||
})
|
||||
return singleSubject.blockingGet()
|
||||
}
|
||||
|
||||
fun discardPod() {
|
||||
aapsOmnipodManager.discardPodState()
|
||||
}
|
||||
}
|
|
@ -58,6 +58,7 @@ class ErosPodManagementActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = OmnipodPodManagementBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class OmnipodErosOverviewFragment : DaggerFragment() {
|
|||
companion object {
|
||||
|
||||
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
|
||||
private const val PLACEHOLDER = "-" // 15 seconds
|
||||
private const val PLACEHOLDER = "-"
|
||||
}
|
||||
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
|
@ -93,11 +93,11 @@ class OmnipodErosOverviewFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private var _binding: OmnipodErosOverviewBinding? = null
|
||||
var _binding: OmnipodErosOverviewBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
OmnipodErosOverviewBinding.inflate(inflater, container!!).also {
|
||||
|
|
Loading…
Reference in a new issue