Add navigation in Replace Pod Wizard

This commit is contained in:
Bart Sopers 2020-09-26 23:34:29 +02:00
parent 80e0992faa
commit 8563817bae
24 changed files with 246 additions and 58 deletions

View file

@ -75,6 +75,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.2.0'
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "androidx.activity:activity-ktx:${activityVersion}"
implementation "androidx.fragment:fragment:${fragmentVersion}"
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-analytics-ktx:17.4.3'

View file

@ -9,7 +9,7 @@
<activity android:name=".ui.PodManagementActivity" />
<activity android:name=".ui.PodHistoryActivity" />
<activity android:name=".ui.wizard2.WizardActivity" />
<activity android:name=".ui.wizard2.ReplacePodWizardActivity" />
<activity
android:name="com.atech.android.library.wizardpager.WizardPagerActivity"
android:theme="@style/AppTheme.NoActionBar" />

View file

@ -13,7 +13,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitAct
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitPodTask
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.PodInfoFragment
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.removepod.RemoveActionFragment
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.WizardActivity
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.ReplacePodWizardActivity
@Module
@Suppress("unused")
@ -26,7 +26,7 @@ abstract class OmnipodModule {
@ActivityScope
@ContributesAndroidInjector(modules = [OmnipodWizardModule::class])
abstract fun contributesWizardActivity(): WizardActivity
abstract fun contributesWizardActivity(): ReplacePodWizardActivity
// Fragments
@ContributesAndroidInjector abstract fun initActionFragment(): InitActionFragment

View file

@ -29,7 +29,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateMa
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.*
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.WizardActivity
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.ReplacePodWizardActivity
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.events.EventQueueChanged
@ -94,7 +94,7 @@ class OmnipodFragment : DaggerFragment() {
super.onViewCreated(view, savedInstanceState)
omnipod_button_replace_pod.setOnClickListener {
startActivity(Intent(context, WizardActivity::class.java))
startActivity(Intent(context, ReplacePodWizardActivity::class.java))
}
omnipod_button_pod_mgmt.setOnClickListener {

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManage
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.FullInitPodWizardModel
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.RemovePodWizardModel
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.ShortInitPodWizardModel
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.WizardActivity
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.ReplacePodWizardActivity
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
@ -58,7 +58,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}
initpod_replace_pod.setOnClickListener {
val myIntent = Intent(this@PodManagementActivity, WizardActivity::class.java)
val myIntent = Intent(this@PodManagementActivity, ReplacePodWizardActivity::class.java)
this@PodManagementActivity.startActivity(myIntent)
}

View file

@ -0,0 +1,53 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2
import android.os.Bundle
import android.os.PersistableBundle
import androidx.navigation.fragment.NavHostFragment
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
import javax.inject.Inject
class ReplacePodWizardActivity : NoSplashAppCompatActivity() {
companion object {
const val KEY_START_DESTINATION = "startDestination"
}
@Inject
lateinit var podStateManager: PodStateManager
var startDestination: Int = R.id.deactivatePodInfoFragment
get() = field
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
setContentView(R.layout.omnipod_replace_pod_wizard_activity)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
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;
navController.graph = graph
} else {
startDestination = savedInstanceState.getInt(KEY_START_DESTINATION, R.id.deactivatePodInfoFragment)
}
}
override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
super.onSaveInstanceState(outState, outPersistentState)
outState?.putInt(KEY_START_DESTINATION, startDestination)
}
}

View file

@ -1,13 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2
import android.os.Bundle
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.plugins.pump.omnipod.R
class WizardActivity : NoSplashAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.omnipod_replace_pod_wizard_activity) // TODO: replace with DataBindingUtil.setContentView
}
}

View file

@ -0,0 +1,73 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment
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 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
abstract class FragmentBase : DaggerFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(getLayout(), container, false)
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()
}
val nextButton = view.findViewById<Button>(R.id.omnipod_replace_pod_wizard_button_next)
nextButton?.let {
val nextPage = getNextPageActionId()
it.text = if (nextPage == null) {
getString(R.string.omnipod_replace_pod_wizard_button_finish)
} else {
getString(R.string.omnipod_replace_pod_wizard_button_next)
}
it.setOnClickListener {
if (nextPage == null) {
activity?.finish()
} else {
findNavController().navigate(nextPage)
}
}
}
val startDestination = (activity as ReplacePodWizardActivity).startDestination
val total =
when (startDestination) {
R.id.fillPodInfoFragment -> {
8 - 3
}
R.id.attachPodInfoFragment -> {
8 - 5
}
else -> {
8
}
}
// TODO
view.findViewById<TextView>(R.id.omnipod_replace_pod_wizard_progress_indication)?.text = "X/$total"
}
@LayoutRes
abstract fun getLayout(): Int
@IdRes
abstract fun getNextPageActionId(): Int?
}

