From bc817d10f91e3bc038bd925f51897c052f1e9f7f Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 28 Sep 2020 09:56:39 +0200 Subject: [PATCH] More WIP on new Omnipod wizard --- app/build.gradle | 2 + omnipod/build.gradle | 3 + .../ui/wizard2/ReplacePodWizardActivity.kt | 74 +++++++++++++------ .../ui/wizard2/fragment/FragmentBase.kt | 68 +++++++++++------ .../fragment/action/ActionFragmentBase.kt | 2 +- .../action/DeactivatePodActionFragment.kt | 4 + .../action/InsertCannulaActionFragment.kt | 4 + .../action/PairAndPrimePodActionFragment.kt | 4 + .../fragment/info/AttachPodInfoFragment.kt | 4 + .../info/DeactivatePodInfoFragment.kt | 4 + .../fragment/info/FillPodInfoFragment.kt | 4 + .../wizard2/fragment/info/InfoFragmentBase.kt | 7 +- .../info/PodDeactivatedInfoFragment.kt | 6 +- .../fragment/info/PodReplacedInfoFragment.kt | 6 +- ...eplace_pod_wizard_action_page_fragment.xml | 24 ++---- .../omnipod_replace_pod_wizard_activity.xml | 7 +- ...nipod_replace_pod_wizard_base_fragment.xml | 30 ++++++++ ..._replace_pod_wizard_info_page_fragment.xml | 24 ++---- ...replace_pod_wizard_progress_indication.xml | 14 ++-- omnipod/src/main/res/values/colors.xml | 1 + omnipod/src/main/res/values/strings.xml | 4 + omnipod/src/main/res/values/styles.xml | 10 +++ 22 files changed, 207 insertions(+), 99 deletions(-) create mode 100644 omnipod/src/main/res/layout/omnipod_replace_pod_wizard_base_fragment.xml diff --git a/app/build.gradle b/app/build.gradle index 1b2b39485a..eef64b9eed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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}" diff --git a/omnipod/build.gradle b/omnipod/build.gradle index cf19262acc..552e74e3c7 100644 --- a/omnipod/build.gradle +++ b/omnipod/build.gradle @@ -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" diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/ReplacePodWizardActivity.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/ReplacePodWizardActivity.kt index 0dacf911e8..1912162bff 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/ReplacePodWizardActivity.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/ReplacePodWizardActivity.kt @@ -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 + } \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/fragment/FragmentBase.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/fragment/FragmentBase.kt index 62218df708..9b6cfa57bb 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/fragment/FragmentBase.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/fragment/FragmentBase.kt @@ -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(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