Skip to content

Commit

Permalink
Refactor ProfileId provision process to multiple activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jainv4156 committed Feb 26, 2025
1 parent 469fe9c commit b6aa1de
Show file tree
Hide file tree
Showing 38 changed files with 107 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class ClassroomListActivity :
val recentlyPlayedActivityParams =
RecentlyPlayedActivityParams
.newBuilder()
.setProfileId(profileId)
.setActivityTitle(recentlyPlayedActivityTitle).build()

activityRouter.routeToScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class HomeActivity :
val recentlyPlayedActivityParams =
RecentlyPlayedActivityParams
.newBuilder()
.setProfileId(ProfileId.newBuilder().setInternalId(internalProfileId).build())
.setActivityTitle(recentlyPlayedActivityTitle).build()

activityRouter.routeToScreen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.oppia.android.app.home

import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ProfileId

/** Listener for when an activity should route to a exploration. */
interface RouteToExplorationListener {
fun routeToExploration(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class RecentlyPlayedActivity :
}

override fun routeToExploration(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -72,7 +71,6 @@ class RecentlyPlayedActivity :
startActivity(
ExplorationActivity.createExplorationActivityIntent(
this,
profileId,
classroomId,
topicId,
storyId,
Expand All @@ -84,7 +82,6 @@ class RecentlyPlayedActivity :
}

override fun routeToResumeLesson(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -95,7 +92,6 @@ class RecentlyPlayedActivity :
startActivity(
ResumeLessonActivity.createResumeLessonActivityIntent(
this,
profileId,
classroomId,
topicId,
storyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.RecentlyPlayedActivityBinding
import javax.inject.Inject
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId

/** The presenter for [RecentlyPlayedActivity]. */
@ActivityScope
Expand All @@ -32,7 +33,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(activity.intent.extractCurrentUserProfileId()),
RecentlyPlayedFragment.TAG_RECENTLY_PLAYED_FRAGMENT
).commitNow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class RecentlyPlayedFragment : InjectableFragment(), PromotedStoryClickListener
const val TAG_RECENTLY_PLAYED_FRAGMENT = "TAG_RECENTLY_PLAYED_FRAGMENT"

/** Returns a new [RecentlyPlayedFragment] to display recently played stories. */
fun newInstance(internalProfileId: Int): RecentlyPlayedFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
fun newInstance(profileId: ProfileId): RecentlyPlayedFragment {
return RecentlyPlayedFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -42,13 +41,7 @@ class RecentlyPlayedFragment : InjectableFragment(), PromotedStoryClickListener
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val arguments =
checkNotNull(arguments) { "Expected arguments to be passed to RecentlyPlayedFragment" }
val profileId =
arguments.extractCurrentUserProfileId()

val internalProfileId = profileId.internalId
return recentlyPlayedFragmentPresenter.handleCreateView(inflater, container, internalProfileId)
return recentlyPlayedFragmentPresenter.handleCreateView(inflater, container)
}

override fun promotedStoryClicked(promotedStory: PromotedStory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import javax.inject.Inject
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId

/** The presenter for [RecentlyPlayedFragment]. */
@FragmentScope
Expand All @@ -49,9 +50,9 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
internalProfileId: Int
): View? {
this.profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()

this.profileId = activity.intent.extractCurrentUserProfileId()
val recentlyPlayedViewModel = recentlyPlayedViewModelFactory.create(
fragment as PromotedStoryClickListener,
this.profileId
Expand Down Expand Up @@ -107,7 +108,6 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
if (it is AsyncResult.Success) {
explorationCheckpointLiveData.removeObserver(this)
routeToResumeLessonListener.routeToResumeLesson(
profileId,
promotedStory.classroomId,
promotedStory.topicId,
promotedStory.storyId,
Expand Down Expand Up @@ -195,7 +195,6 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
is AsyncResult.Success -> {
oppiaLogger.d("RecentlyPlayedFragment", "Successfully loaded exploration")
routeToExplorationListener.routeToExploration(
profileId,
classroomId,
topicId,
storyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.extensions.putProtoExtra
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName
import javax.inject.Inject
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId

const val TAG_HINTS_AND_SOLUTION_DIALOG = "HINTS_AND_SOLUTION_DIALOG"

Expand Down Expand Up @@ -59,9 +60,10 @@ class ExplorationActivity :
(activityComponent as ActivityComponentImpl).inject(this)

val params = intent.extractParams()
val profileId: ProfileId = intent.extractCurrentUserProfileId()
explorationActivityPresenter.handleOnCreate(
this,
params.profileId,
profileId,
params.classroomId,
params.topicId,
params.storyId,
Expand Down Expand Up @@ -89,7 +91,6 @@ class ExplorationActivity :
*/
fun createExplorationActivityIntent(
context: Context,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -98,7 +99,6 @@ class ExplorationActivity :
isCheckpointingEnabled: Boolean
): Intent {
val params = ExplorationActivityParams.newBuilder().apply {
this.profileId = profileId
this.classroomId = classroomId
this.topicId = topicId
this.storyId = storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ class ExplorationActivityPresenter @Inject constructor(
activity.supportFragmentManager.beginTransaction().add(
R.id.exploration_fragment_placeholder,
ExplorationFragment.newInstance(
profileId,
classroomId,
topicId,
storyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.ViewGroup
import org.oppia.android.app.fragment.FragmentComponentImpl
import org.oppia.android.app.fragment.InjectableFragment
import org.oppia.android.app.model.ExplorationFragmentArguments
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.util.extensions.putProto
import javax.inject.Inject
Expand All @@ -21,15 +20,13 @@ class ExplorationFragment : InjectableFragment() {
companion object {
/** Returns a new [ExplorationFragment] with the corresponding fragment parameters. */
fun newInstance(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
explorationId: String,
readingTextSize: ReadingTextSize
): ExplorationFragment {
val args = ExplorationFragmentArguments.newBuilder().apply {
this.profileId = profileId
this.classroomId = classroomId
this.topicId = topicId
this.storyId = storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.forEach
import androidx.fragment.app.Fragment
Expand All @@ -29,10 +30,12 @@ import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import javax.inject.Inject
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId

/** The presenter for [ExplorationFragment]. */
@FragmentScope
class ExplorationFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val oppiaLogger: OppiaLogger,
private val analyticsController: AnalyticsController,
Expand All @@ -41,7 +44,6 @@ class ExplorationFragmentPresenter @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler
) {

private var internalProfileId: Int = -1

/** Handles the [Fragment.onAttach] portion of [ExplorationFragment]'s lifecycle. */
fun handleAttach(context: Context) {
Expand All @@ -53,10 +55,9 @@ class ExplorationFragmentPresenter @Inject constructor(
val args = retrieveArguments()
val binding =
ExplorationFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root
internalProfileId = args.profileId.internalId
val stateFragment =
StateFragment.newInstance(
args.profileId.internalId, args.topicId, args.storyId, args.explorationId
args.topicId, args.storyId, args.explorationId
)
logPracticeFragmentEvent(args.classroomId, args.topicId, args.storyId, args.explorationId)
if (getStateFragment() == null) {
Expand All @@ -70,7 +71,7 @@ class ExplorationFragmentPresenter @Inject constructor(

/** Handles the [Fragment.onViewCreated] portion of [ExplorationFragment]'s lifecycle. */
fun handleViewCreated() {
val profileDataProvider = profileManagementController.getProfile(retrieveArguments().profileId)
val profileDataProvider = profileManagementController.getProfile(activity.intent.extractCurrentUserProfileId())
profileDataProvider.toLiveData().observe(
fragment
) { result ->
Expand Down Expand Up @@ -161,7 +162,7 @@ class ExplorationFragmentPresenter @Inject constructor(
oppiaLogger.createOpenExplorationActivityContext(
classroomId, topicId, storyId, explorationId
),
ProfileId.newBuilder().apply { internalId = internalProfileId }.build()
activity.intent.extractCurrentUserProfileId()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ class StateFragment :
* @return a new instance of [StateFragment].
*/
fun newInstance(
internalProfileId: Int,
topicId: String,
storyId: String,
explorationId: String
): StateFragment {

val args = StateFragmentArguments.newBuilder().apply {
this.internalProfileId = internalProfileId
this.topicId = topicId
this.storyId = storyId
this.explorationId = explorationId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class StateFragmentTestActivityPresenter @Inject constructor(
oppiaLogger.e(TEST_ACTIVITY_TAG, "Failed to load exploration", result.error)
is AsyncResult.Success -> {
oppiaLogger.d(TEST_ACTIVITY_TAG, "Successfully loaded exploration")
initializeExploration(profileId, topicId, storyId, explorationId)
initializeExploration( topicId, storyId, explorationId)
}
}
}
Expand All @@ -134,14 +134,13 @@ class StateFragmentTestActivityPresenter @Inject constructor(
* session is fully started).
*/
private fun initializeExploration(
profileId: Int,
topicId: String,
storyId: String,
explorationId: String
) {
stateFragmentTestViewModel.hasExplorationStarted.set(true)

val stateFragment = StateFragment.newInstance(profileId, topicId, storyId, explorationId)
val stateFragment = StateFragment.newInstance( topicId, storyId, explorationId)
activity.supportFragmentManager.beginTransaction().add(
R.id.state_fragment_placeholder,
stateFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ProfileProgressActivity :
val recentlyPlayedActivityParams =
RecentlyPlayedActivityParams
.newBuilder()
.setProfileId(ProfileId.newBuilder().setInternalId(internalProfileId).build())
.setActivityTitle(recentlyPlayedActivityTitle)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.extensions.putProtoExtra
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName
import javax.inject.Inject
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId

/** Activity that allows the user to resume a saved exploration. */
class ResumeLessonActivity :
Expand All @@ -33,8 +34,9 @@ class ResumeLessonActivity :
(activityComponent as ActivityComponentImpl).inject(this)

val params = intent.getProtoExtra(PARAMS_KEY, ResumeLessonActivityParams.getDefaultInstance())
val profileId :ProfileId = intent.extractCurrentUserProfileId()
resumeLessonActivityPresenter.handleOnCreate(
params.profileId,
profileId,
params.classroomId,
params.topicId,
params.storyId,
Expand Down Expand Up @@ -63,7 +65,6 @@ class ResumeLessonActivity :
*/
fun createResumeLessonActivityIntent(
context: Context,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -72,7 +73,6 @@ class ResumeLessonActivity :
checkpoint: ExplorationCheckpoint
): Intent {
val params = ResumeLessonActivityParams.newBuilder().apply {
this.profileId = profileId
this.classroomId = classroomId
this.topicId = topicId
this.storyId = storyId
Expand All @@ -96,7 +96,6 @@ class ResumeLessonActivity :
}

override fun routeToExploration(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -108,7 +107,6 @@ class ResumeLessonActivity :
startActivity(
ExplorationActivity.createExplorationActivityIntent(
this,
profileId,
classroomId,
topicId,
storyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class ResumeLessonActivityPresenter @Inject constructor(
.remove(getResumeLessonFragment() as Fragment).commitNow()

val resumeLessonFragment = ResumeLessonFragment.newInstance(
profileId,
classroomId,
topicId,
storyId,
Expand Down
Loading

0 comments on commit b6aa1de

Please sign in to comment.