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 #5381 Talkback reads 14 underscore in a question in What is a ratio chapter #5553

Merged
merged 39 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d819e70
Merge pull request #1 from oppia/develop
subhajitxyz Jul 23, 2024
c6f54ea
Merge branch 'oppia:develop' into develop
subhajitxyz Jul 27, 2024
d44015b
Merge remote-tracking branch 'upstream/develop' into develop
subhajitxyz Aug 17, 2024
d604bc2
Merge pull request #2 from oppia/develop
subhajitxyz Aug 26, 2024
cc0ddef
Merge pull request #3 from oppia/develop
subhajitxyz Aug 26, 2024
52c6bb1
Merge pull request #4 from oppia/develop
subhajitxyz Aug 29, 2024
773c810
Merge remote-tracking branch 'upstream/develop' into develop
subhajitxyz Sep 5, 2024
56af5ae
Merge pull request #5 from oppia/develop
subhajitxyz Sep 16, 2024
3883f70
Merge pull request #6 from oppia/develop
subhajitxyz Sep 27, 2024
10c8e6e
Fix #5404: Migrate away from onBackPressed for remaining activities (…
dattasneha Oct 3, 2024
5e140e9
Fix #5404: Migrate away from onBackPressed for RevisionCardActivity (…
dattasneha Oct 9, 2024
b4ad7a3
Merge branch 'oppia:develop' into develop
subhajitxyz Oct 11, 2024
238645d
Merge pull request #8 from oppia/develop
subhajitxyz Oct 12, 2024
8d0328c
Add replaceRegexWithBlank function
subhajitxyz Oct 12, 2024
16230b7
Merge remote-tracking branch 'upstream/develop' into fix-talkback-read
subhajitxyz Oct 12, 2024
5a546b9
Merge pull request #9 from oppia/develop
subhajitxyz Nov 3, 2024
95d5d65
add test
subhajitxyz Nov 10, 2024
8c78531
correct klint
subhajitxyz Nov 10, 2024
94929f2
correct formatting
subhajitxyz Nov 10, 2024
6d0bea3
add spaces between functions
subhajitxyz Nov 10, 2024
2732fff
Merge branch 'develop' into fix-talkback-read
subhajitxyz Nov 10, 2024
944474b
add audio datasource
subhajitxyz Nov 10, 2024
7ee17ee
Merge branch 'fix-talkback-read' of https://github.com/subhajitxyz/op…
subhajitxyz Nov 10, 2024
31c5db1
change audio filename
subhajitxyz Nov 11, 2024
8706dff
added shodowmediaplayer resetStaticState
subhajitxyz Nov 11, 2024
e48f898
correct formatting
subhajitxyz Nov 11, 2024
a393924
Merge branch 'develop' into fix-talkback-read
subhajitxyz Nov 19, 2024
b1ca8e1
Merge pull request #10 from oppia/develop
subhajitxyz Nov 19, 2024
f730578
Merge branch 'develop' into fix-talkback-read
adhiamboperes Dec 2, 2024
ad7e380
Merge pull request #11 from oppia/develop
subhajitxyz Dec 11, 2024
b938a4c
Fix #5508: Skipping redundant code coverage and APK/AAB report commen…
Rd4dev Dec 12, 2024
fc2f932
Fix part of #4865: Use profileId in classroom activity and presenter …
tobioyelekan Dec 16, 2024
35f937b
Merge branch 'oppia:develop' into develop
subhajitxyz Dec 17, 2024
81d54c8
Merge branch 'develop' into fix-talkback-read
subhajitxyz Dec 17, 2024
33f0a8f
add practice 5 data source
subhajitxyz Dec 17, 2024
4605b28
Merge branch 'fix-talkback-read' of https://github.com/subhajitxyz/op…
subhajitxyz Dec 17, 2024
47a67b3
correct audio file name
subhajitxyz Dec 18, 2024
7e59fd6
Merge branch 'develop' into fix-talkback-read
subhajitxyz Dec 18, 2024
a00ae61
Merge branch 'develop' into fix-talkback-read
adhiamboperes Dec 23, 2024
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
@@ -1,10 +1,38 @@
package org.oppia.android.app.player.state.itemviewmodel

import android.text.Spannable
import android.text.SpannableStringBuilder

