diff --git a/app/BUILD.bazel b/app/BUILD.bazel index 32677435108..ba205a1040c 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -814,6 +814,7 @@ kt_android_library( "//utility/src/main/java/org/oppia/android/util/extensions:bundle_extensions", "//utility/src/main/java/org/oppia/android/util/parser/image:image_loader", "//utility/src/main/java/org/oppia/android/util/parser/image:image_parsing_annonations", + "//utility/src/main/java/org/oppia/android/util/profile:current_user_profile_id_intent_decorator", "//utility/src/main/java/org/oppia/android/util/statusbar:status_bar_color", ], ) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt index 74e0f97ae89..ebdd11f3456 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt @@ -8,7 +8,7 @@ import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.administratorcontrols.appversion.AppVersionActivity import org.oppia.android.app.administratorcontrols.learneranalytics.ProfileAndDeviceIdActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.ADMINISTRATOR_CONTROLS_ACTIVITY import org.oppia.android.app.settings.profile.ProfileEditFragment import org.oppia.android.app.settings.profile.ProfileListActivity @@ -16,6 +16,8 @@ import org.oppia.android.app.settings.profile.ProfileListFragment import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.extensions.getStringFromBundle import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Argument key for of title for selected controls in [AdministratorControlsActivity]. */ @@ -64,6 +66,7 @@ class AdministratorControlsActivity : lateinit var resourceHandler: AppLanguageResourceHandler private lateinit var lastLoadedFragment: String private var isProfileDeletionDialogVisible: Boolean = false + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -78,29 +81,30 @@ class AdministratorControlsActivity : // TODO(#661): Change the default fragment in the right hand side to be EditAccount fragment in the case of multipane controls. PROFILE_LIST_FRAGMENT } - val selectedProfileId = savedInstanceState?.getInt(SELECTED_PROFILE_ID_SAVED_KEY) ?: -1 + profileId = savedInstanceState?.extractCurrentUserProfileId() + ?: ProfileId.newBuilder().setInternalId(-1).build() administratorControlsActivityPresenter.handleOnCreate( extraControlsTitle, lastLoadedFragment, - selectedProfileId, + profileId, isProfileDeletionDialogVisible ) title = resourceHandler.getStringInLocale(R.string.administrator_controls) } override fun routeToAppVersion() { - startActivity(AppVersionActivity.createAppVersionActivityIntent(this)) + startActivity(AppVersionActivity.createAppVersionActivityIntent(this, profileId)) } override fun routeToProfileList() { - startActivity(ProfileListActivity.createProfileListActivityIntent(this)) + startActivity(ProfileListActivity.createProfileListActivityIntent(this, profileId)) } override fun routeToLearnerAnalytics() { - startActivity(ProfileAndDeviceIdActivity.createIntent(this)) + startActivity(ProfileAndDeviceIdActivity.createIntent(this, profileId)) } - override fun loadProfileEdit(profileId: Int, profileName: String) { + override fun loadProfileEdit(profileId: ProfileId, profileName: String) { lastLoadedFragment = PROFILE_EDIT_FRAGMENT administratorControlsActivityPresenter.loadProfileEdit(profileId, profileName) } @@ -112,17 +116,12 @@ class AdministratorControlsActivity : companion object { /** Returns an [Intent] to start this activity. */ - fun createAdministratorControlsActivityIntent(context: Context, profileId: Int?): Intent { + fun createAdministratorControlsActivityIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, AdministratorControlsActivity::class.java) - intent.putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) intent.decorateWithScreenName(ADMINISTRATOR_CONTROLS_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } - - /** Returns the argument key used to specify the user's internal profile ID. */ - fun getIntentKey(): String { - return NAVIGATION_PROFILE_ID_ARGUMENT_KEY - } } override fun onBackPressed() { diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt index 0dfe9b50b9c..9cb2a6ee581 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt @@ -10,11 +10,13 @@ import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.administratorcontrols.appversion.AppVersionFragment import org.oppia.android.app.administratorcontrols.learneranalytics.ProfileAndDeviceIdFragment import org.oppia.android.app.drawer.NavigationDrawerFragment +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.settings.profile.LoadProfileEditDeletionDialogListener import org.oppia.android.app.settings.profile.ProfileEditFragment import org.oppia.android.app.settings.profile.ProfileListFragment import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.databinding.AdministratorControlsActivityBinding +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** The presenter for [AdministratorControlsActivity]. */ @@ -28,7 +30,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( private lateinit var binding: AdministratorControlsActivityBinding private lateinit var lastLoadedFragment: String - private var selectedProfileId: Int = -1 + private lateinit var selectedProfileId: ProfileId private lateinit var extraControlsTitle: String private var isProfileDeletionDialogVisible: Boolean = false @@ -36,7 +38,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( fun handleOnCreate( extraControlsTitle: String?, lastLoadedFragment: String, - selectedProfileId: Int, + selectedProfileId: ProfileId, isProfileDeletionDialogVisible: Boolean ) { binding = DataBindingUtil.setContentView( @@ -70,7 +72,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( profileId = profileId, profileName = extraControlsTitle ) - if (isProfileDeletionDialogVisible && profileId != 0) { + if (isProfileDeletionDialogVisible && profileId.internalId != 0) { val fragment = activity.supportFragmentManager.findFragmentById( R.id.administrator_controls_fragment_multipane_placeholder ) @@ -144,7 +146,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( } /** Loads the [ProfileEditFragment] when the user clicks on a profile in tablet multipane mode. */ - fun loadProfileEdit(profileId: Int, profileName: String) { + fun loadProfileEdit(profileId: ProfileId, profileName: String) { lastLoadedFragment = PROFILE_EDIT_FRAGMENT selectedProfileId = profileId extraControlsTitle = profileName @@ -209,6 +211,6 @@ class AdministratorControlsActivityPresenter @Inject constructor( isProfileDeletionDialogVisible?.let { outState.putBoolean(IS_PROFILE_DELETION_DIALOG_VISIBLE_KEY, it) } - selectedProfileId?.let { outState.putInt(SELECTED_PROFILE_ID_SAVED_KEY, it) } + selectedProfileId?.let { outState.decorateWithUserProfileId(it) } } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt index 52c193d536c..4289734297d 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt @@ -13,7 +13,6 @@ import org.oppia.android.app.administratorcontrols.administratorcontrolsitemview import org.oppia.android.app.administratorcontrols.administratorcontrolsitemviewmodel.AdministratorControlsItemViewModel import org.oppia.android.app.administratorcontrols.administratorcontrolsitemviewmodel.AdministratorControlsProfileAndDeviceIdViewModel import org.oppia.android.app.administratorcontrols.administratorcontrolsitemviewmodel.AdministratorControlsProfileViewModel -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.ProfileId import org.oppia.android.app.recyclerview.BindableAdapter @@ -24,6 +23,7 @@ import org.oppia.android.databinding.AdministratorControlsFragmentBinding import org.oppia.android.databinding.AdministratorControlsGeneralViewBinding import org.oppia.android.databinding.AdministratorControlsLearnerAnalyticsViewBinding import org.oppia.android.databinding.AdministratorControlsProfileViewBinding +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import java.security.InvalidParameterException import javax.inject.Inject @@ -36,7 +36,6 @@ class AdministratorControlsFragmentPresenter @Inject constructor( ) { private lateinit var binding: AdministratorControlsFragmentBinding private lateinit var linearLayoutManager: LinearLayoutManager - private var internalProfileId: Int = -1 private lateinit var profileId: ProfileId @Inject @@ -56,8 +55,7 @@ class AdministratorControlsFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) - internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId = activity.intent.extractCurrentUserProfileId() administratorControlsViewModel.setProfileId(profileId) linearLayoutManager = LinearLayoutManager(activity.applicationContext) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt index 0a8157990e7..a3cdec22d43 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt @@ -1,7 +1,9 @@ package org.oppia.android.app.administratorcontrols +import org.oppia.android.app.model.ProfileId + /** Listener for when an activity should load [ProfileEditFragment]. */ interface LoadProfileEditListener { /** Inflates [ProfileEditFragment] as part of a tablet mode a multipane fragment. */ - fun loadProfileEdit(profileId: Int, profileName: String) + fun loadProfileEdit(profileId: ProfileId, profileName: String) } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt index ec5dce2c206..7e4f13c900a 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt @@ -6,8 +6,10 @@ import android.os.Bundle import android.view.MenuItem import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.APP_VERSION_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** Activity for App Version. */ @@ -30,9 +32,10 @@ class AppVersionActivity : InjectableAutoLocalizedAppCompatActivity() { companion object { /** Returns an [Intent] to start this activity. */ - fun createAppVersionActivityIntent(context: Context): Intent { + fun createAppVersionActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, AppVersionActivity::class.java).apply { decorateWithScreenName(APP_VERSION_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt index b890f3ebbb9..715856cb3be 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt @@ -6,8 +6,10 @@ import android.os.Bundle import android.view.MenuItem import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.PROFILE_AND_DEVICE_ID_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** @@ -35,9 +37,10 @@ class ProfileAndDeviceIdActivity : InjectableAutoLocalizedAppCompatActivity() { companion object { /** Returns an [Intent] to launch [ProfileAndDeviceIdActivity]. */ - fun createIntent(context: Context): Intent { + fun createIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, ProfileAndDeviceIdActivity::class.java).apply { decorateWithScreenName(PROFILE_AND_DEVICE_ID_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryItemViewModel.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryItemViewModel.kt index 355389d59b5..deaa95c253c 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryItemViewModel.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.completedstorylist import androidx.appcompat.app.AppCompatActivity import org.oppia.android.app.home.RouteToTopicPlayStoryListener import org.oppia.android.app.model.CompletedStory +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.shim.IntentFactoryShim import org.oppia.android.app.viewmodel.ObservableViewModel import org.oppia.android.domain.translation.TranslationController @@ -10,7 +11,7 @@ import org.oppia.android.domain.translation.TranslationController /** Completed story view model for the recycler view in [CompletedStoryListFragment]. */ class CompletedStoryItemViewModel( private val activity: AppCompatActivity, - private val internalProfileId: Int, + private val profileId: ProfileId, val completedStory: CompletedStory, val entityType: String, private val intentFactoryShim: IntentFactoryShim, @@ -31,13 +32,13 @@ class CompletedStoryItemViewModel( /** Called when user clicks on CompletedStoryItem. */ fun onCompletedStoryItemClicked() { - routeToTopicPlayStory(internalProfileId, completedStory.topicId, completedStory.storyId) + routeToTopicPlayStory(profileId, completedStory.topicId, completedStory.storyId) } - override fun routeToTopicPlayStory(internalProfileId: Int, topicId: String, storyId: String) { + override fun routeToTopicPlayStory(profileId: ProfileId, topicId: String, storyId: String) { val intent = intentFactoryShim.createTopicPlayStoryActivityIntent( activity.applicationContext, - internalProfileId, + profileId, topicId, storyId ) diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivity.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivity.kt index 1705b66748f..0ad91acb559 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivity.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivity.kt @@ -5,8 +5,11 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.COMPLETED_STORY_LIST_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for completed stories. */ @@ -17,21 +20,18 @@ class CompletedStoryListActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - val internalProfileId: Int = - intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) - completedStoryListActivityPresenter.handleOnCreate(internalProfileId) + val profileId: ProfileId = intent.extractCurrentUserProfileId() + completedStoryListActivityPresenter.handleOnCreate(profileId) } companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. - const val PROFILE_ID_EXTRA_KEY = - "CompletedStoryListActivity.profile_id" /** Returns a new [Intent] to route to [CompletedStoryListActivity] for a specified profile ID. */ - fun createCompletedStoryListActivityIntent(context: Context, internalProfileId: Int): Intent { + fun createCompletedStoryListActivityIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, CompletedStoryListActivity::class.java) - intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) intent.decorateWithScreenName(COMPLETED_STORY_LIST_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivityPresenter.kt index de44ee70a2c..f864a5b99db 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivityPresenter.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.completedstorylist import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** The presenter for [CompletedStoryListActivity]. */ @@ -10,9 +11,8 @@ import javax.inject.Inject class CompletedStoryListActivityPresenter @Inject constructor( private val activity: AppCompatActivity ) { - /** Initializes views for [CompletedStoryListActivity] and binds [CompletedStoryListFragment]. */ - fun handleOnCreate(internalProfileId: Int) { + fun handleOnCreate(profileId: ProfileId) { activity.setContentView(R.layout.completed_story_list_activity) if (getCompletedStoryListFragment() == null) { activity @@ -20,7 +20,7 @@ class CompletedStoryListActivityPresenter @Inject constructor( .beginTransaction() .add( R.id.completed_story_list_fragment_placeholder, - CompletedStoryListFragment.newInstance(internalProfileId), + CompletedStoryListFragment.newInstance(profileId), CompletedStoryListFragment.COMPLETED_STORY_LIST_FRAGMENT_TAG ).commitNow() } diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragment.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragment.kt index 9bc1ff69b0b..3fca3464fd9 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragment.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragment.kt @@ -7,6 +7,9 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment for displaying completed stories. */ @@ -20,10 +23,10 @@ class CompletedStoryListFragment : InjectableFragment() { "CompletedStoryListFragment.profile_id" /** Returns a new [CompletedStoryListFragment] to display corresponding to the specified profile ID. */ - fun newInstance(internalProfileId: Int): CompletedStoryListFragment { + fun newInstance(profileId: ProfileId): CompletedStoryListFragment { val completedStoryListFragment = CompletedStoryListFragment() val args = Bundle() - args.putInt(COMPLETED_STORY_LIST_FRAGMENT_PROFILE_ID_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) completedStoryListFragment.arguments = args return completedStoryListFragment } @@ -45,13 +48,11 @@ class CompletedStoryListFragment : InjectableFragment() { val args = checkNotNull(arguments) { "Expected arguments to be passed to CompletedStoryListFragment" } - val internalProfileId = args.getInt( - COMPLETED_STORY_LIST_FRAGMENT_PROFILE_ID_KEY, -1 - ) + val profileId = args.extractCurrentUserProfileId() return completedStoryListFragmentPresenter.handleCreateView( inflater, container, - internalProfileId + profileId ) } } diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt index 91e43599cd0..1bebdb181bd 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import org.oppia.android.R +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.recyclerview.BindableAdapter import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.CompletedStoryItemBinding @@ -27,10 +28,10 @@ class CompletedStoryListFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int + profileId: ProfileId ): View? { val viewModel = getCompletedStoryListViewModel() - viewModel.setProfileId(internalProfileId) + viewModel.setProfileId(profileId) binding = CompletedStoryListFragmentBinding .inflate( diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListViewModel.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListViewModel.kt index 678d91b02ce..708765451e9 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListViewModel.kt @@ -26,12 +26,12 @@ class CompletedStoryListViewModel @Inject constructor( private val translationController: TranslationController, @StoryHtmlParserEntityType private val entityType: String ) : ObservableViewModel() { - /** [internalProfileId] needs to be set before any of the live data members can be accessed. */ - private var internalProfileId: Int = -1 + /** [profileId] needs to be set before any of the live data members can be accessed. */ + private lateinit var profileId: ProfileId private val completedStoryListResultLiveData: LiveData> by lazy { topicController.getCompletedStoryList( - ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId ).toLiveData() } @@ -44,9 +44,9 @@ class CompletedStoryListViewModel @Inject constructor( Transformations.map(completedStoryLiveData, ::processCompletedStoryList) } - /** Sets internalProfileId to this ViewModel. */ - fun setProfileId(internalProfileId: Int) { - this.internalProfileId = internalProfileId + /** Sets ProfileId to this ViewModel. */ + fun setProfileId(profileId: ProfileId) { + this.profileId = profileId } private fun processCompletedStoryListResult( @@ -74,7 +74,7 @@ class CompletedStoryListViewModel @Inject constructor( completedStoryList.completedStoryList.map { completedStory -> CompletedStoryItemViewModel( activity, - internalProfileId, + profileId, completedStory, entityType, intentFactoryShim, diff --git a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivity.kt index 92897d6b9c2..50d54d41b01 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivity.kt @@ -12,10 +12,12 @@ import org.oppia.android.app.devoptions.markstoriescompleted.MarkStoriesComplete import org.oppia.android.app.devoptions.marktopicscompleted.MarkTopicsCompletedActivity import org.oppia.android.app.devoptions.mathexpressionparser.MathExpressionParserActivity import org.oppia.android.app.devoptions.vieweventlogs.ViewEventLogsActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.DEVELOPER_OPTIONS_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for Developer Options. */ @@ -35,56 +37,55 @@ class DeveloperOptionsActivity : @Inject lateinit var resourceHandler: AppLanguageResourceHandler - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - internalProfileId = intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) + profileId = intent.extractCurrentUserProfileId() developerOptionsActivityPresenter.handleOnCreate() title = resourceHandler.getStringInLocale(R.string.developer_options_activity_title) } override fun routeToMarkChaptersCompleted() { startActivity( - MarkChaptersCompletedActivity.createMarkChaptersCompletedIntent( - context = this, internalProfileId, showConfirmationNotice = false - ) + MarkChaptersCompletedActivity + .createMarkChaptersCompletedIntent(this, profileId, showConfirmationNotice = false) ) } override fun routeToMarkStoriesCompleted() { startActivity( MarkStoriesCompletedActivity - .createMarkStoriesCompletedIntent(this, internalProfileId) + .createMarkStoriesCompletedIntent(this, profileId) ) } override fun routeToMarkTopicsCompleted() { startActivity( MarkTopicsCompletedActivity - .createMarkTopicsCompletedIntent(this, internalProfileId) + .createMarkTopicsCompletedIntent(this, profileId) ) } override fun routeToViewEventLogs() { - startActivity(ViewEventLogsActivity.createViewEventLogsActivityIntent(this)) + startActivity(ViewEventLogsActivity.createViewEventLogsActivityIntent(this, profileId)) } override fun routeToForceNetworkType() { - startActivity(ForceNetworkTypeActivity.createForceNetworkTypeActivityIntent(this)) + startActivity(ForceNetworkTypeActivity.createForceNetworkTypeActivityIntent(this, profileId)) } override fun routeToMathExpressionParserTest() { - startActivity(MathExpressionParserActivity.createIntent(this)) + startActivity(MathExpressionParserActivity.createIntent(this, profileId)) } companion object { /** Function to create intent for DeveloperOptionsActivity. */ - fun createDeveloperOptionsActivityIntent(context: Context, internalProfileId: Int): Intent { + fun createDeveloperOptionsActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, DeveloperOptionsActivity::class.java).apply { - putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, internalProfileId) decorateWithScreenName(DEVELOPER_OPTIONS_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarter.kt b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarter.kt index 20732c19e7b..6a1f5aadeb7 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarter.kt @@ -2,8 +2,9 @@ package org.oppia.android.app.devoptions import android.content.Context import android.content.Intent +import org.oppia.android.app.model.ProfileId /** Interface to create intent for [DeveloperOptionsActivity]. */ interface DeveloperOptionsStarter { - fun createIntent(context: Context, internalProfileId: Int): Intent + fun createIntent(context: Context, profileId: ProfileId): Intent } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarterImpl.kt b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarterImpl.kt index 0182cbe08be..5c18f62a718 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarterImpl.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsStarterImpl.kt @@ -2,10 +2,11 @@ package org.oppia.android.app.devoptions import android.content.Context import android.content.Intent +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** Binds implementation of DeveloperOptionsStarter. */ class DeveloperOptionsStarterImpl @Inject constructor() : DeveloperOptionsStarter { - override fun createIntent(context: Context, internalProfileId: Int): Intent = - DeveloperOptionsActivity.createDeveloperOptionsActivityIntent(context, internalProfileId) + override fun createIntent(context: Context, profileId: ProfileId): Intent = + DeveloperOptionsActivity.createDeveloperOptionsActivityIntent(context, profileId) } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeActivity.kt index 78d07c9e7f4..89cf6ccb947 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeActivity.kt @@ -6,9 +6,11 @@ import android.os.Bundle import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.FORCE_NETWORK_TYPE_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** Activity for forcing the network mode for the app. */ @@ -28,9 +30,10 @@ class ForceNetworkTypeActivity : InjectableAutoLocalizedAppCompatActivity() { companion object { /** Returns [Intent] for [ForceNetworkTypeActivity]. */ - fun createForceNetworkTypeActivityIntent(context: Context): Intent { + fun createForceNetworkTypeActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, ForceNetworkTypeActivity::class.java).apply { decorateWithScreenName(FORCE_NETWORK_TYPE_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt index 4509dedb942..e001fa961ea 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt @@ -7,9 +7,12 @@ import android.view.MenuItem import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.MARK_CHAPTERS_COMPLETED_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for Mark Chapters Completed. */ @@ -21,13 +24,15 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity() @Inject lateinit var resourceHandler: AppLanguageResourceHandler + private lateinit var profileId: ProfileId + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - val internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, /* defaultValue= */ -1) + profileId = intent.extractCurrentUserProfileId() val showConfirmationNotice = intent.getBooleanExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, /* defaultValue= */ false) - markChaptersCompletedActivityPresenter.handleOnCreate(internalProfileId, showConfirmationNotice) + markChaptersCompletedActivityPresenter.handleOnCreate(profileId, showConfirmationNotice) title = resourceHandler.getStringInLocale(R.string.mark_chapters_completed_activity_title) } @@ -39,20 +44,19 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity() } companion object { - private const val PROFILE_ID_EXTRA_KEY = "MarkChaptersCompletedActivity.profile_id" private const val SHOW_CONFIRMATION_NOTICE_EXTRA_KEY = "MarkChaptersCompletedActivity.show_confirmation_notice" /** Returns an [Intent] to start this activity. */ fun createMarkChaptersCompletedIntent( context: Context, - internalProfileId: Int, + profileId: ProfileId, showConfirmationNotice: Boolean ): Intent { return Intent(context, MarkChaptersCompletedActivity::class.java).apply { - putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) - putExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, showConfirmationNotice) decorateWithScreenName(MARK_CHAPTERS_COMPLETED_ACTIVITY) + decorateWithUserProfileId(profileId) + putExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, showConfirmationNotice) } } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivityPresenter.kt index 6605456b86e..e35821190e3 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivityPresenter.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.devoptions.markchapterscompleted import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** The presenter for [MarkChaptersCompletedActivity]. */ @@ -11,14 +12,14 @@ class MarkChaptersCompletedActivityPresenter @Inject constructor( private val activity: AppCompatActivity ) { - fun handleOnCreate(internalProfileId: Int, showConfirmationNotice: Boolean) { + fun handleOnCreate(profileId: ProfileId, showConfirmationNotice: Boolean) { activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) activity.setContentView(R.layout.mark_chapters_completed_activity) if (getMarkChaptersCompletedFragment() == null) { - val markChaptersCompletedFragment = - MarkChaptersCompletedFragment.newInstance(internalProfileId, showConfirmationNotice) + val markChaptersCompletedFragment = MarkChaptersCompletedFragment + .newInstance(profileId, showConfirmationNotice) activity.supportFragmentManager.beginTransaction().add( R.id.mark_chapters_completed_container, markChaptersCompletedFragment diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragment.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragment.kt index 9ea2d5af880..ceb52fc58dd 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragment.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragment.kt @@ -7,6 +7,9 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment to display all chapters and provide functionality to mark them completed. */ @@ -15,7 +18,6 @@ class MarkChaptersCompletedFragment : InjectableFragment() { lateinit var markChaptersCompletedFragmentPresenter: MarkChaptersCompletedFragmentPresenter companion object { - private const val PROFILE_ID_ARGUMENT_KEY = "MarkChaptersCompletedFragment.profile_id" private const val SHOW_CONFIRMATION_NOTICE_ARGUMENT_KEY = "MarkChaptersCompletedFragment.show_confirmation_notice" private const val EXPLORATION_ID_LIST_ARGUMENT_KEY = @@ -25,12 +27,12 @@ class MarkChaptersCompletedFragment : InjectableFragment() { /** Returns a new [MarkChaptersCompletedFragment]. */ fun newInstance( - internalProfileId: Int, + profileId: ProfileId, showConfirmationNotice: Boolean ): MarkChaptersCompletedFragment { val markChaptersCompletedFragment = MarkChaptersCompletedFragment() val args = Bundle() - args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) args.putBoolean(SHOW_CONFIRMATION_NOTICE_ARGUMENT_KEY, showConfirmationNotice) markChaptersCompletedFragment.arguments = args return markChaptersCompletedFragment @@ -49,13 +51,13 @@ class MarkChaptersCompletedFragment : InjectableFragment() { ): View? { val args = checkNotNull(arguments) { "Expected arguments to be passed to MarkChaptersCompletedFragment" } - val internalProfileId = args.getInt(PROFILE_ID_ARGUMENT_KEY, /* defaultValue= */ -1) + val profileId = args.extractCurrentUserProfileId() val showConfirmationNotice = args.getBoolean(SHOW_CONFIRMATION_NOTICE_ARGUMENT_KEY, /* defaultValue= */ false) return markChaptersCompletedFragmentPresenter.handleCreateView( inflater, container, - internalProfileId, + profileId, showConfirmationNotice, savedInstanceState?.getStringArrayList(EXPLORATION_ID_LIST_ARGUMENT_KEY) ?: listOf(), savedInstanceState?.getStringArrayList(EXPLORATION_TITLE_LIST_ARGUMENT_KEY) ?: listOf() diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragmentPresenter.kt index 98a5d8f35fc..e413e3ac3bf 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedFragmentPresenter.kt @@ -45,7 +45,7 @@ class MarkChaptersCompletedFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int, + profileId: ProfileId, showConfirmationNotice: Boolean, selectedExplorationIds: List, selectedExplorationTitles: List @@ -68,7 +68,7 @@ class MarkChaptersCompletedFragmentPresenter @Inject constructor( this.selectedExplorationIds += selectedExplorationIds this.selectedExplorationTitles += selectedExplorationTitles - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + this.profileId = profileId viewModel.setProfileId(profileId) linearLayoutManager = LinearLayoutManager(activity.applicationContext) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/testing/MarkChaptersCompletedTestActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/testing/MarkChaptersCompletedTestActivity.kt index e869beaf93d..6d223e61ef3 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/testing/MarkChaptersCompletedTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/testing/MarkChaptersCompletedTestActivity.kt @@ -7,21 +7,27 @@ import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableSystemLocalizedAppCompatActivity import org.oppia.android.app.devoptions.markchapterscompleted.MarkChaptersCompletedFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId /** The activity for testing [MarkChaptersCompletedFragment]. */ class MarkChaptersCompletedTestActivity : InjectableSystemLocalizedAppCompatActivity() { + + private lateinit var profileId: ProfileId + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) setContentView(R.layout.mark_chapters_completed_activity) - val internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, /* default= */ -1) + profileId = intent.extractCurrentUserProfileId() val showConfirmationNotice = intent.getBooleanExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, /* default= */ false) if (getMarkChaptersCompletedFragment() == null) { - val markChaptersCompletedFragment = - MarkChaptersCompletedFragment.newInstance(internalProfileId, showConfirmationNotice) + val markChaptersCompletedFragment = MarkChaptersCompletedFragment + .newInstance(profileId, showConfirmationNotice) supportFragmentManager.beginTransaction().add( R.id.mark_chapters_completed_container, markChaptersCompletedFragment @@ -35,18 +41,17 @@ class MarkChaptersCompletedTestActivity : InjectableSystemLocalizedAppCompatActi } companion object { - private const val PROFILE_ID_EXTRA_KEY = "MarkChaptersCompletedTestActivity.profile_id" private const val SHOW_CONFIRMATION_NOTICE_EXTRA_KEY = "MarkChaptersCompletedTestActivity.show_confirmation_notice" /** Returns an [Intent] for [MarkChaptersCompletedTestActivity]. */ fun createMarkChaptersCompletedTestIntent( context: Context, - internalProfileId: Int, + profileId: ProfileId, showConfirmationNotice: Boolean ): Intent { val intent = Intent(context, MarkChaptersCompletedTestActivity::class.java) - intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) + intent.decorateWithUserProfileId(profileId) intent.putExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, showConfirmationNotice) return intent } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt index 4e3b2f92a12..e341b6bde66 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt @@ -7,9 +7,12 @@ import android.view.MenuItem import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.MARK_STORIES_COMPLETED_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for Mark Stories Completed. */ @@ -21,13 +24,13 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity() @Inject lateinit var resourceHandler: AppLanguageResourceHandler - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) - markStoriesCompletedActivityPresenter.handleOnCreate(internalProfileId) + profileId = intent.extractCurrentUserProfileId() + markStoriesCompletedActivityPresenter.handleOnCreate(profileId) title = resourceHandler.getStringInLocale(R.string.mark_stories_completed_activity_title) } @@ -39,14 +42,11 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity() } companion object { - /** [String] key value for mapping to InternalProfileId in [Bundle]. */ - const val PROFILE_ID_EXTRA_KEY = "MarkStoriesCompletedActivity.profile_id" - /** Returns an [Intent] to start this activity. */ - fun createMarkStoriesCompletedIntent(context: Context, internalProfileId: Int): Intent { + fun createMarkStoriesCompletedIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, MarkStoriesCompletedActivity::class.java).apply { - putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) decorateWithScreenName(MARK_STORIES_COMPLETED_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivityPresenter.kt index d0bfc8d6612..c7d2210caa3 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivityPresenter.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.devoptions.markstoriescompleted import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** The presenter for [MarkStoriesCompletedActivity]. */ @@ -11,14 +12,14 @@ class MarkStoriesCompletedActivityPresenter @Inject constructor( private val activity: AppCompatActivity ) { - fun handleOnCreate(internalProfileId: Int) { + fun handleOnCreate(profileId: ProfileId) { activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) activity.setContentView(R.layout.mark_stories_completed_activity) if (getMarkStoriesCompletedFragment() == null) { val markStoriesCompletedFragment = MarkStoriesCompletedFragment - .newInstance(internalProfileId) + .newInstance(profileId) activity.supportFragmentManager.beginTransaction().add( R.id.mark_stories_completed_container, markStoriesCompletedFragment diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragment.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragment.kt index e87c481af15..ea84147fa61 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragment.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragment.kt @@ -7,6 +7,9 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment to display all stories and provide functionality to mark them completed. */ @@ -20,10 +23,10 @@ class MarkStoriesCompletedFragment : InjectableFragment() { private const val STORY_ID_LIST_ARGUMENT_KEY = "MarkStoriesCompletedFragment.story_id_list" /** Returns a new [MarkStoriesCompletedFragment]. */ - fun newInstance(internalProfileId: Int): MarkStoriesCompletedFragment { + fun newInstance(profileId: ProfileId): MarkStoriesCompletedFragment { val markStoriesCompletedFragment = MarkStoriesCompletedFragment() val args = Bundle() - args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) markStoriesCompletedFragment.arguments = args return markStoriesCompletedFragment } @@ -41,8 +44,7 @@ class MarkStoriesCompletedFragment : InjectableFragment() { ): View? { val args = checkNotNull(arguments) { "Expected arguments to be passed to MarkStoriesCompletedFragment" } - val internalProfileId = args - .getInt(PROFILE_ID_ARGUMENT_KEY, -1) + val profileId = args.extractCurrentUserProfileId() var selectedStoryIdList = ArrayList() if (savedInstanceState != null) { selectedStoryIdList = savedInstanceState.getStringArrayList(STORY_ID_LIST_ARGUMENT_KEY)!! @@ -50,7 +52,7 @@ class MarkStoriesCompletedFragment : InjectableFragment() { return markStoriesCompletedFragmentPresenter.handleCreateView( inflater, container, - internalProfileId, + profileId, selectedStoryIdList ) } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragmentPresenter.kt index a7514fa682b..263dbe63c4b 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedFragmentPresenter.kt @@ -32,7 +32,7 @@ class MarkStoriesCompletedFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int, + profileId: ProfileId, selectedStoryIdList: ArrayList ): View? { binding = MarkStoriesCompletedFragmentBinding.inflate( @@ -52,7 +52,7 @@ class MarkStoriesCompletedFragmentPresenter @Inject constructor( this.selectedStoryIdList = selectedStoryIdList - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + this.profileId = profileId viewModel.setProfileId(profileId) linearLayoutManager = LinearLayoutManager(activity.applicationContext) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/testing/MarkStoriesCompletedTestActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/testing/MarkStoriesCompletedTestActivity.kt index 2217450ebff..a946128c1e4 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/testing/MarkStoriesCompletedTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/testing/MarkStoriesCompletedTestActivity.kt @@ -7,11 +7,14 @@ import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.devoptions.markstoriescompleted.MarkStoriesCompletedFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId /** Activity for testing [MarkStoriesCompletedFragment]. */ class MarkStoriesCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity() { - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -19,9 +22,11 @@ class MarkStoriesCompletedTestActivity : InjectableAutoLocalizedAppCompatActivit supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) setContentView(R.layout.mark_stories_completed_activity) - internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) + profileId = intent.extractCurrentUserProfileId() if (getMarkStoriesCompletedFragment() == null) { - val markStoriesCompletedFragment = MarkStoriesCompletedFragment.newInstance(internalProfileId) + val markStoriesCompletedFragment = MarkStoriesCompletedFragment.newInstance( + profileId + ) supportFragmentManager.beginTransaction().add( R.id.mark_stories_completed_container, markStoriesCompletedFragment @@ -35,13 +40,10 @@ class MarkStoriesCompletedTestActivity : InjectableAutoLocalizedAppCompatActivit } companion object { - /** [String] key value for mapping to InternalProfileId in [Bundle]. */ - const val PROFILE_ID_EXTRA_KEY = "MarkStoriesCompletedTestActivity.profile_id" - /** Returns an [Intent] for [MarkStoriesCompletedTestActivity]. */ - fun createMarkStoriesCompletedTestIntent(context: Context, internalProfileId: Int): Intent { + fun createMarkStoriesCompletedTestIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, MarkStoriesCompletedTestActivity::class.java) - intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt index 5274a993e7b..beba72d96fc 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt @@ -8,9 +8,12 @@ import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.devoptions.markstoriescompleted.testing.MarkStoriesCompletedTestActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.MARK_TOPICS_COMPLETED_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for Mark Topics Completed. */ @@ -22,13 +25,13 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() { @Inject lateinit var resourceHandler: AppLanguageResourceHandler - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) - markTopicsCompletedActivityPresenter.handleOnCreate(internalProfileId) + profileId = intent.extractCurrentUserProfileId() + markTopicsCompletedActivityPresenter.handleOnCreate(profileId) title = resourceHandler.getStringInLocale(R.string.mark_topics_completed_activity_title) } @@ -40,13 +43,10 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() { } companion object { - /** [String] key value for mapping to InternalProfileId in [Bundle]. */ - const val PROFILE_ID_EXTRA_KEY = "MarkTopicsCompletedActivity.profile_id" - /** Returns an [Intent] for [MarkStoriesCompletedTestActivity]. */ - fun createMarkTopicsCompletedIntent(context: Context, internalProfileId: Int): Intent { + fun createMarkTopicsCompletedIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, MarkTopicsCompletedActivity::class.java).apply { - putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) + decorateWithUserProfileId(profileId) decorateWithScreenName(MARK_TOPICS_COMPLETED_ACTIVITY) } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivityPresenter.kt index 74069c28d17..020c38db7df 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivityPresenter.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.devoptions.marktopicscompleted import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** The presenter for [MarkTopicsCompletedActivity]. */ @@ -11,14 +12,14 @@ class MarkTopicsCompletedActivityPresenter @Inject constructor( private val activity: AppCompatActivity ) { - fun handleOnCreate(internalProfileId: Int) { + fun handleOnCreate(profileId: ProfileId) { activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) activity.setContentView(R.layout.mark_topics_completed_activity) if (getMarkTopicsCompletedFragment() == null) { val markTopicsCompletedFragment = MarkTopicsCompletedFragment - .newInstance(internalProfileId) + .newInstance(profileId) activity.supportFragmentManager.beginTransaction().add( R.id.mark_topics_completed_container, markTopicsCompletedFragment diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragment.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragment.kt index 39581587eb6..b16e2251ef7 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragment.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragment.kt @@ -7,6 +7,9 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment to display all topics and provide functionality to mark them completed. */ @@ -15,15 +18,13 @@ class MarkTopicsCompletedFragment : InjectableFragment() { lateinit var markTopicsCompletedFragmentPresenter: MarkTopicsCompletedFragmentPresenter companion object { - internal const val PROFILE_ID_ARGUMENT_KEY = "MarkTopicsCompletedFragment.profile_id" - private const val TOPIC_ID_LIST_ARGUMENT_KEY = "MarkTopicsCompletedFragment.topic_id_list" /** Returns a new [MarkTopicsCompletedFragment]. */ - fun newInstance(internalProfileId: Int): MarkTopicsCompletedFragment { + fun newInstance(profileId: ProfileId): MarkTopicsCompletedFragment { val markTopicsCompletedFragment = MarkTopicsCompletedFragment() val args = Bundle() - args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) markTopicsCompletedFragment.arguments = args return markTopicsCompletedFragment } @@ -41,8 +42,7 @@ class MarkTopicsCompletedFragment : InjectableFragment() { ): View? { val args = checkNotNull(arguments) { "Expected arguments to be passed to MarkTopicsCompletedFragment" } - val internalProfileId = args - .getInt(PROFILE_ID_ARGUMENT_KEY, -1) + val profileId = args.extractCurrentUserProfileId() var selectedTopicIdList = ArrayList() if (savedInstanceState != null) { selectedTopicIdList = savedInstanceState.getStringArrayList(TOPIC_ID_LIST_ARGUMENT_KEY)!! @@ -50,7 +50,7 @@ class MarkTopicsCompletedFragment : InjectableFragment() { return markTopicsCompletedFragmentPresenter.handleCreateView( inflater, container, - internalProfileId, + profileId, selectedTopicIdList ) } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragmentPresenter.kt index ad7451d7eff..e534651bf10 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedFragmentPresenter.kt @@ -32,7 +32,7 @@ class MarkTopicsCompletedFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int, + profileId: ProfileId, selectedTopicIdList: ArrayList ): View? { binding = MarkTopicsCompletedFragmentBinding.inflate( @@ -52,7 +52,7 @@ class MarkTopicsCompletedFragmentPresenter @Inject constructor( this.selectedTopicIdList = selectedTopicIdList - this.profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + this.profileId = profileId viewModel.setProfileId(profileId) linearLayoutManager = LinearLayoutManager(activity.applicationContext) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/testing/MarkTopicsCompletedTestActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/testing/MarkTopicsCompletedTestActivity.kt index a33ad677ace..ca17d781755 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/testing/MarkTopicsCompletedTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/testing/MarkTopicsCompletedTestActivity.kt @@ -7,11 +7,14 @@ import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.devoptions.marktopicscompleted.MarkTopicsCompletedFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId /** The activity for testing [MarkTopicsCompletedFragment]. */ class MarkTopicsCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity() { - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -19,9 +22,11 @@ class MarkTopicsCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) setContentView(R.layout.mark_topics_completed_activity) - internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) + profileId = intent.extractCurrentUserProfileId() if (getMarkTopicsCompletedFragment() == null) { - val markTopicsCompletedFragment = MarkTopicsCompletedFragment.newInstance(internalProfileId) + val markTopicsCompletedFragment = MarkTopicsCompletedFragment.newInstance( + profileId + ) supportFragmentManager.beginTransaction().add( R.id.mark_topics_completed_container, markTopicsCompletedFragment @@ -35,12 +40,11 @@ class MarkTopicsCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity } companion object { - const val PROFILE_ID_EXTRA_KEY = "MarkTopicsCompletedTestActivity.profile_id" /** Returns an [Intent] for [MarkTopicsCompletedTestActivity]. */ - fun createMarkTopicsCompletedTestIntent(context: Context, internalProfileId: Int): Intent { + fun createMarkTopicsCompletedTestIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, MarkTopicsCompletedTestActivity::class.java) - intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/mathexpressionparser/MathExpressionParserActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/mathexpressionparser/MathExpressionParserActivity.kt index 20f7c2d9c63..8cb5e091bea 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/mathexpressionparser/MathExpressionParserActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/mathexpressionparser/MathExpressionParserActivity.kt @@ -6,9 +6,11 @@ import android.os.Bundle import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.MATH_EXPRESSION_PARSER_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** Activity to allow the user to test math expressions/equations. */ @@ -28,9 +30,10 @@ class MathExpressionParserActivity : InjectableAutoLocalizedAppCompatActivity() companion object { /** Returns [Intent] for [MathExpressionParserActivity]. */ - fun createIntent(context: Context): Intent { + fun createIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, MathExpressionParserActivity::class.java).apply { decorateWithScreenName(MATH_EXPRESSION_PARSER_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/testing/DeveloperOptionsTestActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/testing/DeveloperOptionsTestActivity.kt index 69ea6cb1889..f0b89ce97d1 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/testing/DeveloperOptionsTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/testing/DeveloperOptionsTestActivity.kt @@ -17,6 +17,9 @@ import org.oppia.android.app.devoptions.markchapterscompleted.MarkChaptersComple import org.oppia.android.app.devoptions.markstoriescompleted.MarkStoriesCompletedActivity import org.oppia.android.app.devoptions.marktopicscompleted.MarkTopicsCompletedActivity import org.oppia.android.app.devoptions.vieweventlogs.ViewEventLogsActivity +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId /** Activity for testing [DeveloperOptionsFragment]. */ class DeveloperOptionsTestActivity : @@ -27,13 +30,13 @@ class DeveloperOptionsTestActivity : RouteToMarkTopicsCompletedListener, RouteToViewEventLogsListener { - private var internalProfileId = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) setContentView(R.layout.developer_options_activity) - internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) + profileId = intent.extractCurrentUserProfileId() if (getDeveloperOptionsFragment() == null) { supportFragmentManager.beginTransaction().add( R.id.developer_options_fragment_placeholder, @@ -50,28 +53,27 @@ class DeveloperOptionsTestActivity : override fun routeToMarkChaptersCompleted() { startActivity( - MarkChaptersCompletedActivity.createMarkChaptersCompletedIntent( - context = this, internalProfileId, showConfirmationNotice = false - ) + MarkChaptersCompletedActivity + .createMarkChaptersCompletedIntent(this, profileId, showConfirmationNotice = false) ) } override fun routeToMarkStoriesCompleted() { startActivity( MarkStoriesCompletedActivity - .createMarkStoriesCompletedIntent(this, internalProfileId) + .createMarkStoriesCompletedIntent(this, profileId) ) } override fun routeToMarkTopicsCompleted() { startActivity( MarkTopicsCompletedActivity - .createMarkTopicsCompletedIntent(this, internalProfileId) + .createMarkTopicsCompletedIntent(this, profileId) ) } override fun routeToViewEventLogs() { - startActivity(ViewEventLogsActivity.createViewEventLogsActivityIntent(this)) + startActivity(ViewEventLogsActivity.createViewEventLogsActivityIntent(this, profileId)) } override fun forceCrash() { @@ -79,12 +81,10 @@ class DeveloperOptionsTestActivity : } companion object { - const val PROFILE_ID_EXTRA_KEY = "DeveloperOptionsTestActivity.profile_id" - /** Returns [Intent] for [DeveloperOptionsTestActivity]. */ - fun createDeveloperOptionsTestIntent(context: Context, internalProfileId: Int): Intent { + fun createDeveloperOptionsTestIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, DeveloperOptionsActivity::class.java) - intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivity.kt index 895155e88c5..97b1417a11c 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivity.kt @@ -6,9 +6,11 @@ import android.os.Bundle import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.VIEW_EVENT_LOGS_ACTIVITY import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** Activity for View Event Logs. */ @@ -27,9 +29,10 @@ class ViewEventLogsActivity : InjectableAutoLocalizedAppCompatActivity() { } companion object { - fun createViewEventLogsActivityIntent(context: Context): Intent { + fun createViewEventLogsActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, ViewEventLogsActivity::class.java).apply { decorateWithScreenName(VIEW_EVENT_LOGS_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt index ee307e47738..689be3c145c 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt @@ -9,6 +9,7 @@ import androidx.appcompat.widget.Toolbar import androidx.drawerlayout.widget.DrawerLayout import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** [NavigationDrawerFragment] to show navigation drawer. */ @@ -37,7 +38,7 @@ class NavigationDrawerFragment : navigationDrawerFragmentPresenter.setUpDrawer(drawerLayout, toolbar, menuItemId) } - override fun routeToProfileProgress(profileId: Int) { + override fun routeToProfileProgress(profileId: ProfileId) { navigationDrawerFragmentPresenter.openProfileProgress(profileId) } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 44fb2ec9945..438df5554d2 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -39,11 +39,10 @@ import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.domain.topic.TopicController 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.statusbar.StatusBarColor import javax.inject.Inject -const val NAVIGATION_PROFILE_ID_ARGUMENT_KEY = - "NavigationDrawerFragmentPresenter.navigation_profile_id" const val TAG_SWITCH_PROFILE_DIALOG = "SWITCH_PROFILE_DIALOG" /** The presenter for [NavigationDrawerFragment]. */ @@ -63,7 +62,6 @@ class NavigationDrawerFragmentPresenter @Inject constructor( private lateinit var binding: DrawerFragmentBinding private lateinit var profileId: ProfileId private var previousMenuItemId: Int? = null - private var internalProfileId: Int = -1 fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { binding = DrawerFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false) @@ -71,8 +69,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( fragment.setHasOptionsMenu(true) - internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId = activity.intent.extractCurrentUserProfileId() val headerBinding = NavHeaderNavigationDrawerBinding.inflate( @@ -107,7 +104,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() drawerLayout.closeDrawers() getFooterViewModel().isDeveloperOptionsSelected.set(true) - val intent = starter.createIntent(activity, internalProfileId) + val intent = starter.createIntent(activity, profileId) fragment.activity!!.startActivity(intent) if (previousMenuItemId == 0) fragment.activity!!.finish() else if (previousMenuItemId != null && @@ -147,7 +144,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( val intent = AdministratorControlsActivity.createAdministratorControlsActivityIntent( activity, - internalProfileId + profileId ) fragment.activity!!.startActivity(intent) if (previousMenuItemId == -1) fragment.activity!!.finish() @@ -244,13 +241,13 @@ class NavigationDrawerFragmentPresenter @Inject constructor( if (previousMenuItemId != menuItemId) { when (NavigationDrawerItem.valueFromNavId(menuItemId)) { NavigationDrawerItem.HOME -> { - val intent = HomeActivity.createHomeActivity(activity, internalProfileId) + val intent = HomeActivity.createHomeActivity(activity, profileId) fragment.activity!!.startActivity(intent) drawerLayout.closeDrawers() } NavigationDrawerItem.OPTIONS -> { val intent = OptionsActivity.createOptionsActivity( - activity, internalProfileId, + activity, profileId, /* isFromNavigationDrawer= */ true ) fragment.activity!!.startActivity(intent) @@ -261,7 +258,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } NavigationDrawerItem.HELP -> { val intent = HelpActivity.createHelpActivityIntent( - activity, internalProfileId, + activity, profileId, /* isFromNavigationDrawer= */ true ) fragment.activity!!.startActivity(intent) @@ -272,7 +269,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } NavigationDrawerItem.DOWNLOADS -> { val intent = - MyDownloadsActivity.createMyDownloadsActivityIntent(activity, internalProfileId) + MyDownloadsActivity.createMyDownloadsActivityIntent(activity, profileId) fragment.activity!!.startActivity(intent) if (checkIfPreviousActivityShouldGetFinished(menuItemId)) { fragment.activity!!.finish() @@ -318,7 +315,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } } - fun openProfileProgress(profileId: Int) { + fun openProfileProgress(profileId: ProfileId) { activity.startActivity( ProfileProgressActivity.createProfileProgressActivityIntent( activity, diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerHeaderViewModel.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerHeaderViewModel.kt index b46e7a63275..85c12aa4932 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerHeaderViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerHeaderViewModel.kt @@ -25,7 +25,7 @@ class NavigationDrawerHeaderViewModel @Inject constructor( val profileProgressText: ObservableField = ObservableField(computeProfileProgressText()) fun onHeaderClicked() { - routeToProfileProgressListener.routeToProfileProgress(profile.get()!!.id.internalId) + routeToProfileProgressListener.routeToProfileProgress(profile.get()!!.id) } fun setOngoingTopicProgress(ongoingTopicCount: Int) { diff --git a/app/src/main/java/org/oppia/android/app/drawer/RouteToProfileProgressListener.kt b/app/src/main/java/org/oppia/android/app/drawer/RouteToProfileProgressListener.kt index c1b5e12a654..d8c654e356e 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/RouteToProfileProgressListener.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/RouteToProfileProgressListener.kt @@ -1,6 +1,8 @@ package org.oppia.android.app.drawer +import org.oppia.android.app.model.ProfileId + /** Listener for when an activity should route to [ProfileProgressActivity]. */ interface RouteToProfileProgressListener { - fun routeToProfileProgress(profileId: Int) + fun routeToProfileProgress(profileId: ProfileId) } diff --git a/app/src/main/java/org/oppia/android/app/help/HelpActivity.kt b/app/src/main/java/org/oppia/android/app/help/HelpActivity.kt index 8d1182d5105..4cf46f8a752 100644 --- a/app/src/main/java/org/oppia/android/app/help/HelpActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/HelpActivity.kt @@ -6,13 +6,13 @@ import android.os.Bundle import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.help.faq.FAQListActivity import org.oppia.android.app.help.faq.RouteToFAQSingleListener import org.oppia.android.app.help.faq.faqsingle.FAQSingleActivity import org.oppia.android.app.help.thirdparty.ThirdPartyDependencyListActivity import org.oppia.android.app.model.PoliciesActivityParams import org.oppia.android.app.model.PolicyPage +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.HELP_ACTIVITY import org.oppia.android.app.policies.PoliciesActivity import org.oppia.android.app.policies.RouteToPoliciesListener @@ -20,6 +20,8 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.getStringFromBundle import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject const val HELP_OPTIONS_TITLE_SAVED_KEY = "HelpActivity.help_options_title" @@ -55,6 +57,7 @@ class HelpActivity : private lateinit var selectedFragment: String private lateinit var selectedHelpOptionsTitle: String + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -74,6 +77,7 @@ class HelpActivity : POLICIES_ARGUMENT_PROTO, PoliciesActivityParams.getDefaultInstance() ) + profileId = intent.extractCurrentUserProfileId() helpActivityPresenter.handleOnCreate( selectedHelpOptionsTitle, isFromNavigationDrawer, @@ -92,24 +96,25 @@ class HelpActivity : fun createHelpActivityIntent( context: Context, - profileId: Int?, + profileId: ProfileId, isFromNavigationDrawer: Boolean ): Intent { val intent = Intent(context, HelpActivity::class.java) - intent.putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) intent.putExtra(BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY, isFromNavigationDrawer) intent.decorateWithScreenName(HELP_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } } override fun onRouteToFAQList() { - val intent = FAQListActivity.createFAQListActivityIntent(this) + val intent = FAQListActivity.createFAQListActivityIntent(this, profileId) startActivity(intent) } override fun onRouteToThirdPartyDependencyList() { - val intent = ThirdPartyDependencyListActivity.createThirdPartyDependencyListActivityIntent(this) + val intent = + ThirdPartyDependencyListActivity.createThirdPartyDependencyListActivityIntent(this, profileId) startActivity(intent) } @@ -136,7 +141,10 @@ class HelpActivity : // TODO(#3681): Add support to display Single FAQ in split mode on tablet devices. override fun onRouteToFAQSingle(question: String, answer: String) { - startActivity(FAQSingleActivity.createFAQSingleActivityIntent(this, question, answer)) + startActivity( + FAQSingleActivity.createFAQSingleActivityIntent + (this, question, answer, profileId) + ) } override fun onRouteToPolicies(policyPage: PolicyPage) { diff --git a/app/src/main/java/org/oppia/android/app/help/faq/FAQListActivity.kt b/app/src/main/java/org/oppia/android/app/help/faq/FAQListActivity.kt index d9dae44ce19..3578d8db598 100644 --- a/app/src/main/java/org/oppia/android/app/help/faq/FAQListActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/faq/FAQListActivity.kt @@ -6,8 +6,11 @@ import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.help.faq.faqsingle.FAQSingleActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.FAQ_LIST_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The FAQ page activity for placement of different FAQs. */ @@ -15,22 +18,28 @@ class FAQListActivity : InjectableAutoLocalizedAppCompatActivity(), RouteToFAQSi @Inject lateinit var faqListActivityPresenter: FAQListActivityPresenter + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) + profileId = intent.extractCurrentUserProfileId() faqListActivityPresenter.handleOnCreate() } companion object { - fun createFAQListActivityIntent(context: Context): Intent { + fun createFAQListActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, FAQListActivity::class.java).apply { decorateWithScreenName(FAQ_LIST_ACTIVITY) + decorateWithUserProfileId(profileId) } } } override fun onRouteToFAQSingle(question: String, answer: String) { - startActivity(FAQSingleActivity.createFAQSingleActivityIntent(this, question, answer)) + startActivity( + FAQSingleActivity.createFAQSingleActivityIntent + (this, question, answer, profileId) + ) } } diff --git a/app/src/main/java/org/oppia/android/app/help/faq/faqsingle/FAQSingleActivity.kt b/app/src/main/java/org/oppia/android/app/help/faq/faqsingle/FAQSingleActivity.kt index 9b6a10339a9..d48b388fbf3 100644 --- a/app/src/main/java/org/oppia/android/app/help/faq/faqsingle/FAQSingleActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/faq/faqsingle/FAQSingleActivity.kt @@ -5,8 +5,10 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.FAQ_SINGLE_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** The FAQ page activity for placement of single FAQ. */ @@ -32,11 +34,17 @@ class FAQSingleActivity : InjectableAutoLocalizedAppCompatActivity() { const val FAQ_SINGLE_ACTIVITY_QUESTION = "FAQSingleActivity.question" const val FAQ_SINGLE_ACTIVITY_ANSWER = "FAQSingleActivity.answer" - fun createFAQSingleActivityIntent(context: Context, question: String, answer: String): Intent { + fun createFAQSingleActivityIntent( + context: Context, + question: String, + answer: String, + profileId: ProfileId + ): Intent { val intent = Intent(context, FAQSingleActivity::class.java) intent.putExtra(FAQ_SINGLE_ACTIVITY_QUESTION, question) intent.putExtra(FAQ_SINGLE_ACTIVITY_ANSWER, answer) intent.decorateWithScreenName(FAQ_SINGLE_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseListActivity.kt b/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseListActivity.kt index 84301c83952..281168406e4 100644 --- a/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseListActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseListActivity.kt @@ -5,8 +5,11 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.LICENSE_LIST_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The activity that will show list of licenses corresponding to a third-party dependency. */ @@ -14,11 +17,13 @@ class LicenseListActivity : InjectableAutoLocalizedAppCompatActivity(), RouteToL @Inject lateinit var licenseListActivityPresenter: LicenseListActivityPresenter + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) val dependencyIndex = intent.getIntExtra(THIRD_PARTY_DEPENDENCY_INDEX, 0) + profileId = intent.extractCurrentUserProfileId() licenseListActivityPresenter.handleOnCreate(dependencyIndex, false) } @@ -28,11 +33,13 @@ class LicenseListActivity : InjectableAutoLocalizedAppCompatActivity(), RouteToL /** Returns [Intent] for [LicenseListActivity]. */ fun createLicenseListActivityIntent( context: Context, - dependencyIndex: Int + dependencyIndex: Int, + profileId: ProfileId ): Intent { val intent = Intent(context, LicenseListActivity::class.java) intent.putExtra(THIRD_PARTY_DEPENDENCY_INDEX, dependencyIndex) intent.decorateWithScreenName(LICENSE_LIST_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } } @@ -42,7 +49,8 @@ class LicenseListActivity : InjectableAutoLocalizedAppCompatActivity(), RouteToL LicenseTextViewerActivity.createLicenseTextViewerActivityIntent( this, dependencyIndex, - licenseIndex + licenseIndex, + profileId ) ) } diff --git a/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseTextViewerActivity.kt b/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseTextViewerActivity.kt index 4cde507fa3b..3d6f95cacfa 100644 --- a/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseTextViewerActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/thirdparty/LicenseTextViewerActivity.kt @@ -5,8 +5,10 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.LICENSE_TEXT_VIEWER_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** The activity that will show the license text of a copyright license. */ @@ -33,12 +35,14 @@ class LicenseTextViewerActivity : InjectableAutoLocalizedAppCompatActivity() { fun createLicenseTextViewerActivityIntent( context: Context, dependencyIndex: Int, - licenseIndex: Int + licenseIndex: Int, + profileId: ProfileId ): Intent { val intent = Intent(context, LicenseTextViewerActivity::class.java) intent.putExtra(LICENSE_TEXT_VIEWER_ACTIVITY_DEP_INDEX, dependencyIndex) intent.putExtra(LICENSE_TEXT_VIEWER_ACTIVITY_LICENSE_INDEX, licenseIndex) intent.decorateWithScreenName(LICENSE_TEXT_VIEWER_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListActivity.kt b/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListActivity.kt index ac68d9f8ac3..1a29d8777a2 100644 --- a/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListActivity.kt +++ b/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListActivity.kt @@ -5,8 +5,11 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.THIRD_PARTY_DEPENDENCY_LIST_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The activity for displaying a list of third-party dependencies used to build Oppia Android. */ @@ -17,18 +20,24 @@ class ThirdPartyDependencyListActivity : @Inject lateinit var thirdPartyDependencyListActivityPresenter: ThirdPartyDependencyListActivityPresenter + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) + profileId = intent.extractCurrentUserProfileId() thirdPartyDependencyListActivityPresenter.handleOnCreate(false) } companion object { /** Returns [Intent] for starting [ThirdPartyDependencyListActivity]. */ - fun createThirdPartyDependencyListActivityIntent(context: Context): Intent { + fun createThirdPartyDependencyListActivityIntent( + context: Context, + profileId: ProfileId + ): Intent { return Intent(context, ThirdPartyDependencyListActivity::class.java).apply { decorateWithScreenName(THIRD_PARTY_DEPENDENCY_LIST_ACTIVITY) + decorateWithUserProfileId(profileId) } } } @@ -38,7 +47,8 @@ class ThirdPartyDependencyListActivity : LicenseListActivity .createLicenseListActivityIntent( context = this, - dependencyIndex = dependencyIndex + dependencyIndex = dependencyIndex, + profileId ) ) } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index e6de1272867..6028c0ef7a8 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -8,7 +8,6 @@ import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.activity.route.ActivityRouter import org.oppia.android.app.drawer.ExitProfileDialogFragment -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.drawer.TAG_SWITCH_PROFILE_DIALOG import org.oppia.android.app.model.DestinationScreen import org.oppia.android.app.model.ExitProfileDialogArguments @@ -20,6 +19,8 @@ import org.oppia.android.app.model.ScreenName.HOME_ACTIVITY import org.oppia.android.app.topic.TopicActivity import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The central activity for all users entering the app. */ @@ -37,13 +38,13 @@ class HomeActivity : @Inject lateinit var activityRouter: ActivityRouter - private var internalProfileId: Int = -1 + private lateinit var profileId: ProfileId companion object { - fun createHomeActivity(context: Context, profileId: Int?): Intent { + fun createHomeActivity(context: Context, profileId: ProfileId): Intent { return Intent(context, HomeActivity::class.java).apply { - putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) decorateWithScreenName(HOME_ACTIVITY) + decorateWithUserProfileId(profileId) } } } @@ -51,8 +52,8 @@ class HomeActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - internalProfileId = intent?.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1)!! - homeActivityPresenter.handleOnCreate(internalProfileId) + profileId = intent.extractCurrentUserProfileId() + homeActivityPresenter.handleOnCreate(profileId) title = resourceHandler.getStringInLocale(R.string.home_activity_title) } @@ -61,8 +62,8 @@ class HomeActivity : homeActivityPresenter.handleOnRestart() } - override fun routeToTopic(internalProfileId: Int, topicId: String) { - startActivity(TopicActivity.createTopicActivityIntent(this, internalProfileId, topicId)) + override fun routeToTopic(profileId: ProfileId, topicId: String) { + startActivity(TopicActivity.createTopicActivityIntent(this, profileId, topicId)) } override fun onBackPressed() { @@ -81,11 +82,11 @@ class HomeActivity : dialogFragment.showNow(supportFragmentManager, TAG_SWITCH_PROFILE_DIALOG) } - override fun routeToTopicPlayStory(internalProfileId: Int, topicId: String, storyId: String) { + override fun routeToTopicPlayStory(profileId: ProfileId, topicId: String, storyId: String) { startActivity( TopicActivity.createTopicPlayStoryActivityIntent( this, - internalProfileId, + profileId, topicId, storyId ) @@ -96,7 +97,7 @@ class HomeActivity : val recentlyPlayedActivityParams = RecentlyPlayedActivityParams .newBuilder() - .setProfileId(ProfileId.newBuilder().setInternalId(internalProfileId).build()) + .setProfileId(profileId) .setActivityTitle(recentlyPlayedActivityTitle).build() activityRouter.routeToScreen( diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index 83e65950b7f..8f6040c2917 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -7,6 +7,7 @@ import androidx.drawerlayout.widget.DrawerLayout import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.drawer.NavigationDrawerFragment +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.spotlight.SpotlightFragment import org.oppia.android.app.spotlight.SpotlightManager import javax.inject.Inject @@ -18,7 +19,7 @@ const val TAG_HOME_FRAGMENT = "HOME_FRAGMENT" class HomeActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { private var navigationDrawerFragment: NavigationDrawerFragment? = null - fun handleOnCreate(internalProfileId: Int) { + fun handleOnCreate(profileId: ProfileId) { activity.setContentView(R.layout.home_activity) setUpNavigationDrawer() if (getHomeFragment() == null) { @@ -32,7 +33,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA if (getSpotlightFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.home_spotlight_fragment_placeholder, - SpotlightFragment.newInstance(internalProfileId), + SpotlightFragment.newInstance(profileId), SpotlightManager.SPOTLIGHT_FRAGMENT_TAG ).commitNow() } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt index eedc0483a0b..a19d8669193 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt @@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import org.oppia.android.R -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel import org.oppia.android.app.home.promotedlist.PromotedStoryListViewModel @@ -31,6 +30,7 @@ import org.oppia.android.domain.topic.TopicListController import org.oppia.android.domain.translation.TranslationController import org.oppia.android.util.parser.html.StoryHtmlParserEntityType import org.oppia.android.util.parser.html.TopicHtmlParserEntityType +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The presenter for [HomeFragment]. */ @@ -51,21 +51,21 @@ class HomeFragmentPresenter @Inject constructor( ) { private val routeToTopicPlayStoryListener = activity as RouteToTopicPlayStoryListener private lateinit var binding: HomeFragmentBinding - private var internalProfileId: Int = -1 + private lateinit var profileId: ProfileId fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { binding = HomeFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false) // NB: Both the view model and lifecycle owner must be set in order to correctly bind LiveData elements to // data-bound view models. - internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) + profileId = activity.intent.extractCurrentUserProfileId() logHomeActivityEvent() val homeViewModel = HomeViewModel( activity, fragment, oppiaLogger, - internalProfileId, + profileId, profileManagementController, topicListController, topicEntityType, @@ -153,7 +153,7 @@ class HomeFragmentPresenter @Inject constructor( fun onTopicSummaryClicked(topicSummary: TopicSummary) { routeToTopicPlayStoryListener.routeToTopicPlayStory( - internalProfileId, + profileId, topicSummary.topicId, topicSummary.firstStoryId ) @@ -162,7 +162,7 @@ class HomeFragmentPresenter @Inject constructor( private fun logHomeActivityEvent() { analyticsController.logImportantEvent( oppiaLogger.createOpenHomeContext(), - ProfileId.newBuilder().apply { internalId = internalProfileId }.build() + profileId ) } } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt b/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt index c8734e43845..4f03f338873 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt @@ -43,7 +43,7 @@ class HomeViewModel( private val activity: AppCompatActivity, private val fragment: Fragment, private val oppiaLogger: OppiaLogger, - private val internalProfileId: Int, + private val profileId: ProfileId, private val profileManagementController: ProfileManagementController, private val topicListController: TopicListController, @TopicHtmlParserEntityType private val topicEntityType: String, @@ -53,7 +53,6 @@ class HomeViewModel( private val translationController: TranslationController ) : ObservableViewModel() { - private val profileId: ProfileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() private val promotedStoryListLimit = activity.resources.getInteger( R.integer.promoted_story_list_limit ) @@ -197,7 +196,7 @@ class HomeViewModel( .mapIndexed { index, promotedStory -> PromotedStoryViewModel( activity, - internalProfileId, + profileId, sortedStoryList.size, storyEntityType, promotedStory, diff --git a/app/src/main/java/org/oppia/android/app/home/RouteToTopicListener.kt b/app/src/main/java/org/oppia/android/app/home/RouteToTopicListener.kt index 36c7a1a1d94..38fa900fc9d 100755 --- a/app/src/main/java/org/oppia/android/app/home/RouteToTopicListener.kt +++ b/app/src/main/java/org/oppia/android/app/home/RouteToTopicListener.kt @@ -1,6 +1,8 @@ package org.oppia.android.app.home +import org.oppia.android.app.model.ProfileId + /** Listener for when an activity should route to a topic. */ interface RouteToTopicListener { - fun routeToTopic(internalProfileId: Int, topicId: String) + fun routeToTopic(profileId: ProfileId, topicId: String) } diff --git a/app/src/main/java/org/oppia/android/app/home/RouteToTopicPlayStoryListener.kt b/app/src/main/java/org/oppia/android/app/home/RouteToTopicPlayStoryListener.kt index aa7121f1c07..137af2fb368 100755 --- a/app/src/main/java/org/oppia/android/app/home/RouteToTopicPlayStoryListener.kt +++ b/app/src/main/java/org/oppia/android/app/home/RouteToTopicPlayStoryListener.kt @@ -1,6 +1,8 @@ package org.oppia.android.app.home +import org.oppia.android.app.model.ProfileId + /** Listener for when an activity should route to a story-item in TopicPlay tab. */ interface RouteToTopicPlayStoryListener { - fun routeToTopicPlayStory(internalProfileId: Int, topicId: String, storyId: String) + fun routeToTopicPlayStory(profileId: ProfileId, topicId: String, storyId: String) } diff --git a/app/src/main/java/org/oppia/android/app/home/promotedlist/PromotedStoryViewModel.kt b/app/src/main/java/org/oppia/android/app/home/promotedlist/PromotedStoryViewModel.kt index 2adceb6abea..7641640ba3f 100755 --- a/app/src/main/java/org/oppia/android/app/home/promotedlist/PromotedStoryViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/home/promotedlist/PromotedStoryViewModel.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.ViewModel import org.oppia.android.R import org.oppia.android.app.home.RouteToTopicPlayStoryListener +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.PromotedStory import org.oppia.android.app.viewmodel.ObservableViewModel import org.oppia.android.domain.translation.TranslationController @@ -17,7 +18,7 @@ import java.util.Objects /** [ViewModel] for displaying a promoted story. */ class PromotedStoryViewModel( private val activity: AppCompatActivity, - private val internalProfileId: Int, + private val profileId: ProfileId, private val totalStoryCount: Int, val entityType: String, val promotedStory: PromotedStory, @@ -57,7 +58,7 @@ class PromotedStoryViewModel( fun clickOnStoryTile() { routeToTopicPlayStoryListener.routeToTopicPlayStory( - internalProfileId, + profileId, promotedStory.topicId, promotedStory.storyId ) @@ -68,14 +69,14 @@ class PromotedStoryViewModel( // object changes. override fun equals(other: Any?): Boolean { return other is PromotedStoryViewModel && - other.internalProfileId == this.internalProfileId && + other.profileId == this.profileId && other.totalStoryCount == this.totalStoryCount && other.entityType == this.entityType && other.promotedStory == this.promotedStory } override fun hashCode() = Objects.hash( - internalProfileId, + profileId, totalStoryCount, entityType, promotedStory diff --git a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivity.kt b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivity.kt index bf852642259..de5207f87e7 100644 --- a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivity.kt @@ -19,6 +19,7 @@ import org.oppia.android.app.topic.RouteToResumeLessonListener import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.putProtoExtra import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** Activity for recent stories. */ @@ -56,6 +57,7 @@ class RecentlyPlayedActivity : recentlyPlayedActivityParams ) decorateWithScreenName(ScreenName.RECENTLY_PLAYED_ACTIVITY) + decorateWithUserProfileId(recentlyPlayedActivityParams.profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivityPresenter.kt index 9eef029e29b..d66e0d1cf53 100644 --- a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedActivityPresenter.kt @@ -32,7 +32,7 @@ class RecentlyPlayedActivityPresenter @Inject constructor( if (getRecentlyPlayedFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.recently_played_fragment_placeholder, - RecentlyPlayedFragment.newInstance(recentlyPlayedActivityParams.profileId.internalId), + RecentlyPlayedFragment.newInstance(recentlyPlayedActivityParams.profileId), RecentlyPlayedFragment.TAG_RECENTLY_PLAYED_FRAGMENT ).commitNow() } diff --git a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedFragment.kt b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedFragment.kt index c7c23243ac0..bc1a9da0a8f 100644 --- a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedFragment.kt +++ b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedFragment.kt @@ -7,22 +7,22 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.PromotedStory +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject -private const val RECENTLY_PLAYED_FRAGMENT_INTERNAL_PROFILE_ID_KEY = - "RecentlyPlayedFragment.internal_profile_id" - /** Fragment that contains all recently played stories. */ class RecentlyPlayedFragment : InjectableFragment(), PromotedStoryClickListener { companion object { const val TAG_RECENTLY_PLAYED_FRAGMENT = "TAG_RECENTLY_PLAYED_FRAGMENT" /** Returns a new [RecentlyPlayedFragment] to display recently played stories. */ - fun newInstance(internalProfileId: Int): RecentlyPlayedFragment { + fun newInstance(profileId: ProfileId): RecentlyPlayedFragment { val recentlyPlayedFragment = RecentlyPlayedFragment() val args = Bundle() - args.putInt(RECENTLY_PLAYED_FRAGMENT_INTERNAL_PROFILE_ID_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) recentlyPlayedFragment.arguments = args return recentlyPlayedFragment } @@ -43,8 +43,8 @@ class RecentlyPlayedFragment : InjectableFragment(), PromotedStoryClickListener ): View? { val args = checkNotNull(arguments) { "Expected arguments to be passed to RecentlyPlayedFragment" } - val internalProfileId = args.getInt(RECENTLY_PLAYED_FRAGMENT_INTERNAL_PROFILE_ID_KEY, -1) - return recentlyPlayedFragmentPresenter.handleCreateView(inflater, container, internalProfileId) + val profileId = args.extractCurrentUserProfileId() + return recentlyPlayedFragmentPresenter.handleCreateView(inflater, container, profileId) } override fun promotedStoryClicked(promotedStory: PromotedStory) { diff --git a/app/src/main/java/org/oppia/android/app/mydownloads/MyDownloadsActivity.kt b/app/src/main/java/org/oppia/android/app/mydownloads/MyDownloadsActivity.kt index 9e288a070f4..7c3d3d08df6 100644 --- a/app/src/main/java/org/oppia/android/app/mydownloads/MyDownloadsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/mydownloads/MyDownloadsActivity.kt @@ -5,40 +5,38 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.home.HomeActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.MY_DOWNLOADS_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The activity for displaying [MyDownloadsFragment]. */ class MyDownloadsActivity : InjectableAutoLocalizedAppCompatActivity() { @Inject lateinit var myDownloadsActivityPresenter: MyDownloadsActivityPresenter - private var internalProfileId: Int = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) myDownloadsActivityPresenter.handleOnCreate() - internalProfileId = intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) + profileId = intent.extractCurrentUserProfileId() } companion object { - fun createMyDownloadsActivityIntent(context: Context, profileId: Int?): Intent { + fun createMyDownloadsActivityIntent(context: Context, profileId: ProfileId): Intent { val intent = Intent(context, MyDownloadsActivity::class.java) - intent.putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) intent.decorateWithScreenName(MY_DOWNLOADS_ACTIVITY) + intent.decorateWithUserProfileId(profileId) return intent } - - fun getIntentKey(): String { - return NAVIGATION_PROFILE_ID_ARGUMENT_KEY - } } override fun onBackPressed() { - val intent = HomeActivity.createHomeActivity(this, internalProfileId) + val intent = HomeActivity.createHomeActivity(this, profileId) startActivity(intent) finish() } diff --git a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingActivity.kt b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingActivity.kt index 325433fa18b..91b5c2fff8f 100644 --- a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingActivity.kt +++ b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingActivity.kt @@ -41,6 +41,10 @@ class OnboardingActivity : } override fun onRouteToPolicies(policyPage: PolicyPage) { - startActivity(PoliciesActivity.createPoliciesActivityIntent(this, policyPage)) + startActivity( + PoliciesActivity.createPoliciesActivityIntent( + this, policyPage + ) + ) } } diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt index 2f8e6f9e84d..e7128bb8395 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import org.oppia.android.R import org.oppia.android.app.home.RouteToTopicListener import org.oppia.android.app.model.EphemeralTopic +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.shim.IntentFactoryShim import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.viewmodel.ObservableViewModel @@ -13,7 +14,7 @@ import org.oppia.android.domain.translation.TranslationController /** [ViewModel] for displaying topic item in [OngoingTopicListActivity]. */ class OngoingTopicItemViewModel( private val activity: AppCompatActivity, - private val internalProfileId: Int, + private val profileId: ProfileId, ephemeralTopic: EphemeralTopic, val entityType: String, private val intentFactoryShim: IntentFactoryShim, @@ -27,7 +28,7 @@ class OngoingTopicItemViewModel( } fun onTopicItemClicked() { - routeToTopic(internalProfileId, topic.topicId) + routeToTopic(profileId, topic.topicId) } fun computeStoryCountText(): String { @@ -36,10 +37,10 @@ class OngoingTopicItemViewModel( ) } - override fun routeToTopic(internalProfileId: Int, topicId: String) { + override fun routeToTopic(profileId: ProfileId, topicId: String) { val intent = intentFactoryShim.createTopicActivityIntent( activity.applicationContext, - internalProfileId, + profileId, topicId ) activity.startActivity(intent) diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivity.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivity.kt index 7f70f143426..5305a6fc690 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivity.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivity.kt @@ -5,8 +5,11 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.ONGOING_TOPIC_LIST_ACTIVITY import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Activity for ongoing topics. */ @@ -17,22 +20,17 @@ class OngoingTopicListActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - val internalProfileId: Int = intent.getIntExtra( - ONGOING_TOPIC_LIST_ACTIVITY_PROFILE_ID_KEY, -1 - ) - ongoingTopicListActivityPresenter.handleOnCreate(internalProfileId) + val profileId = intent.extractCurrentUserProfileId() + ongoingTopicListActivityPresenter.handleOnCreate(profileId) } companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. - const val ONGOING_TOPIC_LIST_ACTIVITY_PROFILE_ID_KEY = - "OngoingTopicListActivity.profile_id" - /** Returns a new [Intent] to route to [OngoingTopicListActivity] for a specified profile ID. */ - fun createOngoingTopicListActivityIntent(context: Context, internalProfileId: Int): Intent { + fun createOngoingTopicListActivityIntent(context: Context, profileId: ProfileId): Intent { return Intent(context, OngoingTopicListActivity::class.java).apply { - putExtra(ONGOING_TOPIC_LIST_ACTIVITY_PROFILE_ID_KEY, internalProfileId) decorateWithScreenName(ONGOING_TOPIC_LIST_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivityPresenter.kt index 54df078f088..0db8e69db63 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivityPresenter.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.ongoingtopiclist import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope +import org.oppia.android.app.model.ProfileId import javax.inject.Inject /** The presenter for [OngoingTopicListActivity]. */ @@ -10,12 +11,12 @@ import javax.inject.Inject class OngoingTopicListActivityPresenter @Inject constructor( private val activity: AppCompatActivity ) { - fun handleOnCreate(internalProfileId: Int) { + fun handleOnCreate(profileId: ProfileId) { activity.setContentView(R.layout.ongoing_topic_list_activity) if (getOngoingTopicListFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.ongoing_topic_list_fragment_placeholder, - OngoingTopicListFragment.newInstance(internalProfileId), + OngoingTopicListFragment.newInstance(profileId), OngoingTopicListFragment.ONGOING_TOPIC_LIST_FRAGMENT_TAG ).commitNow() } diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragment.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragment.kt index b06d1c1a27a..9667d98e67a 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragment.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragment.kt @@ -7,6 +7,9 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment for displaying [OngoingTopicListActivity]. */ @@ -15,14 +18,12 @@ class OngoingTopicListFragment : InjectableFragment() { companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. const val ONGOING_TOPIC_LIST_FRAGMENT_TAG = "TAG_ONGOING_TOPIC_LIST_FRAGMENT" - internal const val ONGOING_TOPIC_LIST_FRAGMENT_PROFILE_ID_KEY = - "OngoingTopicListFragment.profile_id" /** Returns a new [OngoingTopicListFragment] to display corresponding to the specified profile ID. */ - fun newInstance(internalProfileId: Int): OngoingTopicListFragment { + fun newInstance(profileId: ProfileId): OngoingTopicListFragment { val ongoingTopicListFragment = OngoingTopicListFragment() val args = Bundle() - args.putInt(ONGOING_TOPIC_LIST_FRAGMENT_PROFILE_ID_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) ongoingTopicListFragment.arguments = args return ongoingTopicListFragment } @@ -43,13 +44,11 @@ class OngoingTopicListFragment : InjectableFragment() { ): View? { val args = checkNotNull(arguments) { "Expected arguments to be passed to OngoingTopicListFragment" } - val internalProfileId = args.getInt( - ONGOING_TOPIC_LIST_FRAGMENT_PROFILE_ID_KEY, -1 - ) + val profileId = args.extractCurrentUserProfileId() return ongoingTopicListFragmentPresenter.handleCreateView( inflater, container, - internalProfileId + profileId ) } } diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt index 09968096fad..0a340939939 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import org.oppia.android.R +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.recyclerview.BindableAdapter import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.OngoingTopicItemBinding @@ -26,7 +27,7 @@ class OngoingTopicListFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int + profileId: ProfileId ): View? { val viewModel = getOngoingTopicListViewModel() binding = @@ -35,7 +36,7 @@ class OngoingTopicListFragmentPresenter @Inject constructor( container, /* attachToRoot= */ false ) - viewModel.setProfileId(internalProfileId) + viewModel.setProfileId(profileId) binding.ongoingTopicListToolbar.setNavigationOnClickListener { (activity as OngoingTopicListActivity).finish() diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt index 37ecd2369ad..bfb9ded2100 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt @@ -29,11 +29,11 @@ class OngoingTopicListViewModel @Inject constructor( private val translationController: TranslationController ) : ObservableViewModel() { /** [internalProfileId] needs to be set before any of the live data members can be accessed. */ - private var internalProfileId: Int = -1 + private lateinit var profileId: ProfileId private val ongoingTopicListResultLiveData: LiveData> by lazy { topicController.getOngoingTopicList( - ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId ).toLiveData() } @@ -45,8 +45,8 @@ class OngoingTopicListViewModel @Inject constructor( Transformations.map(ongoingTopicListLiveData, ::processOngoingTopicList) } - fun setProfileId(internalProfileId: Int) { - this.internalProfileId = internalProfileId + fun setProfileId(profileId: ProfileId) { + this.profileId = profileId } private fun processOngoingTopicResult( @@ -74,7 +74,7 @@ class OngoingTopicListViewModel @Inject constructor( ongoingTopicList.topicList.map { ephemeralTopic -> OngoingTopicItemViewModel( activity, - internalProfileId, + profileId, ephemeralTopic, entityType, intentFactoryShim, diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageActivity.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageActivity.kt index 6387577fbce..711b5e00bc3 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageActivity.kt @@ -5,31 +5,33 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.model.AppLanguageActivityParams import org.oppia.android.app.model.AppLanguageActivityStateBundle import org.oppia.android.app.model.OppiaLanguage +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.APP_LANGUAGE_ACTIVITY import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.putProto import org.oppia.android.util.extensions.putProtoExtra import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The activity to change the language of the app. */ class AppLanguageActivity : InjectableAutoLocalizedAppCompatActivity() { @Inject lateinit var appLanguageActivityPresenter: AppLanguageActivityPresenter - private var profileId: Int? = -1 + private lateinit var profileId: ProfileId override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - profileId = intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) + profileId = intent.extractCurrentUserProfileId() appLanguageActivityPresenter.handleOnCreate( savedInstanceState?.retrieveLanguageFromSavedState() ?: intent.retrieveLanguageFromParams(), - profileId!! + profileId ) } @@ -40,16 +42,16 @@ class AppLanguageActivity : InjectableAutoLocalizedAppCompatActivity() { /** Returns a new [Intent] to route to [AppLanguageActivity]. */ fun createAppLanguageActivityIntent( context: Context, - oppiaLanguage: OppiaLanguage, - profileId: Int? + profileId: ProfileId, + oppiaLanguage: OppiaLanguage ): Intent { return Intent(context, AppLanguageActivity::class.java).apply { val arguments = AppLanguageActivityParams.newBuilder().apply { this.oppiaLanguage = oppiaLanguage }.build() putProtoExtra(ACTIVITY_PARAMS_KEY, arguments) - putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) decorateWithScreenName(APP_LANGUAGE_ACTIVITY) + decorateWithUserProfileId(profileId) } } diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageActivityPresenter.kt index f058644efd7..b6b842c20e6 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageActivityPresenter.kt @@ -5,6 +5,7 @@ import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.model.OppiaLanguage +import org.oppia.android.app.model.ProfileId import org.oppia.android.databinding.AppLanguageActivityBinding import javax.inject.Inject @@ -14,7 +15,7 @@ class AppLanguageActivityPresenter @Inject constructor(private val activity: App private lateinit var oppiaLanguage: OppiaLanguage /** Initializes and creates the views for [AppLanguageActivity]. */ - fun handleOnCreate(oppiaLanguage: OppiaLanguage, profileId: Int) { + fun handleOnCreate(oppiaLanguage: OppiaLanguage, profileId: ProfileId) { val binding: AppLanguageActivityBinding = DataBindingUtil.setContentView( activity, R.layout.app_language_activity, diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt index cad56a8bd96..ef618eda1dc 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt @@ -5,14 +5,16 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment import org.oppia.android.app.model.AppLanguageFragmentArguments import org.oppia.android.app.model.AppLanguageFragmentStateBundle import org.oppia.android.app.model.OppiaLanguage +import org.oppia.android.app.model.ProfileId import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** The fragment to change the language of the app. */ @@ -20,21 +22,21 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener @Inject lateinit var appLanguageFragmentPresenter: AppLanguageFragmentPresenter - private var profileId: Int? = -1 + private lateinit var profileId: ProfileId companion object { private const val FRAGMENT_ARGUMENTS_KEY = "AppLanguageFragment.arguments" private const val FRAGMENT_SAVED_STATE_KEY = "AppLanguageFragment.saved_state" /** Returns a new [AppLanguageFragment] instance. */ - fun newInstance(oppiaLanguage: OppiaLanguage, profileId: Int): AppLanguageFragment { + fun newInstance(oppiaLanguage: OppiaLanguage, profileId: ProfileId): AppLanguageFragment { return AppLanguageFragment().apply { arguments = Bundle().apply { val args = AppLanguageFragmentArguments.newBuilder().apply { this.oppiaLanguage = oppiaLanguage }.build() putProto(FRAGMENT_ARGUMENTS_KEY, args) - putInt(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) + this.decorateWithUserProfileId(profileId) } } } @@ -68,13 +70,14 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener savedInstanceState?.retrieveLanguageFromSavedState() ?: arguments?.retrieveLanguageFromArguments() ) { "Expected arguments to be passed to AppLanguageFragment" } - profileId = arguments?.getInt(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) + + profileId = arguments?.extractCurrentUserProfileId()!! return appLanguageFragmentPresenter.handleOnCreateView( inflater, container, oppiaLanguage!!, - profileId!! + profileId ) } diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index a7a550583b3..a471f466f4c 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -32,7 +32,7 @@ class AppLanguageFragmentPresenter @Inject constructor( inflater: LayoutInflater, container: ViewGroup?, prefSummaryValue: OppiaLanguage, - profileId: Int + profileId: ProfileId ): View? { val binding = AppLanguageFragmentBinding.inflate( inflater, @@ -40,7 +40,7 @@ class AppLanguageFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) this.appLanguage = prefSummaryValue - this.profileId = ProfileId.newBuilder().apply { internalId = profileId }.build() + this.profileId = profileId appLanguageSelectionViewModel.selectedLanguage.value = prefSummaryValue binding.viewModel = appLanguageSelectionViewModel binding.lifecycleOwner = fragment diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageActivity.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageActivity.kt index 7042393f3d4..fdab36dd0b6 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageActivity.kt @@ -8,12 +8,14 @@ import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.model.AudioLanguage import org.oppia.android.app.model.AudioLanguageActivityParams import org.oppia.android.app.model.AudioLanguageActivityStateBundle +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ScreenName.AUDIO_LANGUAGE_ACTIVITY import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.putProto import org.oppia.android.util.extensions.putProtoExtra import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject /** The activity to change the Default Audio language of the app. */ @@ -45,7 +47,8 @@ class AudioLanguageActivity : InjectableAutoLocalizedAppCompatActivity() { /** Returns a new [Intent] to route to [AudioLanguageActivity]. */ fun createAudioLanguageActivityIntent( context: Context, - audioLanguage: AudioLanguage + audioLanguage: AudioLanguage, + profileId: ProfileId ): Intent { return Intent(context, AudioLanguageActivity::class.java).apply { val arguments = AudioLanguageActivityParams.newBuilder().apply { @@ -53,6 +56,7 @@ class AudioLanguageActivity : InjectableAutoLocalizedAppCompatActivity() { }.build() putProtoExtra(ACTIVITY_PARAMS_KEY, arguments) decorateWithScreenName(AUDIO_LANGUAGE_ACTIVITY) + decorateWithUserProfileId(profileId) } } diff --git a/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt b/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt index 50484e5ff1e..0d836fd9092 100644 --- a/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt @@ -7,10 +7,10 @@ import android.widget.TextView import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.model.AudioLanguage import org.oppia.android.app.model.AudioLanguageActivityResultBundle import org.oppia.android.app.model.OppiaLanguage +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ReadingTextSize import org.oppia.android.app.model.ReadingTextSizeActivityResultBundle import org.oppia.android.app.model.ScreenName.OPTIONS_ACTIVITY @@ -18,6 +18,8 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.getStringFromBundle import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject private const val SELECTED_OPTIONS_TITLE_SAVED_KEY = "OptionsActivity.selected_options_title" @@ -47,7 +49,7 @@ class OptionsActivity : // used to initially load the suitable fragment in the case of multipane. private var isFirstOpen = true private lateinit var selectedFragment: String - private var profileId: Int? = -1 + private lateinit var profileId: ProfileId companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. @@ -58,13 +60,13 @@ class OptionsActivity : /** Returns an [Intent] to start this activity. */ fun createOptionsActivity( context: Context, - profileId: Int?, + profileId: ProfileId, isFromNavigationDrawer: Boolean ): Intent { return Intent(context, OptionsActivity::class.java).apply { - putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, profileId) putExtra(BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY, isFromNavigationDrawer) decorateWithScreenName(OPTIONS_ACTIVITY) + decorateWithUserProfileId(profileId) } } } @@ -76,7 +78,6 @@ class OptionsActivity : BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY, /* defaultValue= */ false ) - profileId = intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) if (savedInstanceState != null) { isFirstOpen = false } @@ -85,6 +86,8 @@ class OptionsActivity : } else { savedInstanceState.get(SELECTED_FRAGMENT_SAVED_KEY) as String } + + profileId = intent.extractCurrentUserProfileId() val extraOptionsTitle = savedInstanceState?.getStringFromBundle(SELECTED_OPTIONS_TITLE_SAVED_KEY) optionActivityPresenter.handleOnCreate( @@ -92,7 +95,7 @@ class OptionsActivity : extraOptionsTitle, isFirstOpen, selectedFragment, - profileId!! + profileId ) title = resourceHandler.getStringInLocale(R.string.menu_options) } @@ -123,22 +126,22 @@ class OptionsActivity : startActivity( AppLanguageActivity.createAppLanguageActivityIntent( this, - oppiaLanguage, - profileId!! + profileId, + oppiaLanguage ) ) } override fun routeAudioLanguageList(audioLanguage: AudioLanguage) { startActivityForResult( - AudioLanguageActivity.createAudioLanguageActivityIntent(this, audioLanguage), + AudioLanguageActivity.createAudioLanguageActivityIntent(this, audioLanguage, profileId), REQUEST_CODE_AUDIO_LANGUAGE ) } override fun routeReadingTextSize(readingTextSize: ReadingTextSize) { startActivityForResult( - ReadingTextSizeActivity.createReadingTextSizeActivityIntent(this, readingTextSize), + ReadingTextSizeActivity.createReadingTextSizeActivityIntent(this, readingTextSize, profileId), REQUEST_CODE_TEXT_SIZE ) } diff --git a/app/src/main/java/org/oppia/android/app/options/OptionsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/options/OptionsActivityPresenter.kt index 6193d3a337e..51e4780bb62 100644 --- a/app/src/main/java/org/oppia/android/app/options/OptionsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/OptionsActivityPresenter.kt @@ -11,6 +11,7 @@ import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.drawer.NavigationDrawerFragment import org.oppia.android.app.model.AudioLanguage import org.oppia.android.app.model.OppiaLanguage +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ReadingTextSize import javax.inject.Inject @@ -21,7 +22,7 @@ class OptionsActivityPresenter @Inject constructor( ) { private var navigationDrawerFragment: NavigationDrawerFragment? = null private lateinit var toolbar: Toolbar - private var profileId: Int? = -1 + private lateinit var profileId: ProfileId /** Initializes and creates the views for [OptionsActivity]. */ fun handleOnCreate( @@ -29,7 +30,7 @@ class OptionsActivityPresenter @Inject constructor( extraOptionsTitle: String?, isFirstOpen: Boolean, selectedFragment: String, - profileId: Int + profileId: ProfileId ) { if (isFromNavigationDrawer) { activity.setContentView(R.layout.option_activity) @@ -122,7 +123,7 @@ class OptionsActivityPresenter @Inject constructor( */ fun loadAppLanguageFragment(appLanguage: OppiaLanguage) { val appLanguageFragment = - AppLanguageFragment.newInstance(appLanguage, profileId = this.profileId!!) + AppLanguageFragment.newInstance(appLanguage, profileId = this.profileId) activity.supportFragmentManager .beginTransaction() .replace(R.id.multipane_options_container, appLanguageFragment) diff --git a/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt index 0e11f227c1e..8e0c7941f05 100644 --- a/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt @@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.recyclerview.widget.RecyclerView -import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.AppLanguageSelection import org.oppia.android.app.model.AudioLanguage @@ -25,6 +24,7 @@ import org.oppia.android.domain.profile.ProfileManagementController 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 java.security.InvalidParameterException import javax.inject.Inject @@ -51,7 +51,6 @@ class OptionsFragmentPresenter @Inject constructor( ) { private lateinit var binding: OptionsFragmentBinding private lateinit var recyclerViewAdapter: RecyclerView.Adapter<*> - private var internalProfileId: Int = -1 private lateinit var profileId: ProfileId private var appLanguage = OppiaLanguage.ENGLISH private var audioLanguage = AudioLanguage.NO_AUDIO @@ -73,8 +72,7 @@ class OptionsFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) - internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId = activity.intent.extractCurrentUserProfileId() viewModel.setProfileId(profileId) val optionsRecyclerViewAdapter = createRecyclerViewAdapter(isMultipane) diff --git a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt index 6c8c14d87ae..2a749016401 100644 --- a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ReadingTextSize import org.oppia.android.app.model.ReadingTextSizeActivityParams import org.oppia.android.app.model.ReadingTextSizeActivityResultBundle @@ -15,6 +16,7 @@ import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.putProto import org.oppia.android.util.extensions.putProtoExtra import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject private const val ACTIVITY_PARAMS_KEY = "ReadingTextSizeActivity.params" @@ -40,7 +42,8 @@ class ReadingTextSizeActivity : InjectableAutoLocalizedAppCompatActivity() { /** Returns a new [Intent] to route to [ReadingTextSizeActivity]. */ fun createReadingTextSizeActivityIntent( context: Context, - initialReadingTextSize: ReadingTextSize + initialReadingTextSize: ReadingTextSize, + profileId: ProfileId ): Intent { val params = ReadingTextSizeActivityParams.newBuilder().apply { readingTextSize = initialReadingTextSize @@ -48,6 +51,7 @@ class ReadingTextSizeActivity : InjectableAutoLocalizedAppCompatActivity() { return Intent(context, ReadingTextSizeActivity::class.java).apply { putProtoExtra(ACTIVITY_PARAMS_KEY, params) decorateWithScreenName(READING_TEXT_SIZE_ACTIVITY) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragment.kt b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragment.kt index 0fe678cbb5a..562e6bd8e9f 100755 --- a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragment.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragment.kt @@ -7,7 +7,10 @@ import android.view.View import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.State +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment that controls audio for a content-card. */ @@ -25,10 +28,10 @@ class AudioFragment : * @param profileId used by AudioFragment to get Audio Language. * @return a new instance of [AudioFragment]. */ - fun newInstance(profileId: Int): AudioFragment { + fun newInstance(profileId: ProfileId): AudioFragment { val audioFragment = AudioFragment() val args = Bundle() - args.putInt(AUDIO_FRAGMENT_PROFILE_ID_ARGUMENT_KEY, profileId) + args.decorateWithUserProfileId(profileId) audioFragment.arguments = args return audioFragment } @@ -45,9 +48,8 @@ class AudioFragment : savedInstanceState: Bundle? ): View? { super.onCreateView(inflater, container, savedInstanceState) - val internalProfileId = - arguments!!.getInt(AUDIO_FRAGMENT_PROFILE_ID_ARGUMENT_KEY, /* defaultValue= */ -1) - return audioFragmentPresenter.handleCreateView(inflater, container, internalProfileId) + val profileId = arguments!!.extractCurrentUserProfileId() + return audioFragmentPresenter.handleCreateView(inflater, container, profileId) } override fun languageSelectionClicked() { diff --git a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt index 02bcc3deb32..387ba645392 100644 --- a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt @@ -40,7 +40,6 @@ import javax.inject.Inject const val TAG_LANGUAGE_DIALOG = "LANGUAGE_DIALOG" private const val TAG_CELLULAR_DATA_DIALOG = "CELLULAR_DATA_DIALOG" -const val AUDIO_FRAGMENT_PROFILE_ID_ARGUMENT_KEY = "AUDIO_FRAGMENT_PROFILE_ID_ARGUMENT_KEY" /** The presenter for [AudioFragment]. */ @FragmentScope @@ -74,9 +73,9 @@ class AudioFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int + profileId: ProfileId ): View? { - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + this.profileId = profileId cellularAudioDialogController.getCellularDataPreference().toLiveData() .observe( fragment, diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt index b20609b8e4d..4290e703925 100755 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt @@ -24,6 +24,7 @@ import org.oppia.android.app.topic.conceptcard.ConceptCardListener import org.oppia.android.util.extensions.getProtoExtra import org.oppia.android.util.extensions.putProtoExtra import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject const val TAG_HINTS_AND_SOLUTION_DIALOG = "HINTS_AND_SOLUTION_DIALOG" @@ -100,6 +101,7 @@ class ExplorationActivity : return Intent(context, ExplorationActivity::class.java).apply { putProtoExtra(PARAMS_KEY, params) decorateWithScreenName(EXPLORATION_ACTIVITY) + decorateWithUserProfileId(params.profileId) } } diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt index 5d1d0414196..cc1b92301b8 100644 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt @@ -142,7 +142,7 @@ class ExplorationActivityPresenter @Inject constructor( if (getSpotlightManager() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.exploration_spotlight_fragment_placeholder, - SpotlightFragment.newInstance(profileId.internalId), + SpotlightFragment.newInstance(profileId), SpotlightManager.SPOTLIGHT_FRAGMENT_TAG ).commitNow() } @@ -202,7 +202,7 @@ class ExplorationActivityPresenter @Inject constructor( R.id.action_options -> { val intent = OptionsActivity.createOptionsActivity( activity, - profileId.internalId, + profileId, /* isFromNavigationDrawer= */ false ) fontScaleConfigurationUtil.adjustFontScale(activity, ReadingTextSize.MEDIUM_TEXT_SIZE) @@ -211,7 +211,7 @@ class ExplorationActivityPresenter @Inject constructor( } R.id.action_help -> { val intent = HelpActivity.createHelpActivityIntent( - activity, profileId.internalId, + activity, profileId, /* isFromNavigationDrawer= */false ) fontScaleConfigurationUtil.adjustFontScale(activity, ReadingTextSize.MEDIUM_TEXT_SIZE) @@ -380,7 +380,7 @@ class ExplorationActivityPresenter @Inject constructor( ExplorationActivityParams.ParentScreen.UNRECOGNIZED -> { // Default to the topic activity. activity.startActivity( - TopicActivity.createTopicActivityIntent(context, profileId.internalId, topicId) + TopicActivity.createTopicActivityIntent(context, profileId, topicId) ) } } diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationFragmentPresenter.kt index 8796b96b672..8a15fe9e1bf 100755 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationFragmentPresenter.kt @@ -56,7 +56,7 @@ class ExplorationFragmentPresenter @Inject constructor( internalProfileId = args.profileId.internalId val stateFragment = StateFragment.newInstance( - args.profileId.internalId, args.topicId, args.storyId, args.explorationId + args.profileId, args.topicId, args.storyId, args.explorationId ) logPracticeFragmentEvent(args.topicId, args.storyId, args.explorationId) if (getStateFragment() == null) { diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationManagerFragment.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationManagerFragment.kt index a7775707373..481eab8198e 100644 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationManagerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationManagerFragment.kt @@ -5,8 +5,8 @@ import android.os.Bundle import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment import org.oppia.android.app.model.ProfileId -import org.oppia.android.util.extensions.getProto -import org.oppia.android.util.extensions.putProto +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** @@ -26,13 +26,11 @@ class ExplorationManagerFragment : InjectableFragment() { super.onCreate(savedInstanceState) val profileId = checkNotNull(arguments) { "Expected arguments to be provided for fragment." - }.getProto(PROFILE_ID_ARGUMENT_KEY, ProfileId.getDefaultInstance()) + }.extractCurrentUserProfileId() explorationManagerFragmentPresenter.handleCreate(profileId) } companion object { - private const val PROFILE_ID_ARGUMENT_KEY = "ExplorationManagerFragment.profile_id" - /** * Returns a new instance of [ExplorationManagerFragment] corresponding to the specified * [profileId]. @@ -40,7 +38,7 @@ class ExplorationManagerFragment : InjectableFragment() { fun createNewInstance(profileId: ProfileId): ExplorationManagerFragment { return ExplorationManagerFragment().apply { arguments = Bundle().apply { - putProto(PROFILE_ID_ARGUMENT_KEY, profileId) + decorateWithUserProfileId(profileId) } } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt index e55b81ef35d..f47045567dd 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment import org.oppia.android.app.model.HelpIndex +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.UserAnswer import org.oppia.android.app.player.state.answerhandling.InteractionAnswerErrorOrAvailabilityCheckReceiver import org.oppia.android.app.player.state.answerhandling.InteractionAnswerHandler @@ -20,6 +21,8 @@ import org.oppia.android.app.player.state.listener.ReturnToTopicNavigationButton import org.oppia.android.app.player.state.listener.ShowHintAvailabilityListener import org.oppia.android.app.player.state.listener.SubmitNavigationButtonListener import org.oppia.android.util.extensions.getStringFromBundle +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject /** Fragment that represents the current state of an exploration. */ @@ -45,14 +48,14 @@ class StateFragment : * @return a new instance of [StateFragment]. */ fun newInstance( - internalProfileId: Int, + profileId: ProfileId, topicId: String, storyId: String, explorationId: String ): StateFragment { val stateFragment = StateFragment() val args = Bundle() - args.putInt(STATE_FRAGMENT_PROFILE_ID_ARGUMENT_KEY, internalProfileId) + args.decorateWithUserProfileId(profileId) args.putString(STATE_FRAGMENT_TOPIC_ID_ARGUMENT_KEY, topicId) args.putString(STATE_FRAGMENT_STORY_ID_ARGUMENT_KEY, storyId) args.putString(STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY, explorationId) @@ -74,7 +77,7 @@ class StateFragment : container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val internalProfileId = arguments!!.getInt(STATE_FRAGMENT_PROFILE_ID_ARGUMENT_KEY, -1) + val profileId = arguments!!.extractCurrentUserProfileId() val topicId = arguments!!.getStringFromBundle(STATE_FRAGMENT_TOPIC_ID_ARGUMENT_KEY)!! val storyId = arguments!!.getStringFromBundle(STATE_FRAGMENT_STORY_ID_ARGUMENT_KEY)!! val explorationId = @@ -82,7 +85,7 @@ class StateFragment : return stateFragmentPresenter.handleCreateView( inflater, container, - internalProfileId, + profileId, topicId, storyId, explorationId diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt index d13a5dca065..224d938e683 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt @@ -55,8 +55,6 @@ import org.oppia.android.util.parser.html.ExplorationHtmlParserEntityType import org.oppia.android.util.system.OppiaClock import javax.inject.Inject -const val STATE_FRAGMENT_PROFILE_ID_ARGUMENT_KEY = - "StateFragmentPresenter.state_fragment_profile_id" const val STATE_FRAGMENT_TOPIC_ID_ARGUMENT_KEY = "StateFragmentPresenter.state_fragment_topic_id" const val STATE_FRAGMENT_STORY_ID_ARGUMENT_KEY = "StateFragmentPresenter.state_fragment_story_id" const val STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY = @@ -108,12 +106,12 @@ class StateFragmentPresenter @Inject constructor( fun handleCreateView( inflater: LayoutInflater, container: ViewGroup?, - internalProfileId: Int, + profileId: ProfileId, topicId: String, storyId: String, explorationId: String ): View? { - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + this.profileId = profileId this.topicId = topicId this.storyId = storyId this.explorationId = explorationId @@ -273,7 +271,7 @@ class StateFragmentPresenter @Inject constructor( private fun getAudioUiManager(): AudioUiManager? { if (getAudioFragment() == null) { - val audioFragment: AudioFragment = AudioFragment.newInstance(profileId.internalId) + val audioFragment: AudioFragment = AudioFragment.newInstance(profileId) fragment.childFragmentManager.beginTransaction() .add(R.id.audio_fragment_placeholder, audioFragment, TAG_AUDIO_FRAGMENT).commitNow() } diff --git a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt index 07e0c179795..c0cf543905a 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt @@ -19,10 +19,10 @@ import org.oppia.android.app.player.exploration.TAG_HINTS_AND_SOLUTION_DIALOG import org.oppia.android.app.player.state.listener.RouteToHintsAndSolutionListener import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener import org.oppia.android.app.player.stopplaying.StopStatePlayingSessionWithSavedProgressListener +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId import javax.inject.Inject -internal const val TEST_ACTIVITY_PROFILE_ID_EXTRA_KEY = - "StateFragmentTestActivity.test_activity_profile_id" internal const val TEST_ACTIVITY_TOPIC_ID_EXTRA_KEY = "StateFragmentTestActivity.test_activity_topic_id" internal const val TEST_ACTIVITY_STORY_ID_EXTRA_KEY = @@ -52,9 +52,7 @@ class StateFragmentTestActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) - profileId = ProfileId.newBuilder().apply { - internalId = intent.getIntExtra(TEST_ACTIVITY_PROFILE_ID_EXTRA_KEY, -1) - }.build() + profileId = intent.extractCurrentUserProfileId() stateFragmentTestActivityPresenter.handleOnCreate() } @@ -69,14 +67,13 @@ class StateFragmentTestActivity : companion object { fun createTestActivityIntent( context: Context, - profileId: Int, + profileId: ProfileId, topicId: String, storyId: String, explorationId: String, shouldSavePartialProgress: Boolean ): Intent { val intent = Intent(context, StateFragmentTestActivity::class.java) - intent.putExtra(TEST_ACTIVITY_PROFILE_ID_EXTRA_KEY, profileId) intent.putExtra(TEST_ACTIVITY_TOPIC_ID_EXTRA_KEY, topicId) intent.putExtra(TEST_ACTIVITY_STORY_ID_EXTRA_KEY, storyId) intent.putExtra(TEST_ACTIVITY_EXPLORATION_ID_EXTRA_KEY, explorationId) @@ -84,6 +81,7 @@ class StateFragmentTestActivity : TEST_ACTIVITY_SHOULD_SAVE_PARTIAL_PROGRESS_EXTRA_KEY, shouldSavePartialProgress ) + intent.decorateWithUserProfileId(profileId) return intent } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt index 312e5477daa..eaa8d7e8eba 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt @@ -19,6 +19,7 @@ import org.oppia.android.domain.topic.TEST_STORY_ID_0 import org.oppia.android.domain.topic.TEST_TOPIC_ID_0 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 javax.inject.Inject private const val TEST_ACTIVITY_TAG = "TestActivity" @@ -32,7 +33,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( private val viewModelProvider: ViewModelProvider ) { - private var profileId: Int = 1 + private lateinit var profileId: ProfileId private lateinit var topicId: String private lateinit var storyId: String private lateinit var explorationId: String @@ -48,7 +49,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( viewModel = getStateFragmentTestViewModel() } - profileId = activity.intent.getIntExtra(TEST_ACTIVITY_PROFILE_ID_EXTRA_KEY, 1) + profileId = activity.intent.extractCurrentUserProfileId() topicId = activity.intent.getStringExtra(TEST_ACTIVITY_TOPIC_ID_EXTRA_KEY) ?: TEST_TOPIC_ID_0 storyId = @@ -59,7 +60,10 @@ class StateFragmentTestActivityPresenter @Inject constructor( shouldSavePartialProgress = activity.intent.getBooleanExtra(TEST_ACTIVITY_SHOULD_SAVE_PARTIAL_PROGRESS_EXTRA_KEY, false) activity.findViewById