Skip to content

Commit

Permalink
Fix part of #5344: Introduce & modify controllers to support multiple…
Browse files Browse the repository at this point in the history
… classrooms (#5419)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

Fixes part of #5344
- Introduces `ClassroomController` to surface `getClassroomList`
function and adds relevant tests.
- Adds `getTopicList` function in the `ClassroomController` and its
tests.
- Modifies `ProfileManagementController` to store the
`last_selected_classroom_id` per profile and adds its tests.

## 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)).

## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide))
- For PRs introducing new UI elements or color changes, both light and
dark mode screenshots must be included
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing
  • Loading branch information
theMr17 authored Jun 26, 2024
1 parent 9a2e627 commit dee27c0
Show file tree
Hide file tree
Showing 8 changed files with 910 additions and 5 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ private const val SET_SURVEY_LAST_SHOWN_TIMESTAMP_PROVIDER_ID =
"record_survey_last_shown_timestamp_provider_id"
private const val RETRIEVE_SURVEY_LAST_SHOWN_TIMESTAMP_PROVIDER_ID =
"retrieve_survey_last_shown_timestamp_provider_id"
private const val SET_LAST_SELECTED_CLASSROOM_ID_PROVIDER_ID =
"set_last_selected_classroom_id_provider_id"
private const val RETRIEVE_LAST_SELECTED_CLASSROOM_ID_PROVIDER_ID =
"retrieve_last_selected_classroom_id_provider_id"

/** Controller for retrieving, adding, updating, and deleting profiles. */
@Singleton
Expand Down Expand Up @@ -851,6 +855,47 @@ class ProfileManagementController @Inject constructor(
}
}

/**
* Sets the last selected [classroomId] for the specified [profileId]. Returns a [DataProvider]
* indicating whether the save was a success.
*/
fun updateLastSelectedClassroomId(
profileId: ProfileId,
classroomId: String
): DataProvider<Any?> {
val deferred = profileDataStore.storeDataWithCustomChannelAsync(
updateInMemoryCache = true
) { profileDatabase ->
val profile = profileDatabase.profilesMap[profileId.internalId]
val updatedProfile = profile?.toBuilder()?.setLastSelectedClassroomId(
classroomId
)?.build()
val profileDatabaseBuilder = profileDatabase.toBuilder().putProfiles(
profileId.internalId,
updatedProfile
)
Pair(profileDatabaseBuilder.build(), ProfileActionStatus.SUCCESS)
}
return dataProviders.createInMemoryDataProviderAsync(
SET_LAST_SELECTED_CLASSROOM_ID_PROVIDER_ID
) {
return@createInMemoryDataProviderAsync getDeferredResult(profileId, null, deferred)
}
}

/**
* Returns a [DataProvider] containing a nullable last selected classroom ID for the specified
* [profileId].
*/
fun retrieveLastSelectedClassroomId(
profileId: ProfileId
): DataProvider<String?> {
return profileDataStore.transformAsync(RETRIEVE_LAST_SELECTED_CLASSROOM_ID_PROVIDER_ID) {
val lastSelectedClassroomId = it.profilesMap[profileId.internalId]?.lastSelectedClassroomId
AsyncResult.Success(lastSelectedClassroomId)
}
}

private suspend fun getDeferredResult(
profileId: ProfileId?,
name: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.oppia.android.app.model.TopicProgress
import org.oppia.android.app.model.TopicRecord
import org.oppia.android.app.model.TopicSummary
import org.oppia.android.app.model.UpcomingTopic
import org.oppia.android.domain.classroom.TEST_CLASSROOM_ID_0
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.domain.util.JsonAssetRetriever
import org.oppia.android.domain.util.getStringFromObject
Expand Down Expand Up @@ -60,11 +61,6 @@ const val SUBTOPIC_TOPIC_ID = 1
const val SUBTOPIC_TOPIC_ID_2 = 2
const val RATIOS_TOPIC_ID = "omzF4oqgeTXd"

// TODO(#5344): Move these classroom ids to [ClassroomController].
const val TEST_CLASSROOM_ID_0 = "test_classroom_id_0"
const val TEST_CLASSROOM_ID_1 = "test_classroom_id_1"
const val TEST_CLASSROOM_ID_2 = "test_classroom_id_2"

val TOPIC_THUMBNAILS = mapOf(
FRACTIONS_TOPIC_ID to createTopicThumbnail0(),
RATIOS_TOPIC_ID to createTopicThumbnail1(),
Expand Down
Loading

0 comments on commit dee27c0

Please sign in to comment.