Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ProfileId provision process to multiple activity #7

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -10,7 +10,6 @@ import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.home.RouteToExplorationListener
import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ExplorationCheckpoint
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.RecentlyPlayedActivityParams
import org.oppia.android.app.model.ScreenName
import org.oppia.android.app.player.exploration.ExplorationActivity
Expand Down Expand Up @@ -61,7 +60,6 @@ class RecentlyPlayedActivity :
}

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

override fun routeToResumeLesson(
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String,
Expand All @@ -95,7 +91,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 @@ -8,6 +8,7 @@ import org.oppia.android.app.model.RecentlyPlayedActivityParams
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.RecentlyPlayedActivityBinding
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import javax.inject.Inject

/** The presenter for [RecentlyPlayedActivity]. */
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 @@ -10,7 +10,6 @@ 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

/** Fragment that contains all recently played stories. */
Expand All @@ -19,8 +18,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 +40,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 @@ -26,6 +26,8 @@ import org.oppia.android.domain.exploration.lightweightcheckpointing.Exploration
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import javax.inject.Inject

/** The presenter for [RecentlyPlayedFragment]. */
Expand All @@ -49,9 +51,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 @@ -106,8 +108,8 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
override fun onChanged(it: AsyncResult<ExplorationCheckpoint>) {
if (it is AsyncResult.Success) {
explorationCheckpointLiveData.removeObserver(this)
activity.intent.decorateWithUserProfileId(profileId)
routeToResumeLessonListener.routeToResumeLesson(
profileId,
promotedStory.classroomId,
promotedStory.topicId,
promotedStory.storyId,
Expand Down Expand Up @@ -194,8 +196,8 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
oppiaLogger.e("RecentlyPlayedFragment", "Failed to load exploration", result.error)
is AsyncResult.Success -> {
oppiaLogger.d("RecentlyPlayedFragment", "Successfully loaded exploration")
activity.intent.decorateWithUserProfileId(profileId)
routeToExplorationListener.routeToExploration(
profileId,
classroomId,
topicId,
storyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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.extractCurrentUserProfileId
import javax.inject.Inject

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,13 +5,13 @@ 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
import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
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.app.model.Spotlight
import org.oppia.android.app.player.state.StateFragment
Expand All @@ -28,11 +28,13 @@ import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import javax.inject.Inject

/** 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 +43,7 @@ class ExplorationFragmentPresenter @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler
) {

private var internalProfileId: Int = -1
val profileId = activity.intent.extractCurrentUserProfileId()

/** 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
profileId.internalId, args.topicId, args.storyId, args.explorationId
)
logPracticeFragmentEvent(args.classroomId, args.topicId, args.storyId, args.explorationId)
if (getStateFragment() == null) {
Expand All @@ -70,14 +71,16 @@ 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(
profileId
)
profileDataProvider.toLiveData().observe(
fragment
) { result ->
val readingTextSize = retrieveArguments().readingTextSize
if (result is AsyncResult.Success) {
if (result.value.readingTextSize != readingTextSize) {

// Since text views are based on sp for sizing, the activity needs to be recreated so that
// sp can be correctly recomputed.
selectNewReadingTextSize(result.value.readingTextSize)
Expand Down Expand Up @@ -161,7 +164,7 @@ class ExplorationFragmentPresenter @Inject constructor(
oppiaLogger.createOpenExplorationActivityContext(
classroomId, topicId, storyId, explorationId
),
ProfileId.newBuilder().apply { internalId = internalProfileId }.build()
profileId
)
}

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,7 +134,6 @@ class StateFragmentTestActivityPresenter @Inject constructor(
* session is fully started).
*/
private fun initializeExploration(
profileId: Int,
topicId: String,
storyId: String,
explorationId: String
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 @@ -18,6 +18,7 @@ import org.oppia.android.app.player.exploration.ExplorationActivity
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.extractCurrentUserProfileId
import javax.inject.Inject

/** Activity that allows the user to resume a saved exploration. */
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
Loading