More WIP on new Omnipod wizard

This commit is contained in:
Bart Sopers 2020-09-28 09:56:39 +02:00
parent 8563817bae
commit bc817d10f9
22 changed files with 207 additions and 99 deletions

View file

@ -266,6 +266,8 @@ dependencies {
implementation "androidx.activity:activity-ktx:${activityVersion}"
implementation "androidx.fragment:fragment:${fragmentVersion}"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'com.google.android.material:material:1.1.0'
implementation "io.reactivex.rxjava2:rxandroid:${rxandroid_version}"

View file

@ -76,6 +76,7 @@ dependencies {
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "androidx.activity:activity-ktx:${activityVersion}"
implementation "androidx.fragment:fragment:${fragmentVersion}"
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-analytics-ktx:17.4.3'
@ -103,6 +104,8 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'com.google.android.material:material:1.1.0'
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:2.8.47"
testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"

View file

@ -1,7 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2
import android.app.AlertDialog
import android.os.Bundle
import android.os.PersistableBundle
import androidx.annotation.IdRes
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.plugins.pump.omnipod.R
@ -17,37 +19,67 @@ class ReplacePodWizardActivity : NoSplashAppCompatActivity() {
@Inject
lateinit var podStateManager: PodStateManager
var startDestination: Int = R.id.deactivatePodInfoFragment
get() = field
@IdRes
private var startDestination: Int = R.id.deactivatePodInfoFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
setContentView(R.layout.omnipod_replace_pod_wizard_activity)
startDestination = savedInstanceState?.getInt(KEY_START_DESTINATION, R.id.deactivatePodInfoFragment)
?: if (!podStateManager.isPodActivationCompleted) {
if (!podStateManager.isPodInitialized || podStateManager.podProgressStatus.isBefore(PodProgressStatus.PRIMING_COMPLETED)) {
R.id.fillPodInfoFragment
} else {
R.id.attachPodInfoFragment
}
} else {
R.id.deactivatePodInfoFragment
}
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
setContentView(R.layout.omnipod_replace_pod_wizard_activity)
val navController = getNavController()
if (savedInstanceState == null) {
val navInflater = navController.navInflater
val graph = navInflater.inflate(R.navigation.omnipod_replace_pod_wizard_navigation_graph)
if (!podStateManager.isPodActivationCompleted) {
if (!podStateManager.isPodInitialized || podStateManager.podProgressStatus.isBefore(PodProgressStatus.PRIMING_COMPLETED)) {
startDestination = R.id.fillPodInfoFragment
} else {
startDestination = R.id.attachPodInfoFragment
}
}
graph.startDestination = startDestination;
graph.startDestination = startDestination
navController.graph = graph
} else {
startDestination = savedInstanceState.getInt(KEY_START_DESTINATION, R.id.deactivatePodInfoFragment)
}
navController.addOnDestinationChangedListener { controller, destination, _ ->
if (destination.id == R.id.deactivatePodInfoFragment) {
startDestination = R.id.deactivatePodInfoFragment
controller.graph.startDestination = R.id.deactivatePodInfoFragment
}
}
}
override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
super.onSaveInstanceState(outState, outPersistentState)
outState?.putInt(KEY_START_DESTINATION, startDestination)
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(KEY_START_DESTINATION, startDestination)
}
override fun onBackPressed() {
exitActivityAfterConfirmation()
}
fun exitActivityAfterConfirmation() {
if (getNavController().previousBackStackEntry == null) {
finish()
} else {
AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(getString(R.string.omnipod_replace_pod_wizard_replace_pod))
.setMessage(getString(R.string.omnipod_replace_pod_wizard_exit_confirmation))
.setPositiveButton(getString(R.string.omnipod_yes)) { _, _ -> finish() }
.setNegativeButton(getString(R.string.omnipod_no), null)
.show()
}
}
private fun getNavController(): NavController =
(supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment).navController
}

View file

