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 #3892: Locked chapter item selection change is incorrect #4573

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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