Skip to content

Commit

Permalink
Fix part of oppia#5344: Add classroom label to stories on view all sc…
Browse files Browse the repository at this point in the history
…reen (oppia#5502)

<!-- 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 oppia#5344

This PR adds classroom label to the promoted stories on view all screen.

## Screenshots
|Light Mode|Dark Mode|
|--|--|

|![image](https://github.com/user-attachments/assets/c97cbdf7-4e2a-43bf-a3f4-d57c0c53811f)|![image](https://github.com/user-attachments/assets/caff0087-cf33-4de3-ad74-44fa375f4f7c)|

## 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 and adhiamboperes committed Aug 24, 2024
1 parent 02eadc1 commit 496ca4c
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]. */
Expand All @@ -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<Boolean>,
private val promotedStoryClickListener: PromotedStoryClickListener,
private val profileId: ProfileId,
) {
Expand All @@ -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<Boolean>,
) {

/** Creates an instance of [RecentlyPlayedViewModel]. */
Expand All @@ -46,6 +51,7 @@ class RecentlyPlayedViewModel private constructor(
entityType,
resourceHandler,
translationController,
enableMultipleClassrooms,
promotedStoryClickListener,
profileId,
)
Expand Down Expand Up @@ -166,6 +172,7 @@ class RecentlyPlayedViewModel private constructor(
promotedStoryClickListener,
index,
resourceHandler,
enableMultipleClassrooms.value,
translationController
)
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/classroom_label_text_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="50dp" />
<stroke
android:width="2dp"
android:color="@color/component_color_classroom_promoted_list_classroom_label_color" />
<padding
android:left="16dp"
android:right="16dp"
android:top="8dp"
android:bottom="8dp" />
</shape>
21 changes: 20 additions & 1 deletion app/src/main/res/layout/recently_played_story_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<TextView
android:id="@+id/classroom_name_text_view"
style="@style/CaptionViewStart"
android:layout_width="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:text="@{viewModel.classroomTitle}"
android:textAllCaps="true"
android:textColor="@color/component_color_classroom_promoted_list_classroom_label_color"
android:background="@drawable/classroom_label_text_background"
android:visibility="@{viewModel.showClassroomLabel ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topic_name_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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() {
Expand Down Expand Up @@ -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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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)
Expand Down Expand Up @@ -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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.ongoing_story_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 496ca4c

Please sign in to comment.