Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.profile.toProfileIdPreservingZero

/** [ViewModel] for the recycler view in [AdministratorControlsFragment]. */
class AdministratorControlsDownloadPermissionsViewModel(
Expand All @@ -30,7 +31,7 @@ class AdministratorControlsDownloadPermissionsViewModel(
/** Called when topic wifi update permission changes. */
fun onTopicWifiUpdatePermissionChanged() {
profileManagementController.updateWifiPermissionDeviceSettings(
userProfileId,
userProfileId.toProfileIdPreservingZero(),
!isTopicWifiUpdatePermission.get()!!
).toLiveData()
.observe(
Expand All @@ -50,7 +51,7 @@ class AdministratorControlsDownloadPermissionsViewModel(
/** Called when topic auto update permission changes. */
fun onTopicAutoUpdatePermissionChanged() {
profileManagementController.updateTopicAutomaticallyPermissionDeviceSettings(
userProfileId,
userProfileId.toProfileIdPreservingZero(),
!isTopicAutoUpdatePermission.get()!!
).toLiveData().observe(
fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import org.oppia.android.util.parser.html.TopicHtmlParserEntityType
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** Test tag for the classroom list screen. */
Expand Down Expand Up @@ -166,7 +167,9 @@ class ClassroomListFragmentPresenter @Inject constructor(
}
)

profileManagementController.getProfile(profileId).toLiveData().observe(fragment) {
profileManagementController.getProfile(
profileId.toProfileIdPreservingZero()
).toLiveData().observe(fragment) {
processProfileResult(it)
}

Expand All @@ -186,7 +189,9 @@ class ClassroomListFragmentPresenter @Inject constructor(
/** Triggers the view model to update the topic list. */
fun onClassroomSummaryClicked(classroomSummary: ClassroomSummary) {
val classroomId = classroomSummary.classroomId
profileManagementController.updateLastSelectedClassroomId(profileId, classroomId)
profileManagementController.updateLastSelectedClassroomId(
profileId.toProfileIdPreservingZero(), classroomId
)
classroomListViewModel.fetchAndUpdateTopicList(classroomId)
}

Expand Down Expand Up @@ -287,14 +292,18 @@ class ClassroomListFragmentPresenter @Inject constructor(
// These asynchronous API calls do not block or wait for their results. They execute
// in the background and have minimal chances of interfering with the synchronous
// `handleBackPress` call below.
profileManagementController.markProfileOnboardingEnded(profileId)
profileManagementController.markProfileOnboardingEnded(
profileId.toProfileIdPreservingZero()
)
appStartupStateController.markOnboardingFlowCompleted(profileId)
}
profileType == ProfileType.ADDITIONAL_LEARNER &&
!profile.completedProfileOnboarding -> {
// Additional learners complete only profile onboarding, since they will never be the
// first profile in the app.
profileManagementController.markProfileOnboardingEnded(profileId)
profileManagementController.markProfileOnboardingEnded(
profileId.toProfileIdPreservingZero()
)
Comment on lines +305 to +307

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it is okay to use the toProfileIdUnsetIfZero util because an additional profile can never be zero(since they must be created by an existing admin).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto in the HomeFragmentPresenter

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Switched to toProfileIdUnsetIfZero in both ClassroomListFragmentPresenter and HomeFragmentPresenter for markProfileOnboardingEnded calls since non-admin profiles can never have internalId=0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please recheck, only the ADDITIONAL_LEARNER typecase should use toProfileIdUnsetIfZero. The SOLE_LEARNER case above is also an admin and can be zero. This is a new pathway, and is not well documented yet, so apologies for the confusion. Please fix that in the HomeFragmentPresenter as well.

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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.profile.toProfileIdPreservingZero

private const val PROFILE_AND_PROMOTED_ACTIVITY_COMBINED_PROVIDER_ID =
"profile+promotedActivityList"
Expand Down Expand Up @@ -74,7 +75,7 @@ class ClassroomListViewModel(
val selectedClassroomId = ObservableField("")

private val profileDataProvider: DataProvider<Profile> by lazy {
profileManagementController.getProfile(profileId)
profileManagementController.getProfile(profileId.toProfileIdPreservingZero())
}

private val promotedActivityListSummaryDataProvider: DataProvider<PromotedActivityList> by lazy {
Expand Down Expand Up @@ -304,7 +305,9 @@ class ClassroomListViewModel(
fun fetchAndUpdateTopicList(classroomId: String = "") {
if (classroomId.isBlank()) {
// Retrieve the last selected classroom ID if no specific classroom ID is provided.
profileManagementController.retrieveLastSelectedClassroomId(profileId)
profileManagementController.retrieveLastSelectedClassroomId(
profileId.toProfileIdPreservingZero()
)
.toLiveData().observe(fragment) { lastSelectedClassroomIdResult ->
when (lastSelectedClassroomIdResult) {
is AsyncResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.platformparameter.EnableMultipleClassrooms
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import org.oppia.android.util.statusbar.StatusBarColor
import javax.inject.Inject

Expand Down Expand Up @@ -122,7 +123,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor(

private fun getProfileData(): LiveData<Profile> {
return Transformations.map(
profileManagementController.getProfile(profileId).toLiveData(),
profileManagementController.getProfile(profileId.toProfileIdPreservingZero()).toLiveData(),
::processGetProfileResult
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.oppia.android.util.parser.html.TopicHtmlParserEntityType
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** The presenter for [HomeFragment]. */
Expand Down Expand Up @@ -112,7 +113,9 @@ class HomeFragmentPresenter @Inject constructor(
it.viewModel = homeViewModel
}

profileManagementController.getProfile(profileId).toLiveData().observe(fragment) {
profileManagementController.getProfile(
profileId.toProfileIdPreservingZero()
).toLiveData().observe(fragment) {
processProfileResult(it)
}

Expand All @@ -137,14 +140,18 @@ class HomeFragmentPresenter @Inject constructor(
// These asynchronous API calls do not block or wait for their results. They execute
// in the background and have minimal chances of interfering with the synchronous
// `handleBackPress` call below.
profileManagementController.markProfileOnboardingEnded(profileId)
profileManagementController.markProfileOnboardingEnded(
profileId.toProfileIdPreservingZero()
)
appStartupStateController.markOnboardingFlowCompleted(profileId)
}
profileType == ProfileType.ADDITIONAL_LEARNER &&
!profile.completedProfileOnboarding -> {
// Additional learners only end profile onboarding, since they will never be the first
// profile in the app.
profileManagementController.markProfileOnboardingEnded(profileId)
profileManagementController.markProfileOnboardingEnded(
profileId.toProfileIdPreservingZero()
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.parser.html.StoryHtmlParserEntityType
import org.oppia.android.util.parser.html.TopicHtmlParserEntityType
import org.oppia.android.util.profile.toProfileIdPreservingZero

private const val PROFILE_AND_PROMOTED_ACTIVITY_COMBINED_PROVIDER_ID =
"profile+promotedActivityList"
Expand Down Expand Up @@ -70,7 +71,7 @@ class HomeViewModel(
val isProgressBarVisible = ObservableField(true)

private val profileDataProvider: DataProvider<Profile> by lazy {
profileManagementController.getProfile(profileId)
profileManagementController.getProfile(profileId.toProfileIdPreservingZero())
}

private val promotedActivityListSummaryDataProvider: DataProvider<PromotedActivityList> by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.oppia.android.app.ui.R
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.util.extensions.putProtoExtra
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** Argument key for [ProfileChooserActivity] intent parameters. */
Expand Down Expand Up @@ -87,7 +88,7 @@ class AdminIntroFragmentPresenter @Inject constructor(

createComposeView()

profileManagementController.markProfileOnboardingStarted(profileId)
profileManagementController.markProfileOnboardingStarted(profileId.toProfileIdPreservingZero())

return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import org.oppia.android.util.platformparameter.EnableMultipleClassrooms
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** The presenter for [AudioLanguageFragment]. */
Expand Down Expand Up @@ -173,7 +174,9 @@ class AudioLanguageFragmentPresenter @Inject constructor(
) {
val audioLanguageSelection =
AudioTranslationLanguageSelection.newBuilder().setSelectedLanguage(selectedLanguage).build()
translationController.updateAudioTranslationContentLanguage(profileId, audioLanguageSelection)
translationController.updateAudioTranslationContentLanguage(
profileId.toProfileIdPreservingZero(), audioLanguageSelection
)
.toLiveData().observe(fragment) { result ->
when (result) {
is AsyncResult.Success -> {
Expand Down Expand Up @@ -214,7 +217,9 @@ class AudioLanguageFragmentPresenter @Inject constructor(
}

private fun logInToProfile(profileId: LegacyProfileId) {
profileManagementController.loginToProfile(profileId).toLiveData().observe(
profileManagementController.loginToProfile(
profileId.toProfileIdPreservingZero()
).toLiveData().observe(
fragment,
{ result ->
if (result is AsyncResult.Success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.parser.image.ImageLoader
import org.oppia.android.util.parser.image.ImageViewTarget
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** Presenter for [CreateProfileFragment]. */
Expand Down Expand Up @@ -152,7 +153,7 @@ class CreateProfileFragmentPresenter @Inject constructor(

private fun updateProfileDetails(profileName: String) {
profileManagementController.updateNewProfileDetails(
profileId = profileId,
profileId = profileId.toProfileIdPreservingZero(),
profileType = profileType,
avatarImagePath = selectedImageUri,
colorRgb = selectUniqueRandomColor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.ui.R
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** The presenter for [IntroFragment]. */
Expand Down Expand Up @@ -44,7 +45,7 @@ class IntroFragmentPresenter @Inject constructor(

setLearnerName(profileNickname)

profileManagementController.markProfileOnboardingStarted(profileId)
profileManagementController.markProfileOnboardingStarted(profileId.toProfileIdPreservingZero())

if (parentScreen != IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN) {
binding.onboardingStepsCount?.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

private const val ONBOARDING_FRAGMENT_SAVED_STATE_KEY = "OnboardingFragment.saved_state"
Expand Down Expand Up @@ -151,7 +152,9 @@ class OnboardingFragmentPresenter @Inject constructor(

private fun updateSelectedLanguage(selectedLanguage: OppiaLanguage) {
val selection = AppLanguageSelection.newBuilder().setSelectedLanguage(selectedLanguage).build()
translationController.updateAppLanguage(profileId, selection).toLiveData()
translationController.updateAppLanguage(
profileId.toProfileIdPreservingZero(), selection
).toLiveData()
.observe(
fragment,
{ result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** The presenter for [AppLanguageFragment]. */
Expand Down Expand Up @@ -148,7 +149,7 @@ class AppLanguageFragmentPresenter @Inject constructor(

private fun updateSelectedLanguage(selectedLanguage: OppiaLanguage) {
val selection = AppLanguageSelection.newBuilder().setSelectedLanguage(selectedLanguage).build()
translationController.updateAppLanguage(profileId, selection)
translationController.updateAppLanguage(profileId.toProfileIdPreservingZero(), selection)
}

private fun updateAppLanguage(appLanguage: OppiaLanguage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** The presenter for [AppLanguageFragment]. */
Expand Down Expand Up @@ -88,7 +89,9 @@ class AppLanguageFragmentPresenterV1 @Inject constructor(
selectedLanguage = oppiaLanguage
}.build()

translationController.updateAppLanguage(profileId, selection).toLiveData().observe(fragment) {
translationController.updateAppLanguage(
profileId.toProfileIdPreservingZero(), selection
).toLiveData().observe(fragment) {
when (it) {
is AsyncResult.Success -> appLanguage = oppiaLanguage
is AsyncResult.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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.toLiveData
import org.oppia.android.util.profile.toProfileIdPreservingZero
import javax.inject.Inject

/** ViewModel for managing language selection in [AudioLanguageFragment]. */
Expand Down Expand Up @@ -89,7 +90,7 @@ class AudioLanguageSelectionViewModel @Inject constructor(
}

private val languagePreselectionProvider: DataProvider<OppiaLanguage> by lazy {
translationController.getAudioLanguagePreselection(profileId)
translationController.getAudioLanguagePreselection(profileId.toProfileIdPreservingZero())
}

/** Receives and sets the current profileId in this viewModel. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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.profile.toProfileIdPreservingZero
import javax.inject.Inject

private const val OPTIONS_ITEM_VIEW_MODEL_APP_AUDIO_LANGUAGE_PROVIDER_ID =
Expand Down Expand Up @@ -69,11 +70,13 @@ class OptionControlsViewModel @Inject constructor(

private fun createOptionsItemViewModelProvider(): DataProvider<List<OptionsItemViewModel>> {
val appAudioLangProvider =
translationController.getAppLanguage(profileId).combineWith(
profileManagementController.getAudioLanguage(profileId),
translationController.getAppLanguage(profileId.toProfileIdPreservingZero()).combineWith(
profileManagementController.getAudioLanguage(profileId.toProfileIdPreservingZero()),
OPTIONS_ITEM_VIEW_MODEL_APP_AUDIO_LANGUAGE_PROVIDER_ID
) { appLanguage, audioLanguage -> appLanguage to audioLanguage }
return profileManagementController.getProfile(profileId).combineWith(
return profileManagementController.getProfile(
profileId.toProfileIdPreservingZero()
).combineWith(
appAudioLangProvider, OPTIONS_ITEM_VIEW_MODEL_LIST_PROVIDER_ID
) { profile, (appLang, audioLang) -> processViewModelList(profile, appLang, audioLang) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import org.oppia.android.util.profile.toProfileIdPreservingZero
import java.security.InvalidParameterException
import javax.inject.Inject

Expand Down Expand Up @@ -199,7 +200,9 @@ class OptionsFragmentPresenter @Inject constructor(
* @param textSize new textSize to be set as current
*/
fun updateReadingTextSize(textSize: ReadingTextSize) {
val sizeUpdateResult = profileManagementController.updateReadingTextSize(profileId, textSize)
val sizeUpdateResult = profileManagementController.updateReadingTextSize(
profileId.toProfileIdPreservingZero(), textSize
)
sizeUpdateResult.toLiveData().observe(fragment) {
when (it) {
is AsyncResult.Failure -> {
Expand All @@ -225,7 +228,9 @@ class OptionsFragmentPresenter @Inject constructor(
selectedLanguageValue = oppiaLanguage.number
}.build()

translationController.updateAppLanguage(profileId, selection).toLiveData().observe(fragment) {
translationController.updateAppLanguage(
profileId.toProfileIdPreservingZero(), selection
).toLiveData().observe(fragment) {
when (it) {
is AsyncResult.Success -> appLanguage = oppiaLanguage
is AsyncResult.Failure ->
Expand All @@ -245,7 +250,9 @@ class OptionsFragmentPresenter @Inject constructor(
*/
fun updateAudioLanguage(audioLanguage: AudioLanguage) {
val updateLanguageResult =
profileManagementController.updateAudioLanguage(profileId, audioLanguage)
profileManagementController.updateAudioLanguage(
profileId.toProfileIdPreservingZero(), audioLanguage
)
updateLanguageResult.toLiveData().observe(fragment) {
when (it) {
is AsyncResult.Success -> this.audioLanguage = audioLanguage
Expand Down
Loading
Loading