Skip to content

Commit

Permalink
Fixes #3892: Locked chapter item selection change is incorrect (#4573)
Browse files Browse the repository at this point in the history
* Fixed UX for users with visual imparity

* klint issue fixed
  • Loading branch information
vrajdesai78 authored Sep 12, 2022
1 parent 3f93526 commit ad52087
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.oppia.android.databinding.StoryFragmentBinding
import org.oppia.android.databinding.StoryHeaderViewBinding
import org.oppia.android.domain.exploration.ExplorationDataController
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.util.accessibility.AccessibilityService
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.gcsresource.DefaultResourceBucketName
Expand Down Expand Up @@ -63,6 +64,9 @@ class StoryFragmentPresenter @Inject constructor(
@Inject
lateinit var storyViewModel: StoryViewModel

@Inject
lateinit var accessibilityService: AccessibilityService

fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -181,28 +185,30 @@ class StoryFragmentPresenter @Inject constructor(
storyItemViewModel.missingPrerequisiteChapterTitle
)
val chapterLockedSpannable = SpannableString(missingPrerequisiteSummary)
val clickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
smoothScrollToPosition(storyItemViewModel.index - 1)
}
if (!accessibilityService.isScreenReaderEnabled()) {
val clickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
smoothScrollToPosition(storyItemViewModel.index - 1)
}

override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
}
}
chapterLockedSpannable.setSpan(
clickableSpan,
/* start= */ LOCKED_CARD_PREFIX_LENGTH,
/* end= */ chapterLockedSpannable.length - LOCKED_CARD_SUFFIX_LENGTH,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
chapterLockedSpannable.setSpan(
TypefaceSpan("sans-serif-medium"),
/* start= */ LOCKED_CARD_PREFIX_LENGTH,
/* end= */ chapterLockedSpannable.length - LOCKED_CARD_SUFFIX_LENGTH,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
chapterLockedSpannable.setSpan(
clickableSpan,
/* start= */ LOCKED_CARD_PREFIX_LENGTH,
/* end= */ chapterLockedSpannable.length - LOCKED_CARD_SUFFIX_LENGTH,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
chapterLockedSpannable.setSpan(
TypefaceSpan("sans-serif-medium"),
/* start= */ LOCKED_CARD_PREFIX_LENGTH,
/* end= */ chapterLockedSpannable.length - LOCKED_CARD_SUFFIX_LENGTH,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
binding.htmlContent = chapterLockedSpannable
binding.chapterSummary.movementMethod = LinkMovementMethod.getInstance()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import org.oppia.android.testing.threading.TestDispatcherModule
import org.oppia.android.testing.time.FakeOppiaClock
import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.accessibility.FakeAccessibilityService
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.gcsresource.GcsResourceModule
Expand Down Expand Up @@ -175,6 +176,9 @@ class StoryFragmentTest {
@Inject
lateinit var fakeOppiaClock: FakeOppiaClock

@Inject
lateinit var accessibilityService: FakeAccessibilityService

@Captor
lateinit var listCaptor: ArgumentCaptor<List<ImageTransformation>>

Expand Down Expand Up @@ -557,6 +561,52 @@ class StoryFragmentTest {
}
}

@Test
fun testStoryFragment_checkClickableSpanWithoutScreenReader_isClickable() {
launch<StoryActivity>(createFractionsStoryActivityIntent()).use {
accessibilityService.setScreenReaderEnabled(false)
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(
2
)
)
onView(
atPositionOnView(
recyclerViewId = R.id.story_chapter_list,
position = 2,
targetViewId = R.id.chapter_summary
)
).check(
matches(hasClickableSpanWithText("Chapter 1: What is a Fraction?"))
)
}
}

@Test
fun testStoryFragment_checkClickableSpanWithScreenReader_isNotClickable() {
launch<StoryActivity>(createFractionsStoryActivityIntent()).use {
accessibilityService.setScreenReaderEnabled(true)
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(
2
)
)
onView(
atPositionOnView(
recyclerViewId = R.id.story_chapter_list,
position = 2,
targetViewId = R.id.chapter_summary
)
).check(
matches(not(hasClickableSpanWithText("Chapter 1: What is a Fraction?")))
)
}
}

@Test
fun testStoryFragment_clickPrerequisiteChapter_prerequisiteChapterCardIsDisplayed() {
launch<StoryActivity>(createFractionsStoryActivityIntent()).use {
Expand Down

0 comments on commit ad52087

Please sign in to comment.