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 #5133 Audio language name showing two times #5178

Closed
Closed
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 @@ -15,7 +15,6 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
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
Expand Down Expand Up @@ -168,20 +167,6 @@ class AudioFragmentPresenter @Inject constructor(
)
}

/** Gets language code by [AudioLanguage]. */
private fun getAudioLanguage(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"
AudioLanguage.NO_AUDIO, AudioLanguage.UNRECOGNIZED, AudioLanguage.AUDIO_LANGUAGE_UNSPECIFIED,
AudioLanguage.ENGLISH_AUDIO_LANGUAGE -> "en"
}
}

private fun processGetProfileResult(profileResult: AsyncResult<Profile>): String {
val profile = when (profileResult) {
is AsyncResult.Failure -> {
Expand All @@ -191,7 +176,7 @@ class AudioFragmentPresenter @Inject constructor(
is AsyncResult.Pending -> Profile.getDefaultInstance()
is AsyncResult.Success -> profileResult.value
}
return getAudioLanguage(profile.audioLanguage)
return viewModel.getAudioLanguage(profile.audioLanguage)
}

/** Sets selected language code in presenter and ViewModel. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
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.State
import org.oppia.android.app.model.Voiceover
import org.oppia.android.app.model.VoiceoverMapping
Expand Down Expand Up @@ -91,12 +92,18 @@ class AudioViewModel @Inject constructor(
val targetContentId = contentId ?: state.content.contentId
val voiceoverMapping =
state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()

autoPlay = allowAutoPlay
this.reloadingMainContent = reloadingMainContent
voiceoverMap = voiceoverMapping.voiceoverMappingMap
currentContentId = targetContentId
languages = voiceoverMap.keys.toList().map { machineLocale.run { it.toMachineLowerCase() } }
languages = voiceoverMap.keys.toList().filter {
it in getSupportedLanguageCodes()
}.map {
machineLocale.run {
it.toMachineLowerCase()
}
}

selectedLanguageUnavailable.set(false)

val localeLanguageCode =
Expand All @@ -123,6 +130,32 @@ class AudioViewModel @Inject constructor(
}
}

/** Gets language code by [AudioLanguage]. */
fun getAudioLanguage(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"
AudioLanguage.NO_AUDIO,
AudioLanguage.UNRECOGNIZED,
AudioLanguage.AUDIO_LANGUAGE_UNSPECIFIED,
AudioLanguage.ENGLISH_AUDIO_LANGUAGE -> "en"
}
}

fun getSupportedLanguageCodes(): List<String> {
val supportedAudioLanguageCodes = AudioLanguage.values()
.map { audioLanguage ->
getAudioLanguage(audioLanguage)
}
.toMutableList()
supportedAudioLanguageCodes.add("hi-en")
return supportedAudioLanguageCodes
}

/** Sets language code for data binding and changes data source to correct audio. */
fun setAudioLanguageCode(languageCode: String) {
selectedLanguageCode = languageCode
Expand Down
Loading