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

Fix #4285 and #4394, part of #4437: Improve in-lesson reading text size support #4411

Merged
merged 8 commits into from
Sep 8, 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
3 changes: 2 additions & 1 deletion app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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/OptionsReadingTextSizeViewModel.kt",
"src/main/java/org/oppia/android/app/options/TextSizeItemViewModel.kt",
"src/main/java/org/oppia/android/app/parser/FractionParsingUiError.kt",
"src/main/java/org/oppia/android/app/parser/StringToNumberParser.kt",
Expand Down Expand Up @@ -298,7 +299,6 @@ VIEW_MODELS = [
"src/main/java/org/oppia/android/app/options/OptionsAppLanguageViewModel.kt",
"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/exploration/ExplorationViewModel.kt",
"src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContentViewModel.kt",
Expand Down Expand Up @@ -679,6 +679,7 @@ kt_android_library(
"//domain/src/main/java/org/oppia/android/domain/clipboard:clipboard_controller",
"//domain/src/main/java/org/oppia/android/domain/onboarding:state_controller",
"//domain/src/main/java/org/oppia/android/domain/profile:profile_management_controller",
"//model/src/main/proto:arguments_java_proto_lite",
"//third_party:androidx_core_core",
"//third_party:androidx_databinding_databinding-common",
"//third_party:androidx_databinding_databinding-runtime",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.oppia.android.app.home

import org.oppia.android.app.model.ExplorationActivityParams
import org.oppia.android.app.model.ProfileId

/** Listener for when an activity should route to a exploration. */
interface RouteToExplorationListener {
fun routeToExploration(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
storyId: String,
explorationId: String,
backflowScreen: Int?,
parentScreen: ExplorationActivityParams.ParentScreen,
isCheckpointingEnabled: Boolean
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.ActivityIntentFactories
import org.oppia.android.app.activity.InjectableAppCompatActivity
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.player.exploration.ExplorationActivity
Expand Down Expand Up @@ -48,42 +49,42 @@ class RecentlyPlayedActivity :
}

override fun routeToExploration(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
storyId: String,
explorationId: String,
backflowScreen: Int?,
parentScreen: ExplorationActivityParams.ParentScreen,
isCheckpointingEnabled: Boolean
) {
startActivity(
ExplorationActivity.createExplorationActivityIntent(
this,
internalProfileId,
profileId,
topicId,
storyId,
explorationId,
backflowScreen,
parentScreen,
isCheckpointingEnabled
)
)
}

override fun routeToResumeLesson(
internalProfileId: Int,
profileId: ProfileId,
topicId: String,
storyId: String,
explorationId: String,
backflowScreen: Int?,
parentScreen: ExplorationActivityParams.ParentScreen,
explorationCheckpoint: ExplorationCheckpoint
) {
startActivity(
ResumeLessonActivity.createResumeLessonActivityIntent(
this,
internalProfileId,
profileId,
topicId,
storyId,
explorationId,
backflowScreen,
parentScreen,
explorationCheckpoint
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.home.RouteToExplorationListener
import org.oppia.android.app.model.ChapterPlayState
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.PromotedActivityList
Expand Down Expand Up @@ -237,6 +238,9 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
}

fun onOngoingStoryClicked(promotedStory: PromotedStory) {
val profileId = ProfileId.newBuilder().apply {
internalId = internalProfileId
}.build()
val canHavePartialProgressSaved =
when (promotedStory.chapterPlayState) {
ChapterPlayState.IN_PROGRESS_SAVED, ChapterPlayState.IN_PROGRESS_NOT_SAVED,
Expand All @@ -248,10 +252,7 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
if (promotedStory.chapterPlayState == ChapterPlayState.IN_PROGRESS_SAVED) {
val explorationCheckpointLiveData =
explorationCheckpointController.retrieveExplorationCheckpoint(
ProfileId.newBuilder().apply {
internalId = internalProfileId
}.build(),
promotedStory.explorationId
profileId, promotedStory.explorationId
).toLiveData()

explorationCheckpointLiveData.observe(
Expand All @@ -261,11 +262,11 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
if (it is AsyncResult.Success) {
explorationCheckpointLiveData.removeObserver(this)
routeToResumeLessonListener.routeToResumeLesson(
internalProfileId,
profileId,
promotedStory.topicId,
promotedStory.storyId,
promotedStory.explorationId,
backflowScreen = null,
parentScreen = ExplorationActivityParams.ParentScreen.PARENT_SCREEN_UNSPECIFIED,
explorationCheckpoint = it.value
)
} else if (it is AsyncResult.Failure) {
Expand Down Expand Up @@ -320,11 +321,11 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
is AsyncResult.Success -> {
oppiaLogger.d("RecentlyPlayedFragment", "Successfully loaded exploration")
routeToExplorationListener.routeToExploration(
internalProfileId,
ProfileId.newBuilder().apply { internalId = internalProfileId }.build(),
topicId,
storyId,
explorationId,
backflowScreen = null,
parentScreen = ExplorationActivityParams.ParentScreen.PARENT_SCREEN_UNSPECIFIED,
isCheckpointingEnabled = canHavePartialProgressSaved
)
activity.finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.oppia.android.app.options

import org.oppia.android.app.model.ReadingTextSize

/** Listener for when an activity should load a [ReadingTextSizeFragment]. */
interface LoadReadingTextSizeListener {
fun loadReadingTextSizeFragment(textSize: String)
/**
* Loads a tablet UI panel for changing the current UI reading text size (with the current text
* size being passed in via [textSize]).
*/
fun loadReadingTextSizeFragment(textSize: ReadingTextSize)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.oppia.android.app.model.AppLanguage
import org.oppia.android.app.model.AudioLanguage
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.translation.AppLanguageResourceHandler
import org.oppia.android.app.viewmodel.ObservableArrayList
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.profile.ProfileManagementController
Expand All @@ -28,7 +28,8 @@ class OptionControlsViewModel @Inject constructor(
activity: AppCompatActivity,
private val profileManagementController: ProfileManagementController,
private val oppiaLogger: OppiaLogger,
@EnableLanguageSelectionUi private val enableLanguageSelectionUi: PlatformParameterValue<Boolean>
@EnableLanguageSelectionUi private val enableLanguageSelectionUi: PlatformParameterValue<Boolean>,
private val resourceHandler: AppLanguageResourceHandler
) : OptionsItemViewModel() {
private val itemViewModelList: ObservableList<OptionsItemViewModel> = ObservableArrayList()
private lateinit var profileId: ProfileId
Expand Down Expand Up @@ -84,11 +85,12 @@ class OptionControlsViewModel @Inject constructor(
}

private fun processProfileList(profile: Profile): List<OptionsItemViewModel> {

itemViewModelList.clear()

val optionsReadingTextSizeViewModel =
OptionsReadingTextSizeViewModel(routeToReadingTextSizeListener, loadReadingTextSizeListener)
OptionsReadingTextSizeViewModel(
routeToReadingTextSizeListener, loadReadingTextSizeListener, resourceHandler
)
val optionsAppLanguageViewModel =
OptionsAppLanguageViewModel(routeToAppLanguageListListener, loadAppLanguageListListener)
val optionAudioViewViewModel =
Expand All @@ -97,7 +99,7 @@ class OptionControlsViewModel @Inject constructor(
loadAudioLanguageListListener
)

optionsReadingTextSizeViewModel.readingTextSize.set(getReadingTextSize(profile.readingTextSize))
optionsReadingTextSizeViewModel.readingTextSize.set(profile.readingTextSize)
optionsAppLanguageViewModel.appLanguage.set(getAppLanguage(profile.appLanguage))
optionAudioViewViewModel.audioLanguage.set(getAudioLanguage(profile.audioLanguage))

Expand Down Expand Up @@ -126,15 +128,6 @@ class OptionControlsViewModel @Inject constructor(
this.isFirstOpen = isFirstOpen
}

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 getAppLanguage(appLanguage: AppLanguage): String {
return when (appLanguage) {
AppLanguage.ENGLISH_APP_LANGUAGE -> "English"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.model.ReadingTextSizeActivityResultBundle
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.extensions.getStringFromBundle
import javax.inject.Inject

Expand Down Expand Up @@ -82,17 +85,23 @@ class OptionsActivity :

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
checkNotNull(data) {
"Expected data to be passed as an activity result for request: $requestCode."
}
when (requestCode) {
REQUEST_CODE_TEXT_SIZE -> {
val textSize = data!!.getStringExtra(MESSAGE_READING_TEXT_SIZE_ARGUMENT_KEY) as String
optionActivityPresenter.updateReadingTextSize(textSize)
val textSizeResults = data.getProtoExtra(
MESSAGE_READING_TEXT_SIZE_RESULTS_KEY,
ReadingTextSizeActivityResultBundle.getDefaultInstance()
)
optionActivityPresenter.updateReadingTextSize(textSizeResults.selectedReadingTextSize)
}
REQUEST_CODE_APP_LANGUAGE -> {
val appLanguage = data!!.getStringExtra(MESSAGE_APP_LANGUAGE_ARGUMENT_KEY) as String
val appLanguage = data.getStringExtra(MESSAGE_APP_LANGUAGE_ARGUMENT_KEY) as String
optionActivityPresenter.updateAppLanguage(appLanguage)
}
else -> {
val audioLanguage = data!!.getStringExtra(MESSAGE_AUDIO_LANGUAGE_ARGUMENT_KEY) as String
val audioLanguage = data.getStringExtra(MESSAGE_AUDIO_LANGUAGE_ARGUMENT_KEY) as String
optionActivityPresenter.updateAudioLanguage(audioLanguage)
}
}
Expand Down Expand Up @@ -120,18 +129,14 @@ class OptionsActivity :
)
}

override fun routeReadingTextSize(readingTextSize: String?) {
override fun routeReadingTextSize(readingTextSize: ReadingTextSize) {
startActivityForResult(
ReadingTextSizeActivity.createReadingTextSizeActivityIntent(
this,
READING_TEXT_SIZE,
readingTextSize
),
ReadingTextSizeActivity.createReadingTextSizeActivityIntent(this, readingTextSize),
REQUEST_CODE_TEXT_SIZE
)
}

override fun loadReadingTextSizeFragment(textSize: String) {
override fun loadReadingTextSizeFragment(textSize: ReadingTextSize) {
selectedFragment = READING_TEXT_SIZE_FRAGMENT
optionActivityPresenter.setExtraOptionTitle(
resourceHandler.getStringInLocale(R.string.reading_text_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.drawerlayout.widget.DrawerLayout
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.drawer.NavigationDrawerFragment
import org.oppia.android.app.model.ReadingTextSize
import javax.inject.Inject

/** The presenter for [OptionsActivity]. */
Expand Down Expand Up @@ -79,7 +80,7 @@ class OptionsActivityPresenter @Inject constructor(
) as OptionsFragment?
}

fun updateReadingTextSize(textSize: String) {
fun updateReadingTextSize(textSize: ReadingTextSize) {
getOptionFragment()?.updateReadingTextSize(textSize)
}

Expand All @@ -91,7 +92,7 @@ class OptionsActivityPresenter @Inject constructor(
getOptionFragment()?.updateAudioLanguage(audioLanguage)
}

fun loadReadingTextSizeFragment(textSize: String) {
fun loadReadingTextSizeFragment(textSize: ReadingTextSize) {
val readingTextSizeFragment = ReadingTextSizeFragment.newInstance(textSize)
activity.supportFragmentManager
.beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import android.view.View
import android.view.ViewGroup
import org.oppia.android.app.fragment.FragmentComponentImpl
import org.oppia.android.app.fragment.InjectableFragment
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.util.extensions.getStringFromBundle
import javax.inject.Inject

const val MESSAGE_READING_TEXT_SIZE_ARGUMENT_KEY = "OptionsFragment.message_reading_text_size"
const val MESSAGE_READING_TEXT_SIZE_RESULTS_KEY = "OptionsFragment.message_reading_text_size"
const val MESSAGE_APP_LANGUAGE_ARGUMENT_KEY = "OptionsFragment.message_app_language"
const val MESSAGE_AUDIO_LANGUAGE_ARGUMENT_KEY = "OptionsFragment.message_audio_language"
const val REQUEST_CODE_TEXT_SIZE = 1
Expand Down Expand Up @@ -66,7 +67,7 @@ class OptionsFragment : InjectableFragment() {
)
}

fun updateReadingTextSize(textSize: String) {
fun updateReadingTextSize(textSize: ReadingTextSize) {
optionsFragmentPresenter.runAfterUIInitialization {
optionsFragmentPresenter.updateReadingTextSize(textSize)
}
Expand Down
Loading