Skip to content

Commit

Permalink
Merge branch 'oppia:develop' into migrate-onBackPressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas-67 authored Jun 27, 2024
2 parents 11ea757 + c5de68b commit df088a8
Show file tree
Hide file tree
Showing 22 changed files with 2,317 additions and 62 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 df088a8

Please sign in to comment.