Skip to content

Commit

Permalink
Fix #4362, #1491: When reading text size is extra large, resume lesso…
Browse files Browse the repository at this point in the history
…n page and revision tabs content is seen in normal size (#5290)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fixes #4362 
Fixes #1491

Support resizable reading text in resume lesson, question player and
revision card.



| Before| After|
|--------|--------|

|[before.webm](https://github.com/oppia/oppia-android/assets/76042077/aa58a643-727f-421d-8b3a-a4799718113e)|[device-2024-01-02-150914.webm](https://github.com/oppia/oppia-android/assets/76042077/aa46b657-87cf-4c4f-b512-0c1b67dd351d)|

|[tablet_before.webm](https://github.com/oppia/oppia-android/assets/76042077/b9fd6b96-2f28-4a4f-8db5-1106219054f1)|[tablet_after.webm](https://github.com/oppia/oppia-android/assets/76042077/c9a105db-9062-47c4-982b-dd7f35a1f14c)|

Question Player


[questionPLayer.webm](https://github.com/oppia/oppia-android/assets/76042077/6b321c57-35ed-44e6-8220-3b9d52c089cc)

<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only

<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide))
- For PRs introducing new UI elements or color changes, both light and
dark mode screenshots must be included
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing
  • Loading branch information
Vishwajith-Shettigar authored Aug 1, 2024
1 parent f892744 commit 1b72693
Show file tree
Hide file tree
Showing 17 changed files with 631 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import org.oppia.android.app.home.RouteToExplorationListener
import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ExplorationCheckpoint
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.model.ResumeLessonActivityParams
import org.oppia.android.app.model.ScreenName.RESUME_LESSON_ACTIVITY
import org.oppia.android.app.player.exploration.DefaultFontSizeStateListener
import org.oppia.android.app.player.exploration.ExplorationActivity
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.extensions.putProtoExtra
Expand All @@ -20,6 +22,7 @@ import javax.inject.Inject
/** Activity that allows the user to resume a saved exploration. */
class ResumeLessonActivity :
InjectableAutoLocalizedAppCompatActivity(),
DefaultFontSizeStateListener,
RouteToExplorationListener {
@Inject
lateinit var resumeLessonActivityPresenter: ResumeLessonActivityPresenter
Expand Down Expand Up @@ -91,6 +94,7 @@ class ResumeLessonActivity :
parentScreen: ExplorationActivityParams.ParentScreen,
isCheckpointingEnabled: Boolean
) {
resumeLessonActivityPresenter.setReadingTextSizeNormal()
startActivity(
ExplorationActivity.createExplorationActivityIntent(
this,
Expand All @@ -105,4 +109,13 @@ class ResumeLessonActivity :
)
finish()
}

override fun onDefaultFontSizeLoaded(readingTextSize: ReadingTextSize) {
resumeLessonActivityPresenter.loadResumeLessonFragment(readingTextSize)
}

override fun onBackPressed() {
resumeLessonActivityPresenter.setReadingTextSizeNormal()
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@ package org.oppia.android.app.resumelesson

import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ExplorationCheckpoint
import org.oppia.android.app.model.Profile
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.player.exploration.DefaultFontSizeStateListener
import org.oppia.android.app.utility.FontScaleConfigurationUtil
import org.oppia.android.databinding.ResumeLessonActivityBinding
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import javax.inject.Inject

private const val RESUME_LESSON_TAG = "ResumeLesson"

/** The presenter for [ResumeLessonActivity]. */
class ResumeLessonActivityPresenter @Inject constructor(
private val activity: AppCompatActivity
private val activity: AppCompatActivity,
private val profileManagementController: ProfileManagementController,
private val fontScaleConfigurationUtil: FontScaleConfigurationUtil,
private val oppiaLogger: OppiaLogger
) {
private lateinit var profileId: ProfileId
private lateinit var classroomId: String
private lateinit var topicId: String
private lateinit var storyId: String
private lateinit var explorationId: String
private lateinit var parentScreen: ExplorationActivityParams.ParentScreen
private lateinit var explorationCheckpoint: ExplorationCheckpoint

/** Handles onCreate() method of the [ResumeLessonActivity]. */
fun handleOnCreate(
Expand All @@ -30,30 +51,84 @@ class ResumeLessonActivityPresenter @Inject constructor(
activity,
R.layout.resume_lesson_activity
)
this.profileId = profileId
this.classroomId = classroomId
this.topicId = topicId
this.storyId = storyId
this.explorationId = explorationId
this.explorationCheckpoint = explorationCheckpoint
this.parentScreen = parentScreen
val resumeLessonToolbar = binding.resumeLessonActivityToolbar
activity.setSupportActionBar(resumeLessonToolbar)

retrieveReadingTextSize().observe(
activity as ResumeLessonActivity,
{ result ->
(activity as DefaultFontSizeStateListener).onDefaultFontSizeLoaded(result)
}
)

resumeLessonToolbar.setNavigationOnClickListener {
fontScaleConfigurationUtil.adjustFontScale(
context = activity,
ReadingTextSize.MEDIUM_TEXT_SIZE
)
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
}
}

if (getResumeLessonFragment() == null) {
val resumeLessonFragment = ResumeLessonFragment.newInstance(
profileId,
classroomId,
topicId,
storyId,
explorationId,
parentScreen,
explorationCheckpoint
)
activity.supportFragmentManager.beginTransaction().add(
R.id.resume_lesson_fragment_placeholder,
resumeLessonFragment,
RESUME_LESSON_TAG
).commitNow()
}
/** Loads [ResumeLessonFragment]. */
fun loadResumeLessonFragment(readingTextSize: ReadingTextSize) {
if (getResumeLessonFragment() != null)
activity.supportFragmentManager.beginTransaction()
.remove(getResumeLessonFragment() as Fragment).commitNow()

val resumeLessonFragment = ResumeLessonFragment.newInstance(
profileId,
classroomId,
topicId,
storyId,
explorationId,
parentScreen,
explorationCheckpoint,
readingTextSize
)
activity.supportFragmentManager.beginTransaction().add(
R.id.resume_lesson_fragment_placeholder,
resumeLessonFragment,
RESUME_LESSON_TAG
).commitNow()
}

private fun retrieveReadingTextSize(): LiveData<ReadingTextSize> {
return Transformations.map(
profileManagementController.getProfile(profileId).toLiveData(),
::processReadingTextSizeResult
)
}

private fun processReadingTextSizeResult(
profileResult: AsyncResult<Profile>
): ReadingTextSize {
return when (profileResult) {
is AsyncResult.Failure -> {
oppiaLogger.e(
"ResumeLessonActivity",
"Failed to retrieve profile",
profileResult.error
)
Profile.getDefaultInstance()
}
is AsyncResult.Pending -> {
oppiaLogger.d(
"ResumeLessonActivity",
"Result is pending"
)
Profile.getDefaultInstance()
}
is AsyncResult.Success -> profileResult.value
}.readingTextSize
}

private fun getResumeLessonFragment(): ResumeLessonFragment? {
Expand All @@ -63,4 +138,12 @@ class ResumeLessonActivityPresenter @Inject constructor(
R.id.resume_lesson_fragment_placeholder
) as ResumeLessonFragment?
}

/** Set reading text size normal. */
fun setReadingTextSizeNormal() {
fontScaleConfigurationUtil.adjustFontScale(
context = activity,
ReadingTextSize.MEDIUM_TEXT_SIZE
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.oppia.android.app.fragment.InjectableFragment
import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ExplorationCheckpoint
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.model.ResumeLessonFragmentArguments
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
Expand All @@ -18,7 +19,9 @@ import javax.inject.Inject
/** Fragment that allows the user to resume a saved exploration. */
class ResumeLessonFragment : InjectableFragment() {
companion object {
private const val ARGUMENTS_KEY = "ResumeExplorationFragment.arguments"

/** Arguments key for [ResumeLessonFragment]. */
const val RESUME_LESSON_FRAGMENT_ARGUMENTS_KEY = "ResumeLessonFragment.arguments"

/** Creates new instance of [ResumeLessonFragment] for the provided parameters. */
fun newInstance(
Expand All @@ -28,7 +31,8 @@ class ResumeLessonFragment : InjectableFragment() {
storyId: String,
explorationId: String,
parentScreen: ExplorationActivityParams.ParentScreen,
checkpoint: ExplorationCheckpoint
checkpoint: ExplorationCheckpoint,
readingTextSize: ReadingTextSize
): ResumeLessonFragment {
val args = ResumeLessonFragmentArguments.newBuilder().apply {
this.profileId = profileId
Expand All @@ -38,10 +42,11 @@ class ResumeLessonFragment : InjectableFragment() {
this.explorationId = explorationId
this.parentScreen = parentScreen
this.checkpoint = checkpoint
this.readingTextSize = readingTextSize
}.build()
return ResumeLessonFragment().apply {
arguments = Bundle().apply {
putProto(ARGUMENTS_KEY, args)
putProto(RESUME_LESSON_FRAGMENT_ARGUMENTS_KEY, args)
}
}
}
Expand All @@ -53,6 +58,7 @@ class ResumeLessonFragment : InjectableFragment() {
override fun onAttach(context: Context) {
super.onAttach(context)
(fragmentComponent as FragmentComponentImpl).inject(this)
resumeLessonFragmentPresenter.handleAttach(context)
}

override fun onCreateView(
Expand All @@ -62,7 +68,10 @@ class ResumeLessonFragment : InjectableFragment() {
): View? {
val args = checkNotNull(arguments) {
"Expected arguments to be provided for fragment."
}.getProto(ARGUMENTS_KEY, ResumeLessonFragmentArguments.getDefaultInstance())
}.getProto(
RESUME_LESSON_FRAGMENT_ARGUMENTS_KEY,
ResumeLessonFragmentArguments.getDefaultInstance()
)
return resumeLessonFragmentPresenter.handleOnCreate(
inflater,
container,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.app.resumelesson

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -12,14 +13,17 @@ import org.oppia.android.app.model.EphemeralChapterSummary
import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ExplorationCheckpoint
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ResumeLessonFragmentArguments
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.utility.FontScaleConfigurationUtil
import org.oppia.android.databinding.ResumeLessonFragmentBinding
import org.oppia.android.domain.exploration.ExplorationDataController
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.topic.TopicController
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.gcsresource.DefaultResourceBucketName
import org.oppia.android.util.parser.html.HtmlParser
import javax.inject.Inject
Expand All @@ -31,6 +35,7 @@ class ResumeLessonFragmentPresenter @Inject constructor(
private val resumeLessonViewModel: ResumeLessonViewModel,
private val topicController: TopicController,
private val explorationDataController: ExplorationDataController,
private val fontScaleConfigurationUtil: FontScaleConfigurationUtil,
private val htmlParserFactory: HtmlParser.Factory,
private val translationController: TranslationController,
@DefaultResourceBucketName private val resourceBucketName: String,
Expand All @@ -55,6 +60,11 @@ class ResumeLessonFragmentPresenter @Inject constructor(
getChapterSummary()
}

/** Handles the [Fragment.onAttach] portion of [ResumeLessonFragment]'s lifecycle. */
fun handleAttach(context: Context) {
fontScaleConfigurationUtil.adjustFontScale(context, retrieveArguments().readingTextSize)
}

/** Handles onCreateView() method of the [ResumeLessonFragment]. */
fun handleOnCreate(
inflater: LayoutInflater,
Expand All @@ -72,7 +82,6 @@ class ResumeLessonFragmentPresenter @Inject constructor(
container,
/* attachToRoot= */ false
)

this.profileId = profileId
this.topicId = topicId
this.classroomId = classroomId
Expand Down Expand Up @@ -110,10 +119,16 @@ class ResumeLessonFragmentPresenter @Inject constructor(
parentScreen
)
}

return binding.root
}

private fun retrieveArguments(): ResumeLessonFragmentArguments {
return fragment.requireArguments().getProto(
ResumeLessonFragment.RESUME_LESSON_FRAGMENT_ARGUMENTS_KEY,
ResumeLessonFragmentArguments.getDefaultInstance()
)
}

private fun subscribeToChapterSummary() {
chapterSummaryLiveData.observe(
fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import org.oppia.android.app.hintsandsolution.RevealSolutionInterface
import org.oppia.android.app.model.HelpIndex
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.QuestionPlayerActivityParams
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.model.ScreenName.QUESTION_PLAYER_ACTIVITY
import org.oppia.android.app.model.State
import org.oppia.android.app.model.WrittenTranslationContext
import org.oppia.android.app.player.exploration.DefaultFontSizeStateListener
import org.oppia.android.app.player.state.listener.RouteToHintsAndSolutionListener
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.player.stopplaying.RestartPlayingSessionListener
Expand Down Expand Up @@ -41,6 +43,7 @@ class QuestionPlayerActivity :
RevealHintListener,
RevealSolutionInterface,
HintsAndSolutionQuestionManagerListener,
DefaultFontSizeStateListener,
ConceptCardListener {

@Inject
Expand All @@ -57,6 +60,7 @@ class QuestionPlayerActivity :

override fun onBackPressed() {
showStopExplorationDialogFragment()
questionPlayerActivityPresenter.setReadingTextSizeNormal()
}

override fun restartSession() = questionPlayerActivityPresenter.restartSession()
Expand Down Expand Up @@ -130,4 +134,8 @@ class QuestionPlayerActivity :
override fun stopSession() {
questionPlayerActivityPresenter.stopTrainingSession()
}

override fun onDefaultFontSizeLoaded(readingTextSize: ReadingTextSize) {
questionPlayerActivityPresenter.loadFragments(readingTextSize)
}
}
Loading

0 comments on commit 1b72693

Please sign in to comment.