View file

@ -1,20 +1,12 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.action
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.FragmentBase
abstract class ActionFragmentBase : DaggerFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.omnipod_replace_pod_wizard_action_page_fragment, container, false)
abstract class ActionFragmentBase : FragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -22,4 +14,8 @@ abstract class ActionFragmentBase : DaggerFragment() {
}
abstract fun getText(): String
override fun getLayout(): Int {
return R.layout.omnipod_replace_pod_wizard_action_page_fragment
}
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.action
import info.nightscout.androidaps.plugins.pump.omnipod.R
class DeactivatePodActionFragment : ActionFragmentBase() {
override fun getText(): String = "[deactivate Pod]"
override fun getNextPageActionId(): Int = R.id.action_deactivatePodActionFragment_to_podDeactivatedInfoFragment
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.action
import info.nightscout.androidaps.plugins.pump.omnipod.R
class InsertCannulaActionFragment : ActionFragmentBase() {
override fun getText(): String = "[insert cannula]"
override fun getNextPageActionId(): Int = R.id.action_insertCannulaActionFragment_to_podReplacedInfoFragment
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.action
import info.nightscout.androidaps.plugins.pump.omnipod.R
class PairAndPrimePodActionFragment : ActionFragmentBase() {
override fun getText(): String = "[pair and prime Pod]"
override fun getNextPageActionId(): Int = R.id.action_pairAndPrimePodActionFragment_to_attachPodInfoFragment
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import info.nightscout.androidaps.plugins.pump.omnipod.R
class AttachPodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Attach the Pod"
override fun getNextPageActionId(): Int = R.id.action_attachPodInfoFragment_to_insertCannulaActionFragment
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import info.nightscout.androidaps.plugins.pump.omnipod.R
class DeactivatePodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Deactivate the Pod"
override fun getNextPageActionId(): Int = R.id.action_deactivatePodInfoFragment_to_deactivatePodActionFragment
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info
import info.nightscout.androidaps.plugins.pump.omnipod.R
class FillPodInfoFragment : InfoFragmentBase() {
override fun getText(): String = "Fill the Pod"
override fun getNextPageActionId(): Int = R.id.action_fillPodInfoFragment_to_pairAndPrimePodActionFragment
}

View file

@ -1,20 +1,12 @@
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.info;
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.fragment.FragmentBase
abstract class InfoFragmentBase : DaggerFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.omnipod_replace_pod_wizard_info_page_fragment, container, false)
abstract class InfoFragmentBase : FragmentBase() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -23,4 +15,8 @@ abstract class InfoFragmentBase : DaggerFragment() {
abstract fun getText(): String
override fun getLayout(): Int {
return R.layout.omnipod_replace_pod_wizard_info_page_fragment
}
}

View file

@ -1,5 +1,9 @@
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 getNextPageActionId(): Int = R.id.action_podDeactivatedInfoFragment_to_fillPodInfoFragment
}

View file

@ -1,5 +1,9 @@
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
}

View file

@ -2,11 +2,17 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:padding="10dp">
<include layout="@layout/omnipod_replace_pod_wizard_progress_indication" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
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"
@ -14,4 +20,6 @@
android:layout_height="wrap_content" />
</ScrollView>
<include layout="@layout/omnipod_replace_pod_wizard_nav_buttons" />
</LinearLayout>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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"
@ -8,14 +8,8 @@
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/omnipod_replace_pod_wizard_navigation_graph" />
</LinearLayout>
</FrameLayout>

View file

@ -2,11 +2,24 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/omnipod_wizard_info_page_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<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" />
</LinearLayout>

View file

@ -0,0 +1,20 @@
<?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="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/omnipod_replace_pod_wizard_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_replace_pod_wizard_button_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/omnipod_wizard_button_next" />
</LinearLayout>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/omnipod_replace_pod_wizard_progress_indication"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -230,6 +230,9 @@
<string name="omnipod_less_than_a_minute_ago">Less than a minute ago</string>
<string name="omnipod_composite_time">%1$s and %2$s</string>
<string name="omnipod_time_ago">%1$s ago</string>
<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>
<plurals name="omnipod_minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>