Skip to content

Commit

Permalink
Fix part of #4865: Refactor topic to use profileId (#5598)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
### Fixes part of #4865 

This PR aim to refactor `topic` package to use `ProfileId`
Changes include all topic fragments, presenters, and TopicActivity
Also updated the test classes.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

---------

Co-authored-by: Adhiambo Peres <[email protected]>
  • Loading branch information
tobioyelekan and adhiamboperes authored Dec 23, 2024
1 parent 3ada868 commit 8f47196
Show file tree
Hide file tree
Showing 49 changed files with 362 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ class ClassroomListActivity :
)
}

override fun routeToTopic(internalProfileId: Int, classroomId: String, topicId: String) {
override fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String) {
startActivity(
createTopicActivityIntent(this, internalProfileId, classroomId, topicId)
createTopicActivityIntent(this, profileId, classroomId, topicId)
)
}

override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
) {
startActivity(
createTopicPlayStoryActivityIntent(
this,
internalProfileId,
profileId,
classroomId,
topicId,
storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ClassroomListFragmentPresenter @Inject constructor(
/** Routes to the play story view for the first story in the given topic summary. */
fun onTopicSummaryClicked(topicSummary: TopicSummary) {
routeToTopicPlayStoryListener.routeToTopicPlayStory(
profileId.internalId,
profileId,
topicSummary.classroomId,
topicSummary.topicId,
topicSummary.firstStoryId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,22 +33,22 @@ class CompletedStoryItemViewModel(
/** Called when user clicks on CompletedStoryItem. */
fun onCompletedStoryItemClicked() {
routeToTopicPlayStory(
internalProfileId,
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
completedStory.classroomId,
completedStory.topicId,
completedStory.storyId
)
}

override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
) {
val intent = intentFactoryShim.createTopicPlayStoryActivityIntent(
activity.applicationContext,
internalProfileId,
profileId.internalId,
classroomId,
topicId,
storyId
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/oppia/android/app/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ class HomeActivity :
title = resourceHandler.getStringInLocale(R.string.home_activity_title)
}

override fun routeToTopic(internalProfileId: Int, classroomId: String, topicId: String) {
override fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String) {
startActivity(
TopicActivity.createTopicActivityIntent(this, internalProfileId, classroomId, topicId)
TopicActivity.createTopicActivityIntent(this, profileId, classroomId, topicId)
)
}

override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
) {
startActivity(
TopicActivity.createTopicPlayStoryActivityIntent(
this,
internalProfileId,
profileId,
classroomId,
topicId,
storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class HomeFragmentPresenter @Inject constructor(

fun onTopicSummaryClicked(topicSummary: TopicSummary) {
routeToTopicPlayStoryListener.routeToTopicPlayStory(
internalProfileId,
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
topicSummary.classroomId,
topicSummary.topicId,
topicSummary.firstStoryId
Expand Down
Original file line number Diff line number Diff line change
@@ -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, classroomId: String, topicId: String)
fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +63,7 @@ class PromotedStoryViewModel(

fun clickOnStoryTile() {
routeToTopicPlayStoryListener.routeToTopicPlayStory(
internalProfileId,
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
promotedStory.classroomId,
promotedStory.topicId,
promotedStory.storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +28,11 @@ class OngoingTopicItemViewModel(
}

fun onTopicItemClicked() {
routeToTopic(internalProfileId, topic.classroomId, topic.topicId)
routeToTopic(
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build(),
classroomId = topic.classroomId,
topicId = topic.topicId
)
}

fun computeStoryCountText(): String {
Expand All @@ -36,7 +41,7 @@ class OngoingTopicItemViewModel(
)
}

override fun routeToTopic(internalProfileId: Int, classroomId: String, topicId: String) {
override fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String) {
val intent = intentFactoryShim.createTopicActivityIntent(
activity.applicationContext,
internalProfileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class ExplorationActivityPresenter @Inject constructor(
activity.startActivity(
TopicActivity.createTopicActivityIntent(
context,
profileId.internalId,
profileId,
classroomId,
topicId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.profileprogress
import androidx.appcompat.app.AppCompatActivity
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.shim.IntentFactoryShim
import org.oppia.android.app.translation.AppLanguageResourceHandler
Expand Down Expand Up @@ -36,7 +37,10 @@ class RecentlyPlayedStorySummaryViewModel(

fun onStoryItemClicked() {
routeToTopicPlayStory(
internalProfileId, promotedStory.classroomId, promotedStory.topicId, promotedStory.storyId
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build(),
classroomId = promotedStory.classroomId,
topicId = promotedStory.topicId,
storyId = promotedStory.storyId
)
}

Expand All @@ -47,14 +51,14 @@ class RecentlyPlayedStorySummaryViewModel(
}

override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
) {
val intent = intentFactoryShim.createTopicPlayStoryActivityIntent(
activity.applicationContext,
internalProfileId,
profileId.internalId,
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.home.HomeFragment
import org.oppia.android.app.home.RouteToRecentlyPlayedListener
import org.oppia.android.app.home.RouteToTopicListener
import org.oppia.android.app.home.RouteToTopicPlayStoryListener
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ProfileType
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.testing.activity.TestActivity
Expand Down Expand Up @@ -36,9 +37,9 @@ class HomeFragmentTestActivity :
}

// Override functions are needed to fulfill listener definitions.
override fun routeToTopic(internalProfileId: Int, classroomId: String, topicId: String) {}
override fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String) {}
override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ class NavigationDrawerTestActivity :
title = resourceHandler.getStringInLocale(R.string.home_activity_title)
}

override fun routeToTopic(internalProfileId: Int, classroomId: String, topicId: String) {
override fun routeToTopic(profileId: ProfileId, classroomId: String, topicId: String) {
startActivity(
TopicActivity.createTopicActivityIntent(this, internalProfileId, classroomId, topicId)
TopicActivity.createTopicActivityIntent(this, profileId, classroomId, topicId)
)
}

override fun routeToTopicPlayStory(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String,
storyId: String
) {
startActivity(
TopicActivity.createTopicPlayStoryActivityIntent(
this,
internalProfileId,
profileId,
classroomId,
topicId,
storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.testing
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.topic.RouteToRevisionCardListener
import org.oppia.android.app.topic.revision.TopicRevisionFragment
import org.oppia.android.app.topic.revisioncard.RevisionCardActivity
Expand All @@ -23,15 +24,15 @@ class TopicRevisionTestActivity :
}

override fun routeToRevisionCard(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
subtopicId: Int,
subtopicListSize: Int
) {
startActivity(
RevisionCardActivity.createRevisionCardActivityIntent(
this,
internalProfileId,
profileId,
topicId,
subtopicId,
subtopicListSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.testing
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 org.oppia.android.app.topic.revision.TopicRevisionFragment
import javax.inject.Inject

Expand All @@ -14,8 +15,9 @@ class TopicRevisionTestActivityPresenter @Inject constructor(

fun handleOnCreate() {
activity.setContentView(R.layout.topic_revision_test_activity)
val profileId = ProfileId.newBuilder().setInternalId(0).build()
val topicRevisionFragment =
TopicRevisionFragment.newInstance(internalProfileId = 0, topicId = "")
TopicRevisionFragment.newInstance(profileId = profileId, topicId = "")
activity.supportFragmentManager.beginTransaction()
.add(
R.id.topic_revision_container,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class TopicTestActivity :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val profileId = ProfileId.newBuilder().setInternalId(0).build()
(activityComponent as ActivityComponentImpl).inject(this)
topicActivityPresenter.handleOnCreate(
internalProfileId = 0,
profileId = profileId,
classroomId = TEST_CLASSROOM_ID_0,
topicId = TEST_TOPIC_ID_0,
storyId = ""
Expand Down Expand Up @@ -90,14 +91,14 @@ class TopicTestActivity :
}

override fun routeToRevisionCard(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
subtopicId: Int,
subtopicListSize: Int
) {
startActivity(
RevisionCardActivity.createRevisionCardActivityIntent(
this, internalProfileId, topicId, subtopicId, subtopicListSize
this, profileId, topicId, subtopicId, subtopicListSize
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class TopicTestActivityForStory :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val profileId = ProfileId.newBuilder().setInternalId(0).build()
(activityComponent as ActivityComponentImpl).inject(this)
topicActivityPresenter.handleOnCreate(
internalProfileId = 0,
profileId = profileId,
classroomId = TEST_CLASSROOM_ID_0,
topicId = TEST_TOPIC_ID_0,
storyId = TEST_STORY_ID_0
Expand Down Expand Up @@ -118,14 +119,14 @@ class TopicTestActivityForStory :
}

override fun routeToRevisionCard(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
subtopicId: Int,
subtopicListSize: Int
) {
startActivity(
RevisionCardActivity.createRevisionCardActivityIntent(
this, internalProfileId, topicId, subtopicId, subtopicListSize
this, profileId, topicId, subtopicId, subtopicListSize
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.oppia.android.app.topic

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

/** Listener for when an [TopicActivity] should route to a [RevisionCardFragment]. */
interface RouteToRevisionCardListener {
fun routeToRevisionCard(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
subtopicId: Int,
subtopicListSize: Int
Expand Down
Loading

0 comments on commit 8f47196

Please sign in to comment.