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 #2628: Reading Text Size[A11y] #2929

Merged
merged 32 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
efacdc5
Fixes #2628: Reading Text Size[A11y]
Arjupta Mar 16, 2021
3efcd0a
EOF fix
Arjupta Mar 16, 2021
aa8214f
Lint Checks
Arjupta Mar 16, 2021
aa3256b
Corrected the Talkback Output
Arjupta Mar 20, 2021
3c80f1a
Included TextSizeItemViewModel in BUILD.bazel
Arjupta Apr 16, 2021
fbd5856
Included ReadingTextSizeSelectionViewModel in BUILD.bazel
Arjupta Apr 16, 2021
0d60305
Included TextSizeRadioButtonListener in BUILD.bazel
Arjupta Apr 16, 2021
0f56bcb
Changes for RedingTextSizeSelectionViewModel which has resource imports
Arjupta Apr 16, 2021
0998b22
Fixing the tests for New TextSizeSelection UI
Arjupta Apr 18, 2021
c59cc86
Fixing Lint Issues
Arjupta Apr 18, 2021
41d207a
Fixed the TextSize ViewMatcher
Arjupta Apr 18, 2021
7590b06
Added KDocs and refactored function names
Arjupta Apr 19, 2021
6191f10
Apply suggestions from code review
Arjupta Apr 19, 2021
2269150
Corrections due to applied suggestions from Code Review
Arjupta Apr 19, 2021
533627b
Reverting one suggestion of not using lazy initialization
Arjupta Apr 20, 2021
fc9ab60
Nit changes
Arjupta Apr 21, 2021
994968d
Fixes Bug of not updating reading text size correctly
Arjupta Apr 24, 2021
29cdfea
Changed the location of ReadingTextSizeFragmentTest
Arjupta May 2, 2021
0272c9d
add the file
Arjupta May 3, 2021
f556a91
Merge branch 'develop' into reading-text-size
Arjupta May 3, 2021
c93ccb3
Suggested changes
Arjupta May 4, 2021
1153a13
Updating with develop
Arjupta May 10, 2021
2ab5b12
Sugggested changes by @rt4914
Arjupta May 11, 2021
a5bf18c
Failing check due to unwanted import
Arjupta May 12, 2021
f29c4e6
added kdoc for ReadingTextSizeFragment
Arjupta May 12, 2021
b8b8c2d
Added padding dimension for landscape layout and removed val from inj…
Arjupta May 12, 2021
63b844c
Suggested update
Arjupta May 20, 2021
bb9dee6
Merge remote-tracking branch 'origin' into reading-text-size
Arjupta May 21, 2021
5915f76
Merge branch 'reading-text-size' of https://github.com/ARJUPTA/oppia-…
Arjupta May 21, 2021
9aca655
Adding qualifier as suggested
Arjupta May 22, 2021
ae9e456
Adding suggested comments
Arjupta Jun 2, 2021
9a691d4
Corrected the comment format
Arjupta Jun 5, 2021
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
3 changes: 3 additions & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ LISTENERS = [
"src/main/java/org/oppia/android/app/options/RouteToAppLanguageListListener.kt",
"src/main/java/org/oppia/android/app/options/RouteToAudioLanguageListListener.kt",
"src/main/java/org/oppia/android/app/options/RouteToReadingTextSizeListener.kt",
"src/main/java/org/oppia/android/app/options/TextSizeRadioButtonListener.kt",
"src/main/java/org/oppia/android/app/player/audio/LanguageInterface.kt",
"src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerErrorOrAvailabilityCheckReceiver.kt",
"src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerHandler.kt",
Expand Down Expand Up @@ -137,6 +138,7 @@ VIEW_MODELS_WITH_RESOURCE_IMPORTS = [
"src/main/java/org/oppia/android/app/home/topiclist/TopicSummaryViewModel.kt",
"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/options/TextSizeItemViewModel.kt",
"src/main/java/org/oppia/android/app/parser/StringToFractionParser.kt",
"src/main/java/org/oppia/android/app/parser/StringToNumberParser.kt",
"src/main/java/org/oppia/android/app/parser/StringToRatioParser.kt",
Expand Down Expand Up @@ -195,6 +197,7 @@ VIEW_MODELS = [
"src/main/java/org/oppia/android/app/options/OptionsAudioLanguageViewModel.kt",
"src/main/java/org/oppia/android/app/options/OptionsItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/OptionsReadingTextSizeViewModel.kt",
"src/main/java/org/oppia/android/app/options/ReadingTextSizeSelectionViewModel.kt",
"src/main/java/org/oppia/android/app/player/audio/AudioViewModel.kt",
"src/main/java/org/oppia/android/app/player/exploration/ExplorationViewModel.kt",
"src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContentViewModel.kt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import javax.inject.Inject

private const val KEY_READING_TEXT_SIZE_PREFERENCE_SUMMARY_VALUE =
"READING_TEXT_SIZE_PREFERENCE_SUMMARY_VALUE"
private const val SELECTED_READING_TEXT_SIZE_SAVED_KEY =
"ReadingTextSizeFragment.selected_text_size"

/** The fragment to change the text size of the reading content in the app. */
class ReadingTextSizeFragment : InjectableFragment() {
class ReadingTextSizeFragment : InjectableFragment(), TextSizeRadioButtonListener {
@Inject
lateinit var readingTextSizeFragmentPresenter: ReadingTextSizeFragmentPresenter

Expand All @@ -38,7 +40,23 @@ class ReadingTextSizeFragment : InjectableFragment() {
): View? {
val args =
checkNotNull(arguments) { "Expected arguments to be passed to ReadingTextSizeFragment" }
val readingTextSize = args.get(KEY_READING_TEXT_SIZE_PREFERENCE_SUMMARY_VALUE) as String
val readingTextSize = if (savedInstanceState == null) {
args.get(KEY_READING_TEXT_SIZE_PREFERENCE_SUMMARY_VALUE) as String
} else {
savedInstanceState.get(SELECTED_READING_TEXT_SIZE_SAVED_KEY) as String
}
return readingTextSizeFragmentPresenter.handleOnCreateView(inflater, container, readingTextSize)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(
SELECTED_READING_TEXT_SIZE_SAVED_KEY,
readingTextSizeFragmentPresenter.getTextSizeSelected()
)
}

override fun onTextSizeSelected(selectedTextSize: String) {
readingTextSizeFragmentPresenter.onTextSizeSelected(selectedTextSize)
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package org.oppia.android.app.options

import android.content.Intent
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import androidx.fragment.app.Fragment
import org.oppia.android.R
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.recyclerview.BindableAdapter
import org.oppia.android.databinding.ReadingTextSizeFragmentBinding
import org.oppia.android.databinding.TextSizeItemsBinding
import javax.inject.Inject

private const val SMALL_TEXT_SIZE_SCALE = 0.8f
private const val MEDIUM_TEXT_SIZE_SCALE = 1.0f
private const val LARGE_TEXT_SIZE_SCALE = 1.2f
private const val EXTRA_LARGE_TEXT_SIZE_SCALE = 1.4f

/** The presenter for [ReadingTextSizeFragment]. */
class ReadingTextSizeFragmentPresenter @Inject constructor(private val fragment: Fragment) {
private var fontSize: String = getReadingTextSize(ReadingTextSize.MEDIUM_TEXT_SIZE)
class ReadingTextSizeFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val readingTextSizeSelectionViewModel: ReadingTextSizeSelectionViewModel
) {
private var fontSize: String = fragment.requireContext().resources.getString(
R.string.reading_text_size_medium
)

fun handleOnCreateView(
inflater: LayoutInflater,
Expand All @@ -35,99 +34,38 @@ class ReadingTextSizeFragmentPresenter @Inject constructor(private val fragment:
fontSize = readingTextSize
updateTextSize(fontSize)

binding.viewModel = readingTextSizeSelectionViewModel
readingTextSizeSelectionViewModel.selectedTextSize.value = fontSize

binding.readingTextSizeToolbar?.setNavigationOnClickListener {
val message = readingTextSizeSelectionViewModel.selectedTextSize.value
val intent = Intent()
intent.putExtra(MESSAGE_READING_TEXT_SIZE_ARGUMENT_KEY, fontSize)
intent.putExtra(MESSAGE_READING_TEXT_SIZE_ARGUMENT_KEY, message)
(fragment.activity as ReadingTextSizeActivity).setResult(REQUEST_CODE_TEXT_SIZE, intent)
(fragment.activity as ReadingTextSizeActivity).finish()
}

when (readingTextSize) {
getReadingTextSize(ReadingTextSize.SMALL_TEXT_SIZE) -> {
binding.readingTextSizeSeekBar.progress = 0
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.SMALL_TEXT_SIZE)
)
}
getReadingTextSize(ReadingTextSize.MEDIUM_TEXT_SIZE) -> {
binding.readingTextSizeSeekBar.progress = 5
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.MEDIUM_TEXT_SIZE)
)
}
getReadingTextSize(ReadingTextSize.LARGE_TEXT_SIZE) -> {
binding.readingTextSizeSeekBar.progress = 10
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.LARGE_TEXT_SIZE)
)
}
getReadingTextSize(ReadingTextSize.EXTRA_LARGE_TEXT_SIZE) -> {
binding.readingTextSizeSeekBar.progress = 15
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.EXTRA_LARGE_TEXT_SIZE)
)
}
binding.textSizeRecyclerView.apply {
adapter = createRecyclerViewAdapter()
}
return binding.root
}

binding.readingTextSizeSeekBar.max = 15

binding.readingTextSizeSeekBar.setOnSeekBarChangeListener(
object :
SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
var progressValue = progress
progressValue /= 5
progressValue *= 5

when (progressValue) {
0 -> {
fontSize = getReadingTextSize(ReadingTextSize.SMALL_TEXT_SIZE)
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.SMALL_TEXT_SIZE)
)
}
5 -> {
fontSize = getReadingTextSize(ReadingTextSize.MEDIUM_TEXT_SIZE)
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.MEDIUM_TEXT_SIZE)
)
}
10 -> {
fontSize = getReadingTextSize(ReadingTextSize.LARGE_TEXT_SIZE)
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.LARGE_TEXT_SIZE)
)
}
else -> {
fontSize = getReadingTextSize(ReadingTextSize.EXTRA_LARGE_TEXT_SIZE)
binding.previewTextview.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
getReadingTextSizeInFloat(ReadingTextSize.EXTRA_LARGE_TEXT_SIZE)
)
}
}
seekBar.progress = progressValue
updateTextSize(fontSize)
}

