Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #5344: Add classroom label to stories on view all screen #5502

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,37 @@ class RecentlyPlayedFragmentTest {
}
}

@Test
fun testRecentlyPlayedTestActivity_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 +805,41 @@ class RecentlyPlayedFragmentTest {
}
}

@Test
fun testRecentlyPlayedTestActivity_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 +1322,42 @@ class RecentlyPlayedFragmentTest {
}
}

@Test
fun testRecentlyPlayedTestActivity_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 +1566,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
Loading