1
1
package org.oppia.android.app.splash
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.content.ActivityNotFoundException
4
5
import android.content.Intent
5
6
import android.net.Uri
@@ -13,6 +14,8 @@ import org.oppia.android.app.model.AppStartupState
13
14
import org.oppia.android.app.model.AppStartupState.BuildFlavorNoticeMode
14
15
import org.oppia.android.app.model.AppStartupState.StartupMode
15
16
import org.oppia.android.app.model.BuildFlavor
17
+ import org.oppia.android.app.model.Profile
18
+ import org.oppia.android.app.model.ProfileOnboardingState
16
19
import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment
17
20
import org.oppia.android.app.notice.BetaNoticeDialogFragment
18
21
import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment
@@ -24,13 +27,16 @@ import org.oppia.android.databinding.SplashActivityBinding
24
27
import org.oppia.android.domain.locale.LocaleController
25
28
import org.oppia.android.domain.onboarding.AppStartupStateController
26
29
import org.oppia.android.domain.oppialogger.OppiaLogger
30
+ import org.oppia.android.domain.profile.ProfileManagementController
27
31
import org.oppia.android.domain.topic.PrimeTopicAssetsController
28
32
import org.oppia.android.domain.translation.TranslationController
29
33
import org.oppia.android.util.data.AsyncResult
30
34
import org.oppia.android.util.data.DataProvider
31
35
import org.oppia.android.util.data.DataProviders.Companion.combineWith
32
36
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
33
37
import org.oppia.android.util.locale.OppiaLocale
38
+ import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
39
+ import org.oppia.android.util.platformparameter.PlatformParameterValue
34
40
import javax.inject.Inject
35
41
36
42
private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = " auto_deprecation_notice_dialog"
@@ -39,6 +45,7 @@ private const val GA_UPDATE_NOTICE_DIALOG_FRAGMENT_TAG = "general_availability_u
39
45
private const val SPLASH_INIT_STATE_DATA_PROVIDER_ID = " splash_init_state_data_provider"
40
46
41
47
/* * The presenter for [SplashActivity]. */
48
+ @SuppressLint(" CustomSplashScreen" )
42
49
@ActivityScope
43
50
class SplashActivityPresenter @Inject constructor(
44
51
private val activity : AppCompatActivity ,
@@ -49,7 +56,10 @@ class SplashActivityPresenter @Inject constructor(
49
56
private val localeController : LocaleController ,
50
57
private val appLanguageLocaleHandler : AppLanguageLocaleHandler ,
51
58
private val lifecycleSafeTimerFactory : LifecycleSafeTimerFactory ,
52
- private val currentBuildFlavor : BuildFlavor
59
+ private val currentBuildFlavor : BuildFlavor ,
60
+ @EnableOnboardingFlowV2
61
+ private val enableOnboardingFlowV2 : PlatformParameterValue <Boolean >,
62
+ private val profileManagementController : ProfileManagementController
53
63
) {
54
64
lateinit var startupMode: StartupMode
55
65
@@ -211,6 +221,9 @@ class SplashActivityPresenter @Inject constructor(
211
221
AutomaticAppDeprecationNoticeDialogFragment ::newInstance
212
222
)
213
223
}
224
+ StartupMode .ONBOARDING_FLOW_V2 -> {
225
+ computeRoute()
226
+ }
214
227
else -> {
215
228
// In all other cases (including errors when the startup state fails to load or is
216
229
// defaulted), assume the user needs to be onboarded.
@@ -220,6 +233,65 @@ class SplashActivityPresenter @Inject constructor(
220
233
}
221
234
}
222
235
236
+ private fun computeRoute () {
237
+ // Use SplashActivityViewModel to retrieve the profile type and onboarding status
238
+ // Based on the returned profile information, compute route as follows:
239
+ when (getProfileOnboardingState()) {
240
+ ProfileOnboardingState .NEW_INSTALL -> {
241
+ // route to new app language selection screen
242
+ }
243
+ ProfileOnboardingState .SOLE_LEARNER_PROFILE -> {
244
+ // route = home screen
245
+ }
246
+ else -> {
247
+ // route = profile selection screen
248
+ if (enableOnboardingFlowV2.value) {
249
+ // new vs old profile chooser
250
+ }
251
+ activity.startActivity(ProfileChooserActivity .createProfileChooserActivity(activity))
252
+ }
253
+ }
254
+ }
255
+
256
+ /* * Returns the state of the app based on the number of existing profiles. */
257
+ private fun getProfileOnboardingState (): ProfileOnboardingState {
258
+ var profileList = listOf<Profile >()
259
+ profileManagementController.getProfiles().toLiveData().observe(
260
+ activity,
261
+ { result ->
262
+ when (result) {
263
+ is AsyncResult .Success -> {
264
+ profileList = result.value
265
+ }
266
+ is AsyncResult .Failure -> {
267
+ oppiaLogger.e(
268
+ " SplashActivityViewModel" ,
269
+ " Encountered unexpected non-successful result when fetching profiles" ,
270
+ result.error
271
+ )
272
+ }
273
+ else -> {} // no-op
274
+ }
275
+ }
276
+ )
277
+
278
+ return when {
279
+ profileList.size > 1 -> {
280
+ ProfileOnboardingState .MULTIPLE_PROFILES
281
+ }
282
+ profileList.size == 1 -> {
283
+ if (profileList.first().isAdmin && profileList.first().hasPin) {
284
+ ProfileOnboardingState .ADMIN_PROFILE_ONLY
285
+ } else {
286
+ ProfileOnboardingState .SOLE_LEARNER_PROFILE
287
+ }
288
+ }
289
+ else -> {
290
+ ProfileOnboardingState .NEW_INSTALL
291
+ }
292
+ }
293
+ }
294
+
223
295
private fun computeInitStateDataProvider (): DataProvider <SplashInitState > {
224
296
val startupStateDataProvider = appStartupStateController.getAppStartupState()
225
297
val systemAppLanguageLocaleDataProvider = translationController.getSystemLanguageLocale()
0 commit comments