override fun onStartTrackingTouch(seekBar: SeekBar) {
}

override fun onStopTrackingTouch(seekBar: SeekBar) {
}
})
fun getTextSizeSelected(): String? {
return readingTextSizeSelectionViewModel.selectedTextSize.value
}

return binding.root
private fun createRecyclerViewAdapter(): BindableAdapter<TextSizeItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<TextSizeItemViewModel>()
.setLifecycleOwner(fragment)
.registerViewDataBinderWithSameModelType(
inflateDataBinding = TextSizeItemsBinding::inflate,
setViewModel = TextSizeItemsBinding::setViewModel
).build()
}

fun updateTextSize(textSize: String) {
private fun updateTextSize(textSize: String) {
// The first branch of (when) will be used in the case of multipane
when (val parentActivity = fragment.activity) {
is OptionsActivity -> parentActivity.optionActivityPresenter.updateReadingTextSize(textSize)
Expand All @@ -136,24 +74,8 @@ class ReadingTextSizeFragmentPresenter @Inject constructor(private val fragment:
}
}

fun getReadingTextSizeInFloat(readingTextSize: ReadingTextSize): Float {
val defaultReadingTextSizeInFloat = fragment.requireContext().resources.getDimension(
R.dimen.default_reading_text_size
)
return when (readingTextSize) {
ReadingTextSize.SMALL_TEXT_SIZE -> defaultReadingTextSizeInFloat * SMALL_TEXT_SIZE_SCALE
ReadingTextSize.MEDIUM_TEXT_SIZE -> defaultReadingTextSizeInFloat * MEDIUM_TEXT_SIZE_SCALE
ReadingTextSize.LARGE_TEXT_SIZE -> defaultReadingTextSizeInFloat * LARGE_TEXT_SIZE_SCALE
else -> defaultReadingTextSizeInFloat * EXTRA_LARGE_TEXT_SIZE_SCALE
}
}

fun getReadingTextSize(readingTextSize: ReadingTextSize): String {
return when (readingTextSize) {
ReadingTextSize.SMALL_TEXT_SIZE -> "Small"
ReadingTextSize.MEDIUM_TEXT_SIZE -> "Medium"
ReadingTextSize.LARGE_TEXT_SIZE -> "Large"
else -> "Extra Large"
}
fun onTextSizeSelected(selectedTextSize: String) {
readingTextSizeSelectionViewModel.selectedTextSize.value = selectedTextSize
updateTextSize(selectedTextSize)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.oppia.android.app.options

import androidx.fragment.app.Fragment
import androidx.lifecycle.MutableLiveData
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.viewmodel.ObservableViewModel
import javax.inject.Inject

/** Text Size list view model for the recycler view in [ReadingTextSizeFragment]. */
@FragmentScope
class ReadingTextSizeSelectionViewModel @Inject constructor(
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
fragment: Fragment
) : ObservableViewModel() {

private val resourceBundle = fragment.requireContext().resources
val selectedTextSize = MutableLiveData<String>()
private val textSizeRadioButtonListener = fragment as TextSizeRadioButtonListener

private val textSizeList = listOf<TextSizeItemViewModel>(
TextSizeItemViewModel(
resourceBundle,
ReadingTextSize.SMALL_TEXT_SIZE,
selectedTextSize,
textSizeRadioButtonListener
),
TextSizeItemViewModel(
resourceBundle,
ReadingTextSize.MEDIUM_TEXT_SIZE,
selectedTextSize,
textSizeRadioButtonListener
),
TextSizeItemViewModel(
resourceBundle,
ReadingTextSize.LARGE_TEXT_SIZE,
selectedTextSize,
textSizeRadioButtonListener
),
TextSizeItemViewModel(
resourceBundle,
ReadingTextSize.EXTRA_LARGE_TEXT_SIZE,
selectedTextSize,
textSizeRadioButtonListener
),
)

val recyclerViewTextSizeList: List<TextSizeItemViewModel> by lazy {
textSizeList
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.oppia.android.app.options

import android.content.res.Resources
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.viewmodel.ObservableViewModel

private const val SMALL_TEXT_SIZE_SCALE = 0.8f
private const val MEDIUM_TEXT_SIZE_SCALE = 1.0f
private const val LARGE_TEXT_SIZE_SCALE = 1.2f
private const val EXTRA_LARGE_TEXT_SIZE_SCALE = 1.4f

/** Text Size item view model for the recycler view in [ReadingTextSizeFragment]. */
class TextSizeItemViewModel constructor(
val resources: Resources,
val readingTextSize: ReadingTextSize,
private val selectedTextSize: LiveData<String>,
val textSizeRadioButtonListener: TextSizeRadioButtonListener
) : ObservableViewModel() {
private val defaultReadingTextSizeInFloat by lazy {
resources.getDimension(R.dimen.default_reading_text_size)
}
val textSizeName: String by lazy {
when (readingTextSize) {
ReadingTextSize.SMALL_TEXT_SIZE -> resources.getString(R.string.reading_text_size_small)
ReadingTextSize.MEDIUM_TEXT_SIZE -> resources.getString(R.string.reading_text_size_medium)
ReadingTextSize.LARGE_TEXT_SIZE -> resources.getString(R.string.reading_text_size_large)
else -> resources.getString(R.string.reading_text_size_extra_large)
}
}
val textSize: Float by lazy {
when (readingTextSize) {
ReadingTextSize.SMALL_TEXT_SIZE -> defaultReadingTextSizeInFloat * SMALL_TEXT_SIZE_SCALE
ReadingTextSize.MEDIUM_TEXT_SIZE -> defaultReadingTextSizeInFloat * MEDIUM_TEXT_SIZE_SCALE
ReadingTextSize.LARGE_TEXT_SIZE -> defaultReadingTextSizeInFloat * LARGE_TEXT_SIZE_SCALE
else -> defaultReadingTextSizeInFloat * EXTRA_LARGE_TEXT_SIZE_SCALE
}
}
val isTextSizeSelected: LiveData<Boolean> by lazy {
Transformations.map(selectedTextSize) { it == textSizeName }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.oppia.android.app.options

/** Listener for when the reading text size is selected from the [ReadingTextSizeFragment]. */
interface TextSizeRadioButtonListener {
fun onTextSizeSelected(selectedTextSize: String)
}
Loading