diff --git a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/PromotedStoryViewModel.kt b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/PromotedStoryViewModel.kt index f93fba2613c..9dca136cefd 100755 --- a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/PromotedStoryViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/PromotedStoryViewModel.kt @@ -18,6 +18,7 @@ class PromotedStoryViewModel( private val promotedStoryClickListener: PromotedStoryClickListener, private val position: Int, private val resourceHandler: AppLanguageResourceHandler, + val showClassroomLabel: Boolean, translationController: TranslationController ) : RecentlyPlayedItemViewModel() { /** Sets the story title of the recently played story. */ @@ -38,6 +39,12 @@ class PromotedStoryViewModel( promotedStory.nextChapterTitle, promotedStory.nextChapterWrittenTranslationContext ) } + /** Sets the classroom of the recently played story. */ + val classroomTitle by lazy { + translationController.extractString( + promotedStory.classroomTitle, promotedStory.classroomWrittenTranslationContext + ) + } /** * Starts [ResumeLessonActivity] if a saved exploration is selected or [ExplorationActivity] if an diff --git a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedViewModel.kt b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedViewModel.kt index 7716fdf11f5..1542e63bb5a 100644 --- a/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/home/recentlyplayed/RecentlyPlayedViewModel.kt @@ -13,6 +13,8 @@ import org.oppia.android.domain.translation.TranslationController import org.oppia.android.util.data.AsyncResult import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.parser.html.StoryHtmlParserEntityType +import org.oppia.android.util.platformparameter.EnableMultipleClassrooms +import org.oppia.android.util.platformparameter.PlatformParameterValue import javax.inject.Inject /** View model for [RecentlyPlayedFragment]. */ @@ -22,6 +24,7 @@ class RecentlyPlayedViewModel private constructor( @StoryHtmlParserEntityType private val entityType: String, private val resourceHandler: AppLanguageResourceHandler, private val translationController: TranslationController, + private val enableMultipleClassrooms: PlatformParameterValue, private val promotedStoryClickListener: PromotedStoryClickListener, private val profileId: ProfileId, ) { @@ -33,6 +36,8 @@ class RecentlyPlayedViewModel private constructor( @StoryHtmlParserEntityType private val entityType: String, private val resourceHandler: AppLanguageResourceHandler, private val translationController: TranslationController, + @EnableMultipleClassrooms + private val enableMultipleClassrooms: PlatformParameterValue, ) { /** Creates an instance of [RecentlyPlayedViewModel]. */ @@ -46,6 +51,7 @@ class RecentlyPlayedViewModel private constructor( entityType, resourceHandler, translationController, + enableMultipleClassrooms, promotedStoryClickListener, profileId, ) @@ -166,6 +172,7 @@ class RecentlyPlayedViewModel private constructor( promotedStoryClickListener, index, resourceHandler, + enableMultipleClassrooms.value, translationController ) } diff --git a/app/src/main/res/drawable/classroom_label_text_background.xml b/app/src/main/res/drawable/classroom_label_text_background.xml new file mode 100644 index 00000000000..3a316756f7d --- /dev/null +++ b/app/src/main/res/drawable/classroom_label_text_background.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/app/src/main/res/layout/recently_played_story_card.xml b/app/src/main/res/layout/recently_played_story_card.xml index 6dff08a05de..0994de8f994 100755 --- a/app/src/main/res/layout/recently_played_story_card.xml +++ b/app/src/main/res/layout/recently_played_story_card.xml @@ -86,10 +86,29 @@ android:text="@{viewModel.topicTitle}" android:textAllCaps="true" android:textColor="@color/component_color_shared_story_card_topic_name_text_color" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@id/classroom_name_text_view" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/story_name_text_view" /> + + diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt index c45a0580213..9cf3f4ebf3e 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt @@ -97,7 +97,6 @@ import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule -import org.oppia.android.domain.platformparameter.PlatformParameterModule import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule import org.oppia.android.domain.question.QuestionModule import org.oppia.android.domain.topic.FRACTIONS_EXPLORATION_ID_0 @@ -111,6 +110,7 @@ import org.oppia.android.testing.firebase.TestAuthenticationModule import org.oppia.android.testing.junit.InitializeDefaultLocaleRule import org.oppia.android.testing.lightweightcheckpointing.ExplorationCheckpointTestHelper import org.oppia.android.testing.lightweightcheckpointing.FRACTIONS_STORY_0_EXPLORATION_0_CURRENT_VERSION +import org.oppia.android.testing.platformparameter.TestPlatformParameterModule import org.oppia.android.testing.profile.ProfileTestHelper import org.oppia.android.testing.robolectric.RobolectricModule import org.oppia.android.testing.story.StoryProgressTestHelper @@ -457,6 +457,66 @@ class RecentlyPlayedFragmentTest { } } + @Test + fun testRecentlyPlayedTestActivity_disableClassrooms_recommendedSection_classroomNameIsNotDisplayed() { // ktlint-disable max-line-length + TestPlatformParameterModule.forceEnableMultipleClassrooms(false) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 3 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 3, + targetViewId = R.id.classroom_name_text_view + ) + ).check(matches(not(isDisplayed()))) + } + } + + @Test + fun testRecentlyPlayedTestActivity_enableClassrooms_recommendedSection_classroomNameIsCorrect() { + TestPlatformParameterModule.forceEnableMultipleClassrooms(true) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 3 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 3, + targetViewId = R.id.classroom_name_text_view + ) + ).check( + matches(withText(containsString("MATHS"))) + ) + } + } + @Config(qualifiers = "port") @Test fun testRecentlyPlayedTestActivity_recentlyPlayedItemInRtl_rtlMarginIsCorrect() { @@ -774,6 +834,74 @@ class RecentlyPlayedFragmentTest { } } + @Test + fun testRecentlyPlayedTestActivity_disableClassrooms_classroomNameIsNotDisplayed() { + TestPlatformParameterModule.forceEnableMultipleClassrooms(false) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + storyProgressTestHelper.markInProgressSavedRatiosStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = true + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 1 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 1, + targetViewId = R.id.classroom_name_text_view + ) + ).check(matches(not(isDisplayed()))) + } + } + + @Test + fun testRecentlyPlayedTestActivity_enableClassrooms_classroomNameIsCorrect() { + TestPlatformParameterModule.forceEnableMultipleClassrooms(true) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + storyProgressTestHelper.markInProgressSavedRatiosStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = true + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 1 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 1, + targetViewId = R.id.classroom_name_text_view + ) + ).check( + matches(withText(containsString("MATHS"))) + ) + } + } + @Test fun testRecentlyPlayedTestActivity_lessonThumbnailIsCorrect() { fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) @@ -1256,6 +1384,76 @@ class RecentlyPlayedFragmentTest { } } + @Test + fun testRecentlyPlayedTestActivity_disableClassrooms_configChange_classroomNameIsNotDisplayed() { + TestPlatformParameterModule.forceEnableMultipleClassrooms(false) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + storyProgressTestHelper.markInProgressSavedRatiosStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = true + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 1 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 1, + targetViewId = R.id.classroom_name_text_view + ) + ).check(matches(not(isDisplayed()))) + } + } + + @Test + fun testRecentlyPlayedTestActivity_enableClassrooms_configChange_classroomNameIsCorrect() { + TestPlatformParameterModule.forceEnableMultipleClassrooms(true) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = false + ) + storyProgressTestHelper.markInProgressSavedRatiosStory0Exp0( + profileId = profileId, + timestampOlderThanOneWeek = true + ) + ActivityScenario.launch( + createRecentlyPlayedActivityIntent( + internalProfileId = internalProfileId + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 1 + ) + ) + onView( + atPositionOnView( + recyclerViewId = R.id.ongoing_story_recycler_view, + position = 1, + targetViewId = R.id.classroom_name_text_view + ) + ).check( + matches(withText(containsString("MATHS"))) + ) + } + } + @Test fun testRecentlyPlayedTestActivity_configChange_lessonThumbnailIsCorrect() { fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) @@ -1464,7 +1662,7 @@ class RecentlyPlayedFragmentTest { @Component( modules = [ RobolectricModule::class, - PlatformParameterModule::class, PlatformParameterSingletonModule::class, + TestPlatformParameterModule::class, PlatformParameterSingletonModule::class, TestDispatcherModule::class, ApplicationModule::class, LoggerModule::class, ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, MultipleChoiceInputModule::class,