diff --git a/app/src/main/java/org/oppia/android/app/onboarding/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/onboarding/AudioLanguageFragmentPresenter.kt new file mode 100644 index 00000000000..3a238d4b010 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/onboarding/AudioLanguageFragmentPresenter.kt @@ -0,0 +1,73 @@ +package org.oppia.android.app.onboarding + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.inputmethod.EditorInfo +import android.widget.ArrayAdapter +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment +import com.google.android.material.appbar.AppBarLayout +import org.oppia.android.R +import org.oppia.android.app.options.AudioLanguageSelectionViewModel +import org.oppia.android.app.translation.AppLanguageResourceHandler +import org.oppia.android.databinding.AudioLanguageSelectionFragmentBinding +import javax.inject.Inject + +/** The presenter for [AudioLanguageFragment]. */ +class AudioLanguageFragmentPresenter @Inject constructor( + private val fragment: Fragment, + private val activity: AppCompatActivity, + private val appLanguageResourceHandler: AppLanguageResourceHandler, + private val audioLanguageSelectionViewModel: AudioLanguageSelectionViewModel +) { + private lateinit var binding: AudioLanguageSelectionFragmentBinding + + /** + * Returns a newly inflated view to render the fragment with an evaluated audio language as the + * initial selected language, based on current locale. + */ + fun handleCreateView( + inflater: LayoutInflater, + container: ViewGroup? + ): View { + + // Hide toolbar as it's not needed in this layout. The toolbar is created by a shared activity + // and is required in OptionsFragment. + activity.findViewById(R.id.reading_list_app_bar_layout).visibility = View.GONE + + binding = AudioLanguageSelectionFragmentBinding.inflate( + inflater, + container, + /* attachToRoot= */ false + ) + binding.lifecycleOwner = fragment + + binding.audioLanguageText.text = appLanguageResourceHandler.getStringInLocaleWithWrapping( + R.string.audio_language_fragment_text, + appLanguageResourceHandler.getStringInLocale(R.string.app_name) + ) + + binding.onboardingNavigationBack.setOnClickListener { + activity.finish() + } + + val adapter = ArrayAdapter( + fragment.requireContext(), + R.layout.onboarding_language_dropdown_item, + R.id.onboarding_language_text_view, + audioLanguageSelectionViewModel.availableAudioLanguages + ) + + binding.audioLanguageDropdownList.apply { + setAdapter(adapter) + setText( + audioLanguageSelectionViewModel.defaultLanguageSelection, + false + ) + setRawInputType(EditorInfo.TYPE_NULL) + } + + return binding.root + } +} diff --git a/app/src/main/java/org/oppia/android/app/onboarding/IntroFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/onboarding/IntroFragmentPresenter.kt index ac0b9d04401..50fa51300c7 100644 --- a/app/src/main/java/org/oppia/android/app/onboarding/IntroFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/onboarding/IntroFragmentPresenter.kt @@ -6,6 +6,8 @@ import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import org.oppia.android.R +import org.oppia.android.app.model.AudioLanguage +import org.oppia.android.app.options.AudioLanguageActivity import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.databinding.LearnerIntroFragmentBinding import javax.inject.Inject @@ -29,6 +31,7 @@ class IntroFragmentPresenter @Inject constructor( container, /* attachToRoot= */ false ) + binding.lifecycleOwner = fragment setLearnerName(profileNickname) @@ -43,6 +46,14 @@ class IntroFragmentPresenter @Inject constructor( appLanguageResourceHandler.getStringInLocale(R.string.app_name) ) + binding.onboardingNavigationContinue.setOnClickListener { + val intent = AudioLanguageActivity.createAudioLanguageActivityIntent( + fragment.requireContext(), + AudioLanguage.ENGLISH_AUDIO_LANGUAGE + ) + fragment.startActivity(intent) + } + return binding.root } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragment.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragment.kt index fd98e6259cd..71ea48ca09e 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragment.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragment.kt @@ -10,14 +10,23 @@ import org.oppia.android.app.fragment.InjectableFragment import org.oppia.android.app.model.AudioLanguage import org.oppia.android.app.model.AudioLanguageFragmentArguments import org.oppia.android.app.model.AudioLanguageFragmentStateBundle +import org.oppia.android.app.onboarding.AudioLanguageFragmentPresenter import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto +import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2 +import org.oppia.android.util.platformparameter.PlatformParameterValue import javax.inject.Inject /** The fragment to change the default audio language of the app. */ class AudioLanguageFragment : InjectableFragment(), AudioLanguageRadioButtonListener { + @Inject lateinit var audioLanguageFragmentPresenterV1: AudioLanguageFragmentPresenterV1 + @Inject lateinit var audioLanguageFragmentPresenter: AudioLanguageFragmentPresenter + @Inject + @field:EnableOnboardingFlowV2 + lateinit var enableOnboardingFlowV2: PlatformParameterValue + override fun onAttach(context: Context) { super.onAttach(context) (fragmentComponent as FragmentComponentImpl).inject(this) @@ -33,19 +42,27 @@ class AudioLanguageFragment : InjectableFragment(), AudioLanguageRadioButtonList savedInstanceState?.retrieveLanguageFromSavedState() ?: arguments?.retrieveLanguageFromArguments() ) { "Expected arguments to be passed to AudioLanguageFragment" } - return audioLanguageFragmentPresenter.handleOnCreateView(inflater, container, audioLanguage) + return if (enableOnboardingFlowV2.value) { + audioLanguageFragmentPresenter.handleCreateView(inflater, container) + } else { + audioLanguageFragmentPresenterV1.handleOnCreateView(inflater, container, audioLanguage) + } } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - val state = AudioLanguageFragmentStateBundle.newBuilder().apply { - audioLanguage = audioLanguageFragmentPresenter.getLanguageSelected() - }.build() - outState.putProto(FRAGMENT_SAVED_STATE_KEY, state) + if (!enableOnboardingFlowV2.value) { + val state = AudioLanguageFragmentStateBundle.newBuilder().apply { + audioLanguage = audioLanguageFragmentPresenterV1.getLanguageSelected() + }.build() + outState.putProto(FRAGMENT_SAVED_STATE_KEY, state) + } } override fun onLanguageSelected(audioLanguage: AudioLanguage) { - audioLanguageFragmentPresenter.onLanguageSelected(audioLanguage) + if (!enableOnboardingFlowV2.value) { + audioLanguageFragmentPresenterV1.onLanguageSelected(audioLanguage) + } } companion object { diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenterV1.kt similarity index 97% rename from app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt rename to app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenterV1.kt index 5195adcebe1..72774fec6ba 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenterV1.kt @@ -11,7 +11,7 @@ import org.oppia.android.databinding.AudioLanguageItemBinding import javax.inject.Inject /** The presenter for [AudioLanguageFragment]. */ -class AudioLanguageFragmentPresenter @Inject constructor( +class AudioLanguageFragmentPresenterV1 @Inject constructor( private val fragment: Fragment, private val audioLanguageSelectionViewModel: AudioLanguageSelectionViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageSelectionViewModel.kt index c9e0d998e1b..5e25aaabf5d 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageSelectionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageSelectionViewModel.kt @@ -31,6 +31,19 @@ class AudioLanguageSelectionViewModel @Inject constructor( ) } + // TODO(#4938): Update the pre-selection logic. + /** The pre-selected [AudioLanguage] to be shown in the language selection dropdown. */ + val defaultLanguageSelection = getLanguageDisplayName(AudioLanguage.ENGLISH_AUDIO_LANGUAGE) + + /** The list of [AudioLanguage]s supported by the app. */ + val availableAudioLanguages: List by lazy { + AudioLanguage.values().filter { it !in IGNORED_AUDIO_LANGUAGES }.map(::getLanguageDisplayName) + } + + private fun getLanguageDisplayName(audioLanguage: AudioLanguage): String { + return appLanguageResourceHandler.computeLocalizedDisplayName(audioLanguage) + } + private companion object { private val IGNORED_AUDIO_LANGUAGES = listOf( diff --git a/app/src/main/res/layout-land/audio_language_selection_fragment.xml b/app/src/main/res/layout-land/audio_language_selection_fragment.xml new file mode 100644 index 00000000000..ed683db064e --- /dev/null +++ b/app/src/main/res/layout-land/audio_language_selection_fragment.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + +