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

Fixes #4737: No meaningful label of the revision screen navigation cards during talkback. #5113

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package org.oppia.android.app.topic.revisioncard
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.model.EphemeralRevisionCard
import org.oppia.android.app.model.EphemeralSubtopic
import org.oppia.android.app.model.EphemeralTopic
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.topic.RouteToRevisionCardListener
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.viewmodel.ObservableViewModel
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.topic.TopicController
Expand Down Expand Up @@ -36,6 +38,7 @@ class RevisionCardViewModel private constructor(
val topicId: String,
val subtopicId: Int,
val profileId: ProfileId,
private val appLanguageResourceHandler: AppLanguageResourceHandler,
val subtopicListSize: Int
) : ObservableViewModel() {

Expand Down Expand Up @@ -100,6 +103,21 @@ class RevisionCardViewModel private constructor(
} ?: ""
}

/** Returns the content description of the subtopic. */
fun computeContentDescriptionText(subtopicLiveData: LiveData<EphemeralSubtopic>): String {
return when (subtopicLiveData) {
previousSubtopicLiveData -> appLanguageResourceHandler.getStringInLocaleWithWrapping(
R.string.previous_subtopic_talkback_text,
computeTitleText(previousSubtopicLiveData.value)
)
nextSubtopicLiveData -> appLanguageResourceHandler.getStringInLocaleWithWrapping(
R.string.next_subtopic_talkback_text,
computeTitleText(nextSubtopicLiveData.value)
)
else -> ""
}
}

private fun processPreviousSubtopicData(
topicLiveData: AsyncResult<EphemeralTopic>
): EphemeralSubtopic {
Expand Down Expand Up @@ -157,6 +175,7 @@ class RevisionCardViewModel private constructor(
private val topicController: TopicController,
private val oppiaLogger: OppiaLogger,
@TopicHtmlParserEntityType private val entityType: String,
private val appLanguageResourceHandler: AppLanguageResourceHandler,
private val translationController: TranslationController
) {
/** Returns a new [RevisionCardViewModel]. */
Expand All @@ -175,6 +194,7 @@ class RevisionCardViewModel private constructor(
topicId,
subtopicId,
profileId,
appLanguageResourceHandler,
subtopicListSize
)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout-sw600dp/revision_card_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:text="@{viewModel.computeTitleText(viewModel.previousSubtopicLiveData)}"
android:contentDescription="@{viewModel.computeContentDescriptionText(viewModel.previousSubtopicLiveData)}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp"
android:textStyle="bold"
Expand Down Expand Up @@ -166,6 +167,7 @@
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:text="@{viewModel.computeTitleText(viewModel.nextSubtopicLiveData)}"
android:contentDescription="@{viewModel.computeContentDescriptionText(viewModel.nextSubtopicLiveData)}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp"
android:textStyle="bold"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/revision_card_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:text="@{viewModel.computeTitleText(viewModel.previousSubtopicLiveData)}"
android:contentDescription="@{viewModel.computeContentDescriptionText(viewModel.previousSubtopicLiveData)}"
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp"
android:textStyle="bold"
Expand Down Expand Up @@ -164,6 +165,7 @@
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:text="@{viewModel.computeTitleText(viewModel.nextSubtopicLiveData)}"
android:contentDescription="@{viewModel.computeContentDescriptionText(viewModel.nextSubtopicLiveData)}"
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp"
android:textStyle="bold"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,6 @@
<string name="nps_passive_feedback_question">Thanks for responding! How can we provide a better experience?</string>
<string name="nps_detractor_feedback_question">Help us improve your experience! Please share the primary reason for your score:</string>
<string name="nps_score_question">On a scale from 0–10, how likely are you to recommend %s to a friend or colleague?</string>
<string name="previous_subtopic_talkback_text">The previous subtopic is %s</string>
<string name="next_subtopic_talkback_text">The next subtopic is %s</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -183,6 +184,94 @@ class RevisionCardFragmentTest {
Intents.release()
}

@Test
fun testRevisionCard_previousSubtopicTitle_hasCorrectContentDescription() {
launch<RevisionCardActivity>(
createRevisionCardActivityIntent(
context,
profileId.internalId,
"test_topic_id_0",
subtopicId = 1,
FRACTIONS_SUBTOPIC_LIST_SIZE
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.prev_subtopic_title)).check(
matches(
ViewMatchers.withContentDescription(
"The previous subtopic is "
)
)
)
}
}

@Test
fun testRevisionCard_nextSubtopicTitle_hasCorrectContentDescription() {
launch<RevisionCardActivity>(
createRevisionCardActivityIntent(
context,
profileId.internalId,
"test_topic_id_0",
subtopicId = 1,
FRACTIONS_SUBTOPIC_LIST_SIZE
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.next_subtopic_title)).check(
matches(
ViewMatchers.withContentDescription(
"The next subtopic is "
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
}
}

@Test
fun testRevisionCard_previousSubtopicTitle_whatIsAFraction_hasCorrectContentDescription() {
launch<RevisionCardActivity>(
createRevisionCardActivityIntent(
context,
profileId.internalId,
FRACTIONS_TOPIC_ID,
subtopicId = 2,
FRACTIONS_SUBTOPIC_LIST_SIZE
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.prev_subtopic_title)).check(
matches(
ViewMatchers.withContentDescription(
"The previous subtopic is What is a Fraction?"
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
}
}

@Test
fun testRevisionCard_nextSubtopicTitle_mixedNumbers_hasCorrectContentDescription() {
launch<RevisionCardActivity>(
createRevisionCardActivityIntent(
context,
profileId.internalId,
FRACTIONS_TOPIC_ID,
subtopicId = 2,
FRACTIONS_SUBTOPIC_LIST_SIZE
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.next_subtopic_title)).check(
matches(
ViewMatchers.withContentDescription(
"The next subtopic is Mixed Numbers"
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
}
}

@Test
fun testRevisionCardTest_initialise_openBottomSheet_showsBottomSheet() {
launch<ExplorationActivity>(
Expand Down
Loading