Skip to content

Commit

Permalink
Plug in new onboarding and profile configuration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes committed Jan 31, 2024
1 parent 9192df2 commit 6237fbb
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.app.splash

import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
Expand All @@ -13,6 +14,8 @@ import org.oppia.android.app.model.AppStartupState
import org.oppia.android.app.model.AppStartupState.BuildFlavorNoticeMode
import org.oppia.android.app.model.AppStartupState.StartupMode
import org.oppia.android.app.model.BuildFlavor
import org.oppia.android.app.model.Profile
import org.oppia.android.app.model.ProfileOnboardingState
import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment
import org.oppia.android.app.notice.BetaNoticeDialogFragment
import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment
Expand All @@ -24,13 +27,16 @@ import org.oppia.android.databinding.SplashActivityBinding
import org.oppia.android.domain.locale.LocaleController
import org.oppia.android.domain.onboarding.AppStartupStateController
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.domain.topic.PrimeTopicAssetsController
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProvider
import org.oppia.android.util.data.DataProviders.Companion.combineWith
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import javax.inject.Inject

private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog"
Expand All @@ -39,6 +45,7 @@ private const val GA_UPDATE_NOTICE_DIALOG_FRAGMENT_TAG = "general_availability_u
private const val SPLASH_INIT_STATE_DATA_PROVIDER_ID = "splash_init_state_data_provider"

/** The presenter for [SplashActivity]. */
@SuppressLint("CustomSplashScreen")
@ActivityScope
class SplashActivityPresenter @Inject constructor(
private val activity: AppCompatActivity,
Expand All @@ -49,7 +56,10 @@ class SplashActivityPresenter @Inject constructor(
private val localeController: LocaleController,
private val appLanguageLocaleHandler: AppLanguageLocaleHandler,
private val lifecycleSafeTimerFactory: LifecycleSafeTimerFactory,
private val currentBuildFlavor: BuildFlavor
private val currentBuildFlavor: BuildFlavor,
@EnableOnboardingFlowV2
private val enableOnboardingFlowV2: PlatformParameterValue<Boolean>,
private val profileManagementController: ProfileManagementController
) {
lateinit var startupMode: StartupMode

Expand Down Expand Up @@ -211,6 +221,9 @@ class SplashActivityPresenter @Inject constructor(
AutomaticAppDeprecationNoticeDialogFragment::newInstance
)
}
StartupMode.ONBOARDING_FLOW_V2 -> {
computeRoute()
}
else -> {
// In all other cases (including errors when the startup state fails to load or is
// defaulted), assume the user needs to be onboarded.
Expand All @@ -220,6 +233,65 @@ class SplashActivityPresenter @Inject constructor(
}
}

private fun computeRoute() {
// Use SplashActivityViewModel to retrieve the profile type and onboarding status
// Based on the returned profile information, compute route as follows:
when (getProfileOnboardingState()) {
ProfileOnboardingState.NEW_INSTALL -> {
// route to new app language selection screen
}
ProfileOnboardingState.SOLE_LEARNER_PROFILE -> {
// route = home screen
}
else -> {
// route = profile selection screen
if (enableOnboardingFlowV2.value) {
// new vs old profile chooser
}
activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity))
}
}
}

/** Returns the state of the app based on the number of existing profiles. */
private fun getProfileOnboardingState(): ProfileOnboardingState {
var profileList = listOf<Profile>()
profileManagementController.getProfiles().toLiveData().observe(
activity,
{ result ->
when (result) {
is AsyncResult.Success -> {
profileList = result.value
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"SplashActivityViewModel",
"Encountered unexpected non-successful result when fetching profiles",
result.error
)
}
else -> {} // no-op
}
}
)

return when {
profileList.size > 1 -> {
ProfileOnboardingState.MULTIPLE_PROFILES
}
profileList.size == 1 -> {
if (profileList.first().isAdmin && profileList.first().hasPin) {
ProfileOnboardingState.ADMIN_PROFILE_ONLY
} else {
ProfileOnboardingState.SOLE_LEARNER_PROFILE
}
}
else -> {
ProfileOnboardingState.NEW_INSTALL
}
}
}