@ -1,53 +1,67 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.view.ViewStub
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
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.ui.wizard2.ReplacePodWizardActivity
import kotlinx.android.synthetic.main.omnipod_replace_pod_wizard_base_fragment.*
import kotlinx.android.synthetic.main.omnipod_replace_pod_wizard_nav_buttons.*
import kotlinx.android.synthetic.main.omnipod_replace_pod_wizard_progress_indication.*
import kotlin.math.roundToInt
abstract class FragmentBase : DaggerFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(getLayout(), container, false)
): View {
val baseView = inflater.inflate(R.layout.omnipod_replace_pod_wizard_base_fragment, container, false)
val contentView = baseView.findViewById<ViewStub>(R.id.omnipod_wizard_base_fragment_content)
contentView?.let {
it.layoutResource = getLayoutId()
it.inflate()
}
return baseView
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Button>(R.id.omnipod_replace_pod_wizard_button_cancel)?.setOnClickListener {
activity?.finish()
omnipod_wizard_base_fragment_title.text = getTitle()
val nextPage = getNextPageActionId()
if (nextPage == null) {
omnipod_replace_pod_wizard_button_next.text = getString(R.string.omnipod_replace_pod_wizard_button_finish)
omnipod_replace_pod_wizard_button_next.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.review_green, context?.theme))
}
val nextButton = view.findViewById<Button>(R.id.omnipod_replace_pod_wizard_button_next)
nextButton?.let {
val nextPage = getNextPageActionId()
updateProgressIndication()
it.text = if (nextPage == null) {
getString(R.string.omnipod_replace_pod_wizard_button_finish)
omnipod_replace_pod_wizard_button_next.setOnClickListener {
if (nextPage == null) {
activity?.finish()
} else {
getString(R.string.omnipod_replace_pod_wizard_button_next)
}
it.setOnClickListener {
if (nextPage == null) {
activity?.finish()
} else {
findNavController().navigate(nextPage)
}
findNavController().navigate(nextPage)
}
}
val startDestination = (activity as ReplacePodWizardActivity).startDestination
val total =
when (startDestination) {
omnipod_replace_pod_wizard_button_cancel.setOnClickListener {
(activity as? ReplacePodWizardActivity)?.exitActivityAfterConfirmation()
}
}
private fun updateProgressIndication() {
val totalFragments =
when (findNavController().graph.startDestination) {
R.id.fillPodInfoFragment -> {
8 - 3
}
@ -61,13 +75,19 @@ abstract class FragmentBase : DaggerFragment() {
}
}
// TODO
view.findViewById<TextView>(R.id.omnipod_replace_pod_wizard_progress_indication)?.text = "X/$total"
val currentFragment = getIndex() - (8 - totalFragments)
val progressPercentage = (currentFragment / totalFragments.toDouble() * 100).roundToInt()
omnipod_replace_pod_wizard_progress_indication.progress = progressPercentage
}
@LayoutRes
abstract fun getLayout(): Int
abstract fun getLayoutId(): Int
@IdRes
abstract fun getNextPageActionId(): Int?
abstract fun getTitle(): String
abstract fun getIndex(): Int
}

View file

@ -15,7 +15,7 @@ abstract class ActionFragmentBase : FragmentBase() {
abstract fun getText(): String
override fun getLayout(): Int {
override fun getLayoutId(): Int {
return R.layout.omnipod_replace_pod_wizard_action_page_fragment
}
}

View file

@ -6,4 +6,8 @@ class DeactivatePodActionFragment : ActionFragmentBase() {
override fun getText(): String = "[deactivate Pod]"
override fun getNextPageActionId(): Int = R.id.action_deactivatePodActionFragment_to_podDeactivatedInfoFragment
override fun getTitle(): String = "Deactivate Pod"
override fun getIndex(): Int = 2
}

View file

@ -6,4 +6,8 @@ class InsertCannulaActionFragment : ActionFragmentBase() {
override fun getText(): String = "[insert cannula]"
override fun getNextPageActionId(): Int = R.id.action_insertCannulaActionFragment_to_podReplacedInfoFragment
override fun getTitle(): String = "Insert cannula"
override fun getIndex(): Int = 7
}

View file

@ -6,4 +6,8 @@ class PairAndPrimePodActionFragment : ActionFragmentBase() {
override fun getText(): String = "[pair and prime Pod]"
override fun getNextPageActionId(): Int = R.id.action_pairAndPrimePodActionFragment_to_attachPodInfoFragment
override fun getTitle(): String = "Pair and prime Pod"
override fun getIndex(): Int = 5
}

View file

@ -6,4 +6,8 @@ class AttachPodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Attach the Pod"
override fun getNextPageActionId(): Int = R.id.action_attachPodInfoFragment_to_insertCannulaActionFragment
override fun getTitle(): String = "Attach Pod"
override fun getIndex(): Int = 6
}

View file

@ -6,4 +6,8 @@ class DeactivatePodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Deactivate the Pod"
override fun getNextPageActionId(): Int = R.id.action_deactivatePodInfoFragment_to_deactivatePodActionFragment
override fun getTitle(): String = "Deactivate Pod"
override fun getIndex(): Int = 1
}