/** [StateItemViewModel] for content-card state. */
class ContentViewModel(
val htmlContent: CharSequence,
val gcsEntityId: String,
val hasConversationView: Boolean,
val isSplitView: Boolean,
val supportsConceptCards: Boolean
) : StateItemViewModel(ViewType.CONTENT)
) : StateItemViewModel(ViewType.CONTENT) {

private val underscoreRegex = Regex("(?<=\\s|[,.;?!])_{3,}(?=\\s|[,.;?!])")
private val replacementText = "Blank"

/**
* Replaces "2+ underscores, with space/punctuation on both sides" in the input text with a
* replacement string "blank", returning a Spannable.
* Adjusts offsets to handle text length changes during replacements.
*/
fun replaceRegexWithBlank(inputText: CharSequence): Spannable {
val spannableStringBuilder = SpannableStringBuilder(inputText)
val matches = underscoreRegex.findAll(inputText)
var lengthOffset = 0

for (match in matches) {
val matchStart = match.range.first + lengthOffset
val matchEnd = match.range.last + 1 + lengthOffset
spannableStringBuilder.replace(matchStart, matchEnd, replacementText)

// Adjust offset due to change in length (difference between old and new text length)
lengthOffset += replacementText.length - (matchEnd - matchStart)
}
return spannableStringBuilder
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/content_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
android:minWidth="48dp"
android:minHeight="48dp"
android:text="@{htmlContent}"
android:contentDescription="@{viewModel.replaceRegexWithBlank(htmlContent)}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textColorLink="@color/component_color_shared_link_text_color"
android:textSize="16sp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModu
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.topic.FRACTIONS_EXPLORATION_ID_1
import org.oppia.android.domain.topic.RATIOS_EXPLORATION_ID_0
import org.oppia.android.domain.topic.TEST_EXPLORATION_ID_13
import org.oppia.android.domain.topic.TEST_EXPLORATION_ID_2
import org.oppia.android.domain.topic.TEST_EXPLORATION_ID_4
Expand Down Expand Up @@ -5206,6 +5207,110 @@ class StateFragmentTest {
}
}

@Test
fun testStateFragment_contentDescription_replaceUnderscoresWithBlank() {
setUpTestWithLanguageSwitchingFeatureOff()
launchForExploration(RATIOS_EXPLORATION_ID_0, shouldSavePartialProgress = false).use {
startPlayingExploration()

playThroughRatioExplorationState1()
playThroughRatioExplorationState2()
playThroughRatioExplorationState3()
playThroughRatioExplorationState4()
playThroughRatioExplorationState5()
playThroughRatioExplorationState6()
playThroughRatioExplorationState7()
playThroughRatioExplorationState8()
playThroughRatioExplorationState9()
playThroughRatioExplorationState10()
playThroughRatioExplorationState11()
playThroughRatioExplorationState12()
playThroughRatioExplorationState13()
playThroughRatioExplorationState14()

val expectedDescription = "James turned the page, and saw a recipe for banana smoothie." +
" Yummy!\n\n2 cups of milk and 1 cup of banana puree \n\n“I can make this,” he said." +
" “We’ll need to mix milk and banana puree in the ratio Blank.”\n\nCan you complete" +
" James’s sentence? What is the ratio of milk to banana puree?”"

onView(withId(R.id.content_text_view))
.check(matches(withContentDescription(expectedDescription)))
}
}

private fun playThroughRatioExplorationState1() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState2() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState3() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState4() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState5() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState6() {
typeTextInput("2 to 5")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState7() {
typeTextInput("3 to 1")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState8() {
typeTextInput("2:3")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState9() {
typeTextInput("5:2")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState10() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState11() {
selectMultipleChoiceOption(
2,
"The relative relationship between the amounts of different things."
)
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState12() {
clickContinueInteractionButton()
}

private fun playThroughRatioExplorationState13() {
typeTextInput("1:4")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun playThroughRatioExplorationState14() {
typeTextInput("1:4")
clickSubmitAnswerButton()
clickContinueNavigationButton()
}

private fun addShadowMediaPlayerException(dataSource: Any, exception: Exception) {
val classLoader = StateFragmentTest::class.java.classLoader!!
val shadowMediaPlayerClass = classLoader.loadClass("org.robolectric.shadows.ShadowMediaPlayer")
Expand Down Expand Up @@ -5793,7 +5898,13 @@ class StateFragmentTest {
explorationId = FRACTIONS_EXPLORATION_ID_1, audioFileName = "content-en-ouqm7j21vt8.mp3"
)
) { "Failed to create audio data source." }
val dataSource2 = checkNotNull(
createAudioDataSource(
explorationId = RATIOS_EXPLORATION_ID_0, audioFileName = "content-en-057j51i2es.mp3"
)
) { "Failed to create audio data source." }
addShadowMediaPlayerException(dataSource, IOException("Test does not have networking"))
addShadowMediaPlayerException(dataSource2, IOException("Test does not have networking"))
}
}

Expand Down
Loading