private fun computeInitStateDataProvider(): DataProvider<SplashInitState> {
val startupStateDataProvider = appStartupStateController.getAppStartupState()
val systemAppLanguageLocaleDataProvider = translationController.getSystemLanguageLocale()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.oppia.android.util.data.DataProvider
import org.oppia.android.util.data.DataProviders.Companion.transform
import org.oppia.android.util.extensions.getStringFromBundle
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -23,7 +25,9 @@ class AppStartupStateController @Inject constructor(
private val oppiaLogger: OppiaLogger,
private val expirationMetaDataRetriever: ExpirationMetaDataRetriever,
private val machineLocale: OppiaLocale.MachineLocale,
private val currentBuildFlavor: BuildFlavor
private val currentBuildFlavor: BuildFlavor,
@EnableOnboardingFlowV2
private val enableOnboardingFlowV2: PlatformParameterValue<Boolean>
) {
private val onboardingFlowStore by lazy {
cacheStoreFactory.create("on_boarding_flow", OnboardingState.getDefaultInstance())
Expand Down Expand Up @@ -119,6 +123,9 @@ class AppStartupStateController @Inject constructor(
return when {
hasAppExpired() -> StartupMode.APP_IS_DEPRECATED
onboardingState.alreadyOnboardedApp -> StartupMode.USER_IS_ONBOARDED
enableOnboardingFlowV2.value -> {
StartupMode.ONBOARDING_FLOW_V2
}
else -> StartupMode.USER_NOT_YET_ONBOARDED
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAU
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_ONBOARDING_FLOW_V2_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAU
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_ONBOARDING_FLOW_V2_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAU
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_ONBOARDING_FLOW_V2_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
Expand All @@ -31,8 +30,8 @@ import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLes
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.oppia.android.app.model.Profile
import org.oppia.android.app.model.ProfileAvatar
import org.oppia.android.app.model.ProfileDatabase
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ProfileType
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.data.persistence.PersistentCacheStore
import org.oppia.android.data.persistence.PersistentCacheStore.PublishMode
Expand All @@ -30,6 +31,7 @@ import org.oppia.android.util.data.DataProviders.Companion.transformAsync
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.profile.DirectoryManagementUtil
import org.oppia.android.util.profile.ProfileNameValidator
Expand Down Expand Up @@ -89,7 +91,9 @@ class ProfileManagementController @Inject constructor(
private val enableLearnerStudyAnalytics: PlatformParameterValue<Boolean>,
@EnableLoggingLearnerStudyIds
private val enableLoggingLearnerStudyIds: PlatformParameterValue<Boolean>,
private val profileNameValidator: ProfileNameValidator
private val profileNameValidator: ProfileNameValidator,
@EnableOnboardingFlowV2
private val enableOnboardingFlowV2: PlatformParameterValue<Boolean>
) {
private var currentProfileId: Int = DEFAULT_LOGGED_OUT_INTERNAL_PROFILE_ID
private val profileDataStore =
Expand Down Expand Up @@ -290,6 +294,10 @@ class ProfileManagementController @Inject constructor(
avatarImageUri = imageUri
} else avatarColorRgb = colorRgb
}.build()

if (enableOnboardingFlowV2.value) {
this.profileType = computeProfileType(it)
}
}.build()

val wasProfileEverAdded = it.profilesCount > 0
Expand All @@ -306,6 +314,27 @@ class ProfileManagementController @Inject constructor(
}
}

private fun computeProfileType(profileDatabase: ProfileDatabase): ProfileType {
return if (isAdminWithPin(profileDatabase)) {
ProfileType.SUPERVISOR
} else {
if (profileDatabase.profilesCount == 1) {
ProfileType.SOLE_LEARNER
} else {
ProfileType.ADDITIONAL_LEARNER
}
}
}

private fun isAdminWithPin(profileDatabase: ProfileDatabase): Boolean {
profileDatabase.profilesMap.values.forEach {
if (it.isAdmin && it.hasPin) {
return true
}
}
return false
}

/**
* Updates the profile avatar of an existing profile.
*
Expand Down Expand Up @@ -684,7 +713,7 @@ class ProfileManagementController @Inject constructor(
return@createInMemoryDataProviderAsync AsyncResult.Success(0)
}
AsyncResult.Failure(
ProfileNotFoundException(
ProfileManagementController.ProfileNotFoundException(
"ProfileId ${profileId.internalId} is" +
" not associated with an existing profile"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_
import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_ONBOARDING_FLOW_V2_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation
Expand Down

0 comments on commit 6237fbb

Please sign in to comment.