View file

@ -6,4 +6,8 @@ class FillPodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Fill the Pod"
override fun getNextPageActionId(): Int = R.id.action_fillPodInfoFragment_to_pairAndPrimePodActionFragment
override fun getTitle(): String = "Fill new Pod"
override fun getIndex(): Int = 4
}

View file

@ -2,20 +2,21 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import android.os.Bundle
import android.view.View
import android.widget.TextView
import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.FragmentBase
import kotlinx.android.synthetic.main.omnipod_replace_pod_wizard_info_page_fragment.*
abstract class InfoFragmentBase : FragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.omnipod_wizard_info_page_text)?.text = getText();
omnipod_wizard_info_page_text.text = getText()
}
abstract fun getText(): String
override fun getLayout(): Int {
override fun getLayoutId(): Int {
return R.layout.omnipod_replace_pod_wizard_info_page_fragment
}

View file

@ -3,7 +3,11 @@ package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import info.nightscout.androidaps.plugins.pump.omnipod.R
class PodDeactivatedInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Pod has been deactivated"
override fun getText(): String = "Please remove the Pod from your body"
override fun getNextPageActionId(): Int = R.id.action_podDeactivatedInfoFragment_to_fillPodInfoFragment
override fun getTitle(): String = "Remove Pod"
override fun getIndex(): Int = 3
}

View file

@ -1,9 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import info.nightscout.androidaps.plugins.pump.omnipod.R
class PodReplacedInfoFragment : InfoFragmentBase() {
override fun getText(): String = "the Pod has been replaced"
override fun getNextPageActionId(): Int? = null
override fun getTitle(): String = "Pod replaced"
override fun getIndex(): Int = 8
}

View file

@ -2,24 +2,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<include layout="@layout/omnipod_replace_pod_wizard_progress_indication" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="20dp"
android:paddingBottom="20dp">
<TextView
android:id="@+id/omnipod_wizard_action_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<include layout="@layout/omnipod_replace_pod_wizard_nav_buttons" />
android:orientation="vertical">
<TextView
android:id="@+id/omnipod_wizard_action_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:padding="10dp">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/omnipod_replace_pod_wizard_navigation_graph" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/omnipod_replace_pod_wizard_progress_indication" />
<TextView
android:id="@+id/omnipod_wizard_base_fragment_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/WizardPageTitle" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="20dp"
android:paddingBottom="20dp">
<ViewStub
android:id="@+id/omnipod_wizard_base_fragment_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<include layout="@layout/omnipod_replace_pod_wizard_nav_buttons" />
</LinearLayout>

View file

@ -2,24 +2,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<include layout="@layout/omnipod_replace_pod_wizard_progress_indication" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="20dp"
android:paddingBottom="20dp">
<TextView
android:id="@+id/omnipod_wizard_info_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<include layout="@layout/omnipod_replace_pod_wizard_nav_buttons" />
android:orientation="vertical">
<TextView
android:id="@+id/omnipod_wizard_info_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -2,11 +2,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="horizontal">
<TextView
<ProgressBar
android:id="@+id/omnipod_replace_pod_wizard_progress_indication"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:indeterminate="false"
android:progress="0"
android:progressTint="@color/replacePodWizardProgressBar"
android:scaleY=".5" />
</LinearLayout>

View file

@ -2,4 +2,5 @@
<resources>
<color name="black_overlay">#66000000</color>
<color name="ribbonWarning">#f4d700</color>
<color name="replacePodWizardProgressBar">#0099CC</color>
</resources>

View file

@ -233,6 +233,10 @@
<string name="omnipod_wizard_button_cancel">Cancel</string>
<string name="omnipod_replace_pod_wizard_button_finish">Finish</string>
<string name="omnipod_replace_pod_wizard_button_next">Next</string>
<string name="omnipod_replace_pod_wizard_exit_confirmation">You haven\'t finished replacing your pod yet. Are you sure you want to exit?</string>
<string name="omnipod_replace_pod_wizard_replace_pod">Replace Pod</string>
<string name="omnipod_yes">Yes</string>
<string name="omnipod_no">No</string>
<plurals name="omnipod_minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>

View file

@ -28,4 +28,14 @@
<item name="android:divider">@android:color/black</item>
<item name="android:dividerHeight">1dp</item>
</style>
<style name="WizardPageTitle">
<item name="android:id">@android:id/title</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:paddingLeft">@dimen/list_item_padding_left</item>
<item name="android:textSize">36sp</item>
<item name="android:textColor">#0099CC</item>
</style>
</resources>