Skip to content

Commit

Permalink
Merge branch 'text-view-script' of github.com:manas-yu/oppia-android …
Browse files Browse the repository at this point in the history
…into text-view-script
  • Loading branch information
manas-yu committed Jan 22, 2025
2 parents c9af6ad + a82826d commit e32a8d3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ VIEW_MODELS_WITH_RESOURCE_IMPORTS = [
"src/main/java/org/oppia/android/app/onboarding/OnboadingSlideViewModel.kt",
"src/main/java/org/oppia/android/app/onboarding/OnboardingViewModel.kt",
"src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/AudioLanguageItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/OptionsReadingTextSizeViewModel.kt",
"src/main/java/org/oppia/android/app/options/TextSizeItemViewModel.kt",
"src/main/java/org/oppia/android/app/parser/FractionParsingUiError.kt",
Expand Down Expand Up @@ -310,7 +311,6 @@ VIEW_MODELS = [
"src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt",
"src/main/java/org/oppia/android/app/options/AppLanguageItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/AppLanguageSelectionViewModel.kt",
"src/main/java/org/oppia/android/app/options/AudioLanguageItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/AudioLanguageSelectionViewModel.kt",
"src/main/java/org/oppia/android/app/options/OptionControlsViewModel.kt",
"src/main/java/org/oppia/android/app/options/OptionsAppLanguageViewModel.kt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package org.oppia.android.app.options

import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.model.AudioLanguage
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.viewmodel.ObservableViewModel

/**
Expand All @@ -20,7 +22,8 @@ class AudioLanguageItemViewModel(
val language: AudioLanguage,
val languageDisplayName: String,
private val currentSelectedLanguage: LiveData<AudioLanguage>,
val audioLanguageRadioButtonListener: AudioLanguageRadioButtonListener
val audioLanguageRadioButtonListener: AudioLanguageRadioButtonListener,
private val appLanguageResourceHandler: AppLanguageResourceHandler
) : ObservableViewModel() {
/**
* Indicates whether the language corresponding to this view model is _currently_ selected in the
Expand All @@ -29,4 +32,16 @@ class AudioLanguageItemViewModel(
val isLanguageSelected: LiveData<Boolean> by lazy {
Transformations.map(currentSelectedLanguage) { it == language }
}
/**
* Returns the content description for the current language. This is used for accessibility
* purposes to provide a readable description of the language in the UI.
*/
fun languageContentDescription(): String {
return when (language) {
AudioLanguage.ARABIC_LANGUAGE -> appLanguageResourceHandler.getStringInLocaleWithWrapping(
R.string.arabic_language_display_name_content_description
)
else -> languageDisplayName
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class AudioLanguageSelectionViewModel @Inject constructor(
language,
appLanguageResourceHandler.computeLocalizedDisplayName(language),
selectedLanguage,
fragment as AudioLanguageRadioButtonListener
fragment as AudioLanguageRadioButtonListener,
appLanguageResourceHandler
)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/audio_language_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:fontFamily="sans-serif"
android:contentDescription="@{viewModel.languageContentDescription()}"
android:text="@{viewModel.languageDisplayName}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textSize="16sp" />
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,8 @@
<string name="audio_language_fragment_text">In %s, you can listen to lessons!</string>
<string name="audio_language_fragment_subtitle">Select the audio language to listen to lessons</string>
<string name="onboarding_step_count_five">STEP 5 OF 5</string>

<!-- AudioLanguageFragment -->
<string name="arabic_language_display_name_content_description">Arabic</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.test.espresso.matcher.RootMatchers.withDecorView
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand Down Expand Up @@ -499,6 +500,32 @@ class AudioLanguageFragmentTest {
}
}

@Test
fun testFragment_withEnglish_verifyContentDescriptionReadsArabicLanguage() {
initializeTestApplicationComponent(enableOnboardingFlowV2 = false)
launchActivityWithLanguage(ENGLISH_AUDIO_LANGUAGE).use {
verifyEnglishIsSelected()

onView(
atPositionOnView(
R.id.audio_language_recycler_view,
3,
R.id.language_text_view
)
).check(matches(withText(R.string.arabic_localized_language_name)))

onView(
atPositionOnView(
R.id.audio_language_recycler_view,
3,
R.id.language_text_view
)
).check(
matches(withContentDescription(R.string.arabic_language_display_name_content_description))
)
}
}

private fun launchActivityWithLanguage(
audioLanguage: AudioLanguage
): ActivityScenario<AppLanguageActivity> {
Expand Down

0 comments on commit e32a8d3

Please sign in to comment.