Skip to content

Commit

Permalink
Merge with develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Rd4dev committed Aug 23, 2024
2 parents 98587f3 + 6ce90ad commit 1ac4b7c
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 171 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def filesToExclude = [
'**/*AppLanguageLocaleHandlerTest*.kt',
'**/*AppLanguageResourceHandlerTest*.kt',
'**/*AppLanguageWatcherMixinTest*.kt',
'**/*ActivityLanguageLocaleHandlerTest*.kt'
'**/*ActivityLanguageLocaleHandlerTest*.kt',
'**/*OptionsFragmentTest*.kt', // Excludes 2 tests.
]
_excludeSourceFiles(filesToExclude)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PromotedStoryViewModel(
private val promotedStoryClickListener: PromotedStoryClickListener,
private val position: Int,
private val resourceHandler: AppLanguageResourceHandler,
val showClassroomLabel: Boolean,
translationController: TranslationController
) : RecentlyPlayedItemViewModel() {
/** Sets the story title of the recently played story. */
Expand All @@ -38,6 +39,12 @@ class PromotedStoryViewModel(
promotedStory.nextChapterTitle, promotedStory.nextChapterWrittenTranslationContext
)
}
/** Sets the classroom of the recently played story. */
val classroomTitle by lazy {
translationController.extractString(
promotedStory.classroomTitle, promotedStory.classroomWrittenTranslationContext
)
}

