diff --git a/omnipod/src/main/AndroidManifest.xml b/omnipod/src/main/AndroidManifest.xml index ebf23405da..9171091799 100644 --- a/omnipod/src/main/AndroidManifest.xml +++ b/omnipod/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ + diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodModule.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodModule.kt index 225b1bb5ca..f7d0b6a9e9 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodModule.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodModule.kt @@ -14,6 +14,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitPod import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.InitPodRefreshAction 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 javax.inject.Scope @Module @Suppress("unused") @@ -24,6 +26,10 @@ abstract class OmnipodModule { abstract fun contributesPodManagementActivity(): PodManagementActivity @ContributesAndroidInjector abstract fun contributesPodHistoryActivity(): PodHistoryActivity + @ActivityScope + @ContributesAndroidInjector(modules = [OmnipodWizardModule::class]) + abstract fun contributesWizardActivity(): WizardActivity + // Fragments @ContributesAndroidInjector abstract fun initActionFragment(): InitActionFragment @ContributesAndroidInjector abstract fun removeActionFragment(): RemoveActionFragment @@ -39,7 +45,20 @@ abstract class OmnipodModule { @ContributesAndroidInjector abstract fun rlHistoryItemOmnipod(): RLHistoryItemOmnipod companion object { + @Provides fun podStateManagerProvider(aapsPodStateManager: AapsPodStateManager): PodStateManager = aapsPodStateManager } } + +// TODO: These annotations could be used globally -> move to core or app + +@MustBeDocumented +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class ActivityScope + +@MustBeDocumented +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class FragmentScope diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodWizardModule.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodWizardModule.kt new file mode 100644 index 0000000000..8d7c936747 --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dagger/OmnipodWizardModule.kt @@ -0,0 +1,49 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dagger + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import dagger.Binds +import dagger.MapKey +import dagger.Module +import dagger.android.ContributesAndroidInjector +import dagger.multibindings.IntoMap +import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.WizardFragment1 +import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2.WizardViewModel1 +import javax.inject.Inject +import javax.inject.Provider +import kotlin.reflect.KClass + +@Suppress("UNCHECKED_CAST") +class ViewModelFactory @Inject constructor( + private val viewModels: MutableMap, @JvmSuppressWildcards Provider> +) : ViewModelProvider.Factory { + override fun create(modelClass: Class): T = viewModels[modelClass]?.get() as T +} + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@kotlin.annotation.Retention(AnnotationRetention.RUNTIME) +@MapKey +internal annotation class ViewModelKey(val value: KClass) + +@Module +abstract class OmnipodWizardModule { + + @Binds + abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory + + // VIEW MODELS + @Binds + @IntoMap + @ViewModelKey(WizardViewModel1::class) + internal abstract fun bindWizardViewModel1(viewModel: WizardViewModel1): ViewModel + + // Add the rest of the view models + + // FRAGMENTS + + @FragmentScope + @ContributesAndroidInjector + internal abstract fun contributesWizardFragment1(): WizardFragment1 + + // Add the rest of the fragments +} \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardActivity.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardActivity.kt new file mode 100644 index 0000000000..da6611dbb1 --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardActivity.kt @@ -0,0 +1,13 @@ +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_wizard_activity) // TODO: replace with DataBindingUtil.setContentView + } +} \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardFragment1.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardFragment1.kt new file mode 100644 index 0000000000..77100a9259 --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/wizard2/WizardFragment1.kt @@ -0,0 +1,43 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard2 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.fragment.app.viewModels +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import dagger.android.support.DaggerFragment +import info.nightscout.androidaps.plugins.pump.omnipod.R +import javax.inject.Inject + +class WizardFragment1 : DaggerFragment() { + + @Inject + lateinit var viewModelFactory: ViewModelProvider.Factory + + lateinit var viewModel: WizardViewModel1 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + val vm: WizardViewModel1 by viewModels { viewModelFactory } + this.viewModel = vm + vm.doSomethingForTesting() + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = inflater.inflate(R.layout.omnipod_wizard_fragment1, container, false) + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + view.findViewById