Skip to content

Commit

Permalink
Merge branch 'develop' into kavyanshkhandelwal/#5273/fix-unused-attri…
Browse files Browse the repository at this point in the history
…bute-warning
  • Loading branch information
kavyanshkhandelwal authored Jan 11, 2025
2 parents 84c18cb + 965861f commit 42210e8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,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,
Expand All @@ -33,7 +33,7 @@ class CompletedStoryItemViewModel(
/** Called when user clicks on CompletedStoryItem. */
fun onCompletedStoryItemClicked() {
routeToTopicPlayStory(
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
profileId,
completedStory.classroomId,
completedStory.topicId,
completedStory.storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class CompletedStoryListActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

val internalProfileId: Int = intent?.extractCurrentUserProfileId()?.internalId ?: -1
completedStoryListActivityPresenter.handleOnCreate(internalProfileId)
val profileId = intent?.extractCurrentUserProfileId() ?: ProfileId.getDefaultInstance()
completedStoryListActivityPresenter.handleOnCreate(profileId)
}

companion object {
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.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.model.ProfileId
import javax.inject.Inject

/** The presenter for [CompletedStoryListActivity]. */
Expand All @@ -12,15 +13,15 @@ class CompletedStoryListActivityPresenter @Inject constructor(
) {

/** 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
.supportFragmentManager
.beginTransaction()
.add(
R.id.completed_story_list_fragment_placeholder,
CompletedStoryListFragment.newInstance(internalProfileId),
CompletedStoryListFragment.newInstance(profileId),
CompletedStoryListFragment.COMPLETED_STORY_LIST_FRAGMENT_TAG
).commitNow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class CompletedStoryListFragment : InjectableFragment() {
const val COMPLETED_STORY_LIST_FRAGMENT_TAG = "COMPLETED_STORY_LIST_FRAGMENT_TAG"

/** Returns a new [CompletedStoryListFragment] to display corresponding to the specified profile ID. */
fun newInstance(internalProfileId: Int): CompletedStoryListFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
fun newInstance(profileId: ProfileId): CompletedStoryListFragment {
return CompletedStoryListFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -47,11 +46,10 @@ class CompletedStoryListFragment : InjectableFragment() {
"Expected arguments to be passed to CompletedStoryListFragment"
}
val profileId = arguments.extractCurrentUserProfileId()
val internalProfileId = profileId.internalId
return completedStoryListFragmentPresenter.handleCreateView(
inflater,
container,
internalProfileId
profileId
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.databinding.CompletedStoryItemBinding
import org.oppia.android.databinding.CompletedStoryListFragmentBinding
Expand All @@ -26,9 +27,9 @@ class CompletedStoryListFragmentPresenter @Inject constructor(
fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
internalProfileId: Int
profileId: ProfileId
): View? {
viewModel.setProfileId(internalProfileId)
viewModel.setProfileId(profileId)

binding = CompletedStoryListFragmentBinding
.inflate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ 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 var profileId: ProfileId = ProfileId.getDefaultInstance()

private val completedStoryListResultLiveData: LiveData<AsyncResult<CompletedStoryList>> by lazy {
topicController.getCompletedStoryList(
ProfileId.newBuilder().setInternalId(internalProfileId).build()
).toLiveData()
topicController.getCompletedStoryList(profileId).toLiveData()
}

private val completedStoryLiveData: LiveData<CompletedStoryList> by lazy {
Expand All @@ -45,8 +43,8 @@ class CompletedStoryListViewModel @Inject constructor(
}

/** Sets internalProfileId to this ViewModel. */
fun setProfileId(internalProfileId: Int) {
this.internalProfileId = internalProfileId
fun setProfileId(profileId: ProfileId) {
this.profileId = profileId
}

private fun processCompletedStoryListResult(
Expand Down Expand Up @@ -74,7 +72,7 @@ class CompletedStoryListViewModel @Inject constructor(
completedStoryList.completedStoryList.map { completedStory ->
CompletedStoryItemViewModel(
activity,
internalProfileId,
profileId,
completedStory,
entityType,
intentFactoryShim,
Expand Down

0 comments on commit 42210e8

Please sign in to comment.