/**
* Starts [ResumeLessonActivity] if a saved exploration is selected or [ExplorationActivity] if an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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.parser.html.StoryHtmlParserEntityType
import org.oppia.android.util.platformparameter.EnableMultipleClassrooms
import org.oppia.android.util.platformparameter.PlatformParameterValue
import javax.inject.Inject

/** View model for [RecentlyPlayedFragment]. */
Expand All @@ -22,6 +24,7 @@ class RecentlyPlayedViewModel private constructor(
@StoryHtmlParserEntityType private val entityType: String,
private val resourceHandler: AppLanguageResourceHandler,
private val translationController: TranslationController,
private val enableMultipleClassrooms: PlatformParameterValue<Boolean>,
private val promotedStoryClickListener: PromotedStoryClickListener,
private val profileId: ProfileId,
) {
Expand All @@ -33,6 +36,8 @@ class RecentlyPlayedViewModel private constructor(
@StoryHtmlParserEntityType private val entityType: String,
private val resourceHandler: AppLanguageResourceHandler,
private val translationController: TranslationController,
@EnableMultipleClassrooms
private val enableMultipleClassrooms: PlatformParameterValue<Boolean>,
) {

/** Creates an instance of [RecentlyPlayedViewModel]. */
Expand All @@ -46,6 +51,7 @@ class RecentlyPlayedViewModel private constructor(
entityType,
resourceHandler,
translationController,
enableMultipleClassrooms,
promotedStoryClickListener,
profileId,
)
Expand Down Expand Up @@ -166,6 +172,7 @@ class RecentlyPlayedViewModel private constructor(
promotedStoryClickListener,
index,
resourceHandler,
enableMultipleClassrooms.value,
translationController
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.AudioLanguage
import org.oppia.android.app.model.OppiaLanguage
import org.oppia.android.app.model.Profile
import org.oppia.android.app.model.ProfileId
Expand All @@ -20,7 +20,8 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import javax.inject.Inject

/** [ViewModel] for [OptionsFragment]. */
private const val OPTIONS_ITEM_VIEW_MODEL_APP_AUDIO_LANGUAGE_PROVIDER_ID =
"OPTIONS_ITEM_VIEW_MODEL_APP_AUDIO_LANGUAGE_PROVIDER_ID"
private const val OPTIONS_ITEM_VIEW_MODEL_LIST_PROVIDER_ID =
"OPTIONS_ITEM_VIEW_MODEL_LIST_PROVIDER_ID"

Expand Down Expand Up @@ -67,11 +68,14 @@ class OptionControlsViewModel @Inject constructor(
}

private fun createOptionsItemViewModelProvider(): DataProvider<List<OptionsItemViewModel>> {
val appAudioLangProvider =
translationController.getAppLanguage(profileId).combineWith(
profileManagementController.getAudioLanguage(profileId),
OPTIONS_ITEM_VIEW_MODEL_APP_AUDIO_LANGUAGE_PROVIDER_ID
) { appLanguage, audioLanguage -> appLanguage to audioLanguage }
return profileManagementController.getProfile(profileId).combineWith(
translationController.getAppLanguage(profileId),
OPTIONS_ITEM_VIEW_MODEL_LIST_PROVIDER_ID,
::processViewModelList
)
appAudioLangProvider, OPTIONS_ITEM_VIEW_MODEL_LIST_PROVIDER_ID
) { profile, (appLang, audioLang) -> processViewModelList(profile, appLang, audioLang) }
}

private fun processViewModelListsResult(
Expand All @@ -93,12 +97,13 @@ class OptionControlsViewModel @Inject constructor(

private fun processViewModelList(
profile: Profile,
oppiaLanguage: OppiaLanguage
appLanguage: OppiaLanguage,
audioLanguage: AudioLanguage
): List<OptionsItemViewModel> {
return listOfNotNull(
createReadingTextSizeViewModel(profile),
createAppLanguageViewModel(oppiaLanguage),
createAudioLanguageViewModel(profile)
createAppLanguageViewModel(appLanguage),
createAudioLanguageViewModel(audioLanguage)
)
}

Expand All @@ -117,12 +122,14 @@ class OptionControlsViewModel @Inject constructor(
)
}

private fun createAudioLanguageViewModel(profile: Profile): OptionsAudioLanguageViewModel {
private fun createAudioLanguageViewModel(
audioLanguage: AudioLanguage
): OptionsAudioLanguageViewModel {
return OptionsAudioLanguageViewModel(
routeToAudioLanguageListListener,
loadAudioLanguageListListener,
profile.audioLanguage,
resourceHandler.computeLocalizedDisplayName(profile.audioLanguage)
audioLanguage,
resourceHandler.computeLocalizedDisplayName(audioLanguage)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.AudioLanguage
import org.oppia.android.app.model.CellularDataPreference
import org.oppia.android.app.model.Profile
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.Spotlight
import org.oppia.android.app.model.State
Expand Down Expand Up @@ -147,15 +146,15 @@ class AudioFragmentPresenter @Inject constructor(
) as? SpotlightManager
}

private fun getProfileData(): LiveData<String> {
private fun retrieveAudioLanguageCode(): LiveData<String> {
return Transformations.map(
profileManagementController.getProfile(profileId).toLiveData(),
::processGetProfileResult
profileManagementController.getAudioLanguage(profileId).toLiveData(),
::processAudioLanguageResult
)
}

private fun subscribeToAudioLanguageLiveData() {
getProfileData().observe(
retrieveAudioLanguageCode().observe(
activity,
Observer<String> { result ->
audioViewModel.selectedLanguageCode = result
Expand All @@ -165,11 +164,9 @@ class AudioFragmentPresenter @Inject constructor(
}

/** Gets language code by [AudioLanguage]. */
private fun getAudioLanguage(audioLanguage: AudioLanguage): String {
private fun computeLanguageCode(audioLanguage: AudioLanguage): String {
return when (audioLanguage) {
AudioLanguage.HINDI_AUDIO_LANGUAGE -> "hi"
AudioLanguage.FRENCH_AUDIO_LANGUAGE -> "fr"
AudioLanguage.CHINESE_AUDIO_LANGUAGE -> "zh"
AudioLanguage.BRAZILIAN_PORTUGUESE_LANGUAGE -> "pt"
AudioLanguage.ARABIC_LANGUAGE -> "ar"
AudioLanguage.NIGERIAN_PIDGIN_LANGUAGE -> "pcm"
Expand All @@ -178,16 +175,16 @@ class AudioFragmentPresenter @Inject constructor(
}
}

private fun processGetProfileResult(profileResult: AsyncResult<Profile>): String {
val profile = when (profileResult) {
private fun processAudioLanguageResult(languageResult: AsyncResult<AudioLanguage>): String {
val audioLanguage = when (languageResult) {
is AsyncResult.Failure -> {
oppiaLogger.e("AudioFragment", "Failed to retrieve profile", profileResult.error)
Profile.getDefaultInstance()
oppiaLogger.e("AudioFragment", "Failed to retrieve audio language", languageResult.error)
AudioLanguage.AUDIO_LANGUAGE_UNSPECIFIED
}
is AsyncResult.Pending -> Profile.getDefaultInstance()
is AsyncResult.Success -> profileResult.value
is AsyncResult.Pending -> AudioLanguage.AUDIO_LANGUAGE_UNSPECIFIED
is AsyncResult.Success -> languageResult.value
}
return getAudioLanguage(profile.audioLanguage)
return computeLanguageCode(audioLanguage)
}

/** Sets selected language code in presenter and ViewModel. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class LanguageDialogFragment : InjectableDialogFragment() {
for (languageCode in languageCodeArrayList) {
val audioLanguage = when (machineLocale.run { languageCode.toMachineLowerCase() }) {
"hi" -> AudioLanguage.HINDI_AUDIO_LANGUAGE
"fr" -> AudioLanguage.FRENCH_AUDIO_LANGUAGE
"zh" -> AudioLanguage.CHINESE_AUDIO_LANGUAGE
"pt", "pt-br" -> AudioLanguage.BRAZILIAN_PORTUGUESE_LANGUAGE
"ar" -> AudioLanguage.ARABIC_LANGUAGE
"pcm" -> AudioLanguage.NIGERIAN_PIDGIN_LANGUAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class AppLanguageResourceHandler @Inject constructor(
fun computeLocalizedDisplayName(audioLanguage: AudioLanguage): String {
return when (audioLanguage) {
AudioLanguage.HINDI_AUDIO_LANGUAGE -> getLocalizedDisplayName("hi")
AudioLanguage.FRENCH_AUDIO_LANGUAGE -> getLocalizedDisplayName("fr")
AudioLanguage.CHINESE_AUDIO_LANGUAGE -> getLocalizedDisplayName("zh")
AudioLanguage.BRAZILIAN_PORTUGUESE_LANGUAGE -> getLocalizedDisplayName("pt", "BR")
AudioLanguage.ARABIC_LANGUAGE -> getLocalizedDisplayName("ar", "EG")
AudioLanguage.NIGERIAN_PIDGIN_LANGUAGE ->
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/classroom_label_text_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="50dp" />
<stroke
android:width="2dp"
android:color="@color/component_color_classroom_promoted_list_classroom_label_color" />
<padding
android:left="16dp"
android:right="16dp"
android:top="8dp"
android:bottom="8dp" />
</shape>
21 changes: 20 additions & 1 deletion app/src/main/res/layout/recently_played_story_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,29 @@
android:text="@{viewModel.topicTitle}"
android:textAllCaps="true"
android:textColor="@color/component_color_shared_story_card_topic_name_text_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/classroom_name_text_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/story_name_text_view" />

<TextView
android:id="@+id/classroom_name_text_view"
style="@style/CaptionViewStart"
android:layout_width="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:text="@{viewModel.classroomTitle}"
android:textAllCaps="true"
android:textColor="@color/component_color_classroom_promoted_list_classroom_label_color"
android:background="@drawable/classroom_label_text_background"
android:visibility="@{viewModel.showClassroomLabel ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topic_name_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
Expand Down
Loading

0 comments on commit 1ac4b7c

Please sign in to comment.