From 5cf09d07fa99f9f9edc3a915c1942f3e85648e7a Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Wed, 11 Nov 2020 10:40:00 +0530 Subject: [PATCH 01/27] issue 2098 --- .idea/gradle.xml | 3 ++- .idea/misc.xml | 4 ++-- .../domain/classify/rules/RuleQualifiers.kt | 20 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6aa35f75034..6466b7bedb7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,7 +20,8 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f06c82261e6..d5d35ec44f1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - + - + \ No newline at end of file diff --git a/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt b/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt index a868bd537f0..18b9d9faed7 100644 --- a/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt +++ b/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt @@ -2,42 +2,42 @@ package org.oppia.android.domain.classify.rules import javax.inject.Qualifier -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the continue interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the continue interaction. */ @Qualifier annotation class ContinueRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the fraction input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the fraction input interaction. */ @Qualifier annotation class FractionInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the item selection interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the item selection interaction. */ @Qualifier annotation class ItemSelectionInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the multiple choice interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the multiple choice interaction. */ @Qualifier annotation class MultipleChoiceInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the number with units interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the number with units interaction. */ @Qualifier annotation class NumberWithUnitsRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the text input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the text input interaction. */ @Qualifier annotation class TextInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the numeric input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the numeric input interaction. */ @Qualifier annotation class NumericInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the drag drop sort input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the drag drop sort input interaction. */ @Qualifier annotation class DragDropSortInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the image click input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the image click input interaction. */ @Qualifier annotation class ImageClickInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the ratio input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the ratio input interaction. */ @Qualifier annotation class RatioExpressionInputRules From f3483f87c4133e87aedb77afa920b55cb5f05e0a Mon Sep 17 00:00:00 2001 From: farees Date: Thu, 31 Dec 2020 22:47:15 +0530 Subject: [PATCH 02/27] test commit --- .idea/gradle.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6aa35f75034..6466b7bedb7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,7 +20,8 @@ - + \ No newline at end of file From 2110cdf3f857b0834be04db4f7d810d85a561082 Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Fri, 1 Jan 2021 01:11:14 +0530 Subject: [PATCH 03/27] Update gradle.xml --- .idea/gradle.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6466b7bedb7..6aa35f75034 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,8 +20,7 @@ - \ No newline at end of file + From e09a602460edb2e233447bc56356571a70238a9a Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Fri, 1 Jan 2021 01:11:48 +0530 Subject: [PATCH 04/27] Update misc.xml --- .idea/misc.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d35ec44f1..f06c82261e6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - + - \ No newline at end of file + From 38fb39f7e13d5bc80b044f1364220af6a6b6f87b Mon Sep 17 00:00:00 2001 From: farees Date: Fri, 1 Jan 2021 06:38:11 +0530 Subject: [PATCH 05/27] Fix gradle.xml --- .idea/gradle.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6466b7bedb7..6aa35f75034 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,8 +20,7 @@ - \ No newline at end of file + From 7c8bdaef878346a7caa9a90ca202fe7a3282fe12 Mon Sep 17 00:00:00 2001 From: farees Date: Mon, 4 Jan 2021 12:23:07 +0530 Subject: [PATCH 06/27] initial inmplementation --- .../options/AudioLanguageFragmentPresenter.kt | 54 +++++++++++++++++-- .../app/options/LanguageItemViewModel.kt | 5 ++ .../app/options/LanguageSelectionViewModel.kt | 26 +++++++++ .../res/layout/audio_language_fragment.xml | 7 +++ app/src/main/res/layout/language_items.xml | 7 ++- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt create mode 100644 app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index b23f9ca4bc4..85f32f0d7a3 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -5,11 +5,20 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import org.oppia.android.app.recyclerview.BindableAdapter +import org.oppia.android.app.topic.practice.TopicPracticeViewModel +import org.oppia.android.app.topic.practice.practiceitemviewmodel.TopicPracticeSubtopicViewModel +import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AudioLanguageFragmentBinding +import org.oppia.android.databinding.LanguageItemsBinding +import org.oppia.android.databinding.TopicPracticeSubtopicBinding import javax.inject.Inject /** The presenter for [AudioLanguageFragment]. */ -class AudioLanguageFragmentPresenter @Inject constructor(private val fragment: Fragment) { +class AudioLanguageFragmentPresenter @Inject constructor( + private val fragment: Fragment, + private val viewModelProvider: ViewModelProvider +) { private lateinit var prefSummaryValue: String private lateinit var languageSelectionAdapter: LanguageSelectionAdapter @@ -25,12 +34,13 @@ class AudioLanguageFragmentPresenter @Inject constructor(private val fragment: F container, /* attachToRoot= */ false ) + binding.viewModel = getLanguageSelectionViewModel() prefSummaryValue = prefValue languageSelectionAdapter = LanguageSelectionAdapter(prefKey) { updateAudioLanguage(it) } binding.audioLanguageRecyclerView.apply { - adapter = languageSelectionAdapter + adapter = createRecyclerViewAdapter() } binding.audioLanguageToolbar?.setNavigationOnClickListener { @@ -40,7 +50,7 @@ class AudioLanguageFragmentPresenter @Inject constructor(private val fragment: F (fragment.activity as AudioLanguageActivity).setResult(REQUEST_CODE_AUDIO_LANGUAGE, intent) (fragment.activity as AudioLanguageActivity).finish() } - createAdapter() +// createAdapter() return binding.root } @@ -69,4 +79,42 @@ class AudioLanguageFragmentPresenter @Inject constructor(private val fragment: F languageSelectionAdapter.setLanguageList(languageList) languageSelectionAdapter.setDefaultLanguageSelected(prefSummaryValue = prefSummaryValue) } + + private fun createRecyclerViewAdapter(): BindableAdapter { + return BindableAdapter.MultiTypeBuilder + .newBuilder { viewModel -> + ViewType.VIEW_TYPE_LANGUAGE + } + .registerViewDataBinder( + viewType = ViewType.VIEW_TYPE_LANGUAGE, + inflateDataBinding = LanguageItemsBinding::inflate, + setViewModel = this::bindSkillView, + transformViewModel = {it as LanguageSelectionViewModel} + ).build() + } + + private fun bindSkillView( + binding: TopicPracticeSubtopicBinding, + model: TopicPracticeSubtopicViewModel + ) { + binding.viewModel = model +// binding.isChecked = selectedSubtopicIdList.contains(model.subtopic.subtopicId) +// binding.subtopicCheckBox.setOnCheckedChangeListener { _, isChecked -> +// if (isChecked) { +// subtopicSelected(model.subtopic.subtopicId, model.subtopic.skillIdsList) +// } else { +// subtopicUnselected(model.subtopic.subtopicId, model.subtopic.skillIdsList) +// } +// } + } + + + private enum class ViewType { + VIEW_TYPE_LANGUAGE + } + + private fun getLanguageSelectionViewModel() : LanguageSelectionViewModel { + return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) + } + } diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt new file mode 100644 index 00000000000..4419f4b1a41 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -0,0 +1,5 @@ +package org.oppia.android.app.options + +import org.oppia.android.app.viewmodel.ObservableViewModel + +class LanguageItemViewModel(val language: String): ObservableViewModel() \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt new file mode 100644 index 00000000000..40a6775ed3c --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt @@ -0,0 +1,26 @@ +package org.oppia.android.app.options + +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.LiveData +import org.oppia.android.app.fragment.FragmentScope +import org.oppia.android.app.viewmodel.ObservableViewModel +import javax.inject.Inject + +@FragmentScope +class LanguageSelectionViewModel @Inject constructor( + val activity: AppCompatActivity +) :ObservableViewModel() { + + var audioLanguagesList = listOf( + LanguageItemViewModel("No Audio"), + LanguageItemViewModel("English"), + LanguageItemViewModel("French"), + LanguageItemViewModel("Hindi"), + LanguageItemViewModel("Chinese") + ) + + + val recyclerViewAudioList: List by lazy { + audioLanguagesList + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/audio_language_fragment.xml b/app/src/main/res/layout/audio_language_fragment.xml index a405f01f283..ebe6abdce95 100644 --- a/app/src/main/res/layout/audio_language_fragment.xml +++ b/app/src/main/res/layout/audio_language_fragment.xml @@ -2,6 +2,12 @@ + + + + @@ -45,6 +51,7 @@ android:clipToPadding="false" android:overScrollMode="never" android:paddingBottom="132dp" + app:list="@{viewModel.recyclerViewAudioList}" android:scrollbars="none" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/language_items.xml b/app/src/main/res/layout/language_items.xml index 702e5bf7551..3ca720d0737 100755 --- a/app/src/main/res/layout/language_items.xml +++ b/app/src/main/res/layout/language_items.xml @@ -1,10 +1,12 @@ - + @@ -33,7 +36,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="24dp" android:fontFamily="sans-serif" - android:text="@{languageString}" + android:text="@{viewModel.language}" android:textColor="@color/oppiaPrimaryText" android:textSize="16sp" /> From cc86c6abae83b1ecc75f17f176a1230edb6b9941 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 5 Jan 2021 22:10:25 +0530 Subject: [PATCH 07/27] Ready for Review --- .../options/AppLanguageFragmentPresenter.kt | 75 ++++++++++++------- .../options/AudioLanguageFragmentPresenter.kt | 68 ++++++----------- .../app/options/LanguageItemViewModel.kt | 2 +- .../app/options/LanguageSelectionAdapter.kt | 72 ------------------ .../app/options/LanguageSelectionViewModel.kt | 23 ++++-- .../main/res/layout/app_language_fragment.xml | 7 ++ .../res/layout/audio_language_fragment.xml | 2 +- app/src/main/res/layout/language_items.xml | 5 +- 8 files changed, 99 insertions(+), 155 deletions(-) delete mode 100644 app/src/main/java/org/oppia/android/app/options/LanguageSelectionAdapter.kt diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index bf8ff6e0a4d..728fe1b91b6 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -5,14 +5,20 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer +import org.oppia.android.app.recyclerview.BindableAdapter +import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AppLanguageFragmentBinding +import org.oppia.android.databinding.LanguageItemsBinding import javax.inject.Inject /** The presenter for [AppLanguageFragment]. */ -class AppLanguageFragmentPresenter @Inject constructor(private val fragment: Fragment) { - private lateinit var languageSelectionAdapter: LanguageSelectionAdapter +class AppLanguageFragmentPresenter @Inject constructor( + private val fragment: Fragment, + private val viewModelProvider: ViewModelProvider +) { private lateinit var prefSummaryValue: String - + private lateinit var languageSelectionViewModel: LanguageSelectionViewModel fun handleOnCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -25,47 +31,62 @@ class AppLanguageFragmentPresenter @Inject constructor(private val fragment: Fra /* attachToRoot= */ false ) this.prefSummaryValue = prefSummaryValue - languageSelectionAdapter = LanguageSelectionAdapter(prefKey) { - updateAppLanguage(it) - } + languageSelectionViewModel = getLanguageSelectionViewModel() + binding.viewModel = languageSelectionViewModel + languageSelectionViewModel.selectedLanguage.value = prefSummaryValue binding.languageRecyclerView.apply { - adapter = languageSelectionAdapter + adapter = createRecyclerViewAdapter() } binding.appLanguageToolbar?.setNavigationOnClickListener { - val message = languageSelectionAdapter.getSelectedLanguage() + val message = languageSelectionViewModel.selectedLanguage.value val intent = Intent() intent.putExtra(MESSAGE_APP_LANGUAGE_ARGUMENT_KEY, message) (fragment.activity as AppLanguageActivity).setResult(REQUEST_CODE_APP_LANGUAGE, intent) (fragment.activity as AppLanguageActivity).finish() } - createAdapter() return binding.root } - private fun updateAppLanguage(appLanguage: String) { - // The first branch of (when) will be used in the case of multipane - when (val parentActivity = fragment.activity) { - is OptionsActivity -> parentActivity.optionActivityPresenter.updateAppLanguage(appLanguage) - is AppLanguageActivity -> parentActivity.appLanguageActivityPresenter.setLanguageSelected( - appLanguage - ) + fun getLanguageSelected(): String { + return languageSelectionViewModel.selectedLanguage.value!! + } + + private fun createRecyclerViewAdapter(): BindableAdapter { + return BindableAdapter.MultiTypeBuilder + .newBuilder { viewModel -> + ViewType.VIEW_TYPE_LANGUAGE + } + .registerViewDataBinder( + viewType = ViewType.VIEW_TYPE_LANGUAGE, + inflateDataBinding = LanguageItemsBinding::inflate, + setViewModel = this::bindSkillView, + transformViewModel = { it as LanguageItemViewModel } + ).build() + } + + private fun bindSkillView( + binding: LanguageItemsBinding, + model: LanguageItemViewModel + ) { + binding.viewModel = model + binding.radioContainer.setOnClickListener { + languageSelectionViewModel.selectedLanguage.value = model.language } + languageSelectionViewModel.selectedLanguage.observe( + fragment, + Observer { + binding.isChecked = model.language == it + } + ) } - fun getLanguageSelected(): String { - return languageSelectionAdapter.getSelectedLanguage() + private enum class ViewType { + VIEW_TYPE_LANGUAGE } - private fun createAdapter() { - // TODO(#669): Replace dummy list with actual language list from backend. - val languageList = ArrayList() - languageList.add("English") - languageList.add("French") - languageList.add("Hindi") - languageList.add("Chinese") - languageSelectionAdapter.setLanguageList(languageList) - languageSelectionAdapter.setDefaultLanguageSelected(prefSummaryValue = prefSummaryValue) + private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { + return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 85f32f0d7a3..98401ab57d0 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -5,13 +5,11 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.topic.practice.TopicPracticeViewModel -import org.oppia.android.app.topic.practice.practiceitemviewmodel.TopicPracticeSubtopicViewModel import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AudioLanguageFragmentBinding import org.oppia.android.databinding.LanguageItemsBinding -import org.oppia.android.databinding.TopicPracticeSubtopicBinding import javax.inject.Inject /** The presenter for [AudioLanguageFragment]. */ @@ -21,8 +19,7 @@ class AudioLanguageFragmentPresenter @Inject constructor( ) { private lateinit var prefSummaryValue: String - private lateinit var languageSelectionAdapter: LanguageSelectionAdapter - + private lateinit var languageSelectionViewModel: LanguageSelectionViewModel fun handleOnCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -34,17 +31,16 @@ class AudioLanguageFragmentPresenter @Inject constructor( container, /* attachToRoot= */ false ) - binding.viewModel = getLanguageSelectionViewModel() + languageSelectionViewModel = getLanguageSelectionViewModel() + binding.viewModel = languageSelectionViewModel prefSummaryValue = prefValue - languageSelectionAdapter = LanguageSelectionAdapter(prefKey) { - updateAudioLanguage(it) - } + languageSelectionViewModel.selectedLanguage.value = prefSummaryValue binding.audioLanguageRecyclerView.apply { adapter = createRecyclerViewAdapter() } binding.audioLanguageToolbar?.setNavigationOnClickListener { - val message = languageSelectionAdapter.getSelectedLanguage() + val message = languageSelectionViewModel.selectedLanguage.value val intent = Intent() intent.putExtra(MESSAGE_AUDIO_LANGUAGE_ARGUMENT_KEY, message) (fragment.activity as AudioLanguageActivity).setResult(REQUEST_CODE_AUDIO_LANGUAGE, intent) @@ -55,29 +51,7 @@ class AudioLanguageFragmentPresenter @Inject constructor( } fun getLanguageSelected(): String { - return languageSelectionAdapter.getSelectedLanguage() - } - - private fun updateAudioLanguage(audioLanguage: String) { - // The first branch of (when) will be used in the case of multipane - when (val parentActivity = fragment.activity) { - is OptionsActivity -> - parentActivity.optionActivityPresenter.updateAudioLanguage(audioLanguage) - is AudioLanguageActivity -> - parentActivity.audioLanguageActivityPresenter.setLanguageSelected(audioLanguage) - } - } - - private fun createAdapter() { - // TODO(#669): Replace dummy list with actual language list from backend. - val languageList = ArrayList() - languageList.add("No Audio") - languageList.add("English") - languageList.add("French") - languageList.add("Hindi") - languageList.add("Chinese") - languageSelectionAdapter.setLanguageList(languageList) - languageSelectionAdapter.setDefaultLanguageSelected(prefSummaryValue = prefSummaryValue) + return languageSelectionViewModel.selectedLanguage.value!! } private fun createRecyclerViewAdapter(): BindableAdapter { @@ -89,32 +63,32 @@ class AudioLanguageFragmentPresenter @Inject constructor( viewType = ViewType.VIEW_TYPE_LANGUAGE, inflateDataBinding = LanguageItemsBinding::inflate, setViewModel = this::bindSkillView, - transformViewModel = {it as LanguageSelectionViewModel} + transformViewModel = { it as LanguageItemViewModel } ).build() } private fun bindSkillView( - binding: TopicPracticeSubtopicBinding, - model: TopicPracticeSubtopicViewModel + binding: LanguageItemsBinding, + model: LanguageItemViewModel ) { binding.viewModel = model -// binding.isChecked = selectedSubtopicIdList.contains(model.subtopic.subtopicId) -// binding.subtopicCheckBox.setOnCheckedChangeListener { _, isChecked -> -// if (isChecked) { -// subtopicSelected(model.subtopic.subtopicId, model.subtopic.skillIdsList) -// } else { -// subtopicUnselected(model.subtopic.subtopicId, model.subtopic.skillIdsList) -// } -// } + binding.radioContainer.setOnClickListener { + prefSummaryValue = model.language + languageSelectionViewModel.selectedLanguage.value = model.language + } + languageSelectionViewModel.selectedLanguage.observe( + fragment, + Observer { + binding.isChecked = model.language == it + } + ) } - private enum class ViewType { VIEW_TYPE_LANGUAGE } - private fun getLanguageSelectionViewModel() : LanguageSelectionViewModel { + private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } - } diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index 4419f4b1a41..e11952c9731 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -2,4 +2,4 @@ package org.oppia.android.app.options import org.oppia.android.app.viewmodel.ObservableViewModel -class LanguageItemViewModel(val language: String): ObservableViewModel() \ No newline at end of file +class LanguageItemViewModel(val language: String) : ObservableViewModel() diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionAdapter.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionAdapter.kt deleted file mode 100644 index 68b778d5222..00000000000 --- a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionAdapter.kt +++ /dev/null @@ -1,72 +0,0 @@ -package org.oppia.android.app.options - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.databinding.DataBindingUtil -import androidx.recyclerview.widget.RecyclerView -import org.oppia.android.R -import org.oppia.android.databinding.LanguageItemsBinding - -// TODO(#216): Make use of generic data-binding-enabled RecyclerView adapter. - -/** Adapter to bind languages to [RecyclerView] inside [AppLanguageActivityPresenter] and [AudioLanguageActivityPresenter]. */ -class LanguageSelectionAdapter( - private val prefKey: String, - private val onLanguageClicked: (language: String) -> Unit = {} -) : - RecyclerView.Adapter() { - - private var prefSummaryValue: String? = null - private var languageList: List = ArrayList() - private lateinit var selectedLanguage: String - private var selectedPosition: Int = -1 - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LanguageViewHolder { - val languageListItemBinding = DataBindingUtil.inflate( - LayoutInflater.from(parent.context), - R.layout.language_items, parent, - /* attachToRoot= */ false - ) - return LanguageViewHolder(languageListItemBinding) - } - - override fun onBindViewHolder(languageViewHolder: LanguageViewHolder, i: Int) { - languageViewHolder.bind(languageList[i], i) - } - - override fun getItemCount(): Int { - return languageList.size - } - - fun setLanguageList(languageList: List) { - this.languageList = languageList - notifyDataSetChanged() - } - - fun setDefaultLanguageSelected(prefSummaryValue: String?) { - selectedPosition = languageList.indexOf(prefSummaryValue) - this.prefSummaryValue = prefSummaryValue - } - - fun getSelectedLanguage(): String { - selectedLanguage = languageList[selectedPosition] - return selectedLanguage - } - - inner class LanguageViewHolder(val binding: LanguageItemsBinding) : - RecyclerView.ViewHolder(binding.root) { - internal fun bind(language: String, position: Int) { - binding.languageString = language - binding.languageRadioButton.isChecked = position == selectedPosition - binding.radioContainer.setOnClickListener { - if (prefKey == APP_LANGUAGE || prefKey == AUDIO_LANGUAGE) { - selectedPosition = adapterPosition - notifyDataSetChanged() - onLanguageClicked.invoke(getSelectedLanguage()) - } else { - selectedPosition = adapterPosition - notifyDataSetChanged() - } - } - } - } -} diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt index 40a6775ed3c..96d6f2815ae 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt @@ -1,7 +1,7 @@ package org.oppia.android.app.options import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.viewmodel.ObservableViewModel import javax.inject.Inject @@ -9,9 +9,17 @@ import javax.inject.Inject @FragmentScope class LanguageSelectionViewModel @Inject constructor( val activity: AppCompatActivity -) :ObservableViewModel() { +) : ObservableViewModel() { - var audioLanguagesList = listOf( + val selectedLanguage = MutableLiveData() + + val appLanguagesList = listOf( + LanguageItemViewModel("English"), + LanguageItemViewModel("French"), + LanguageItemViewModel("Hindi"), + LanguageItemViewModel("Chinese") + ) + val audioLanguagesList = listOf( LanguageItemViewModel("No Audio"), LanguageItemViewModel("English"), LanguageItemViewModel("French"), @@ -19,8 +27,11 @@ class LanguageSelectionViewModel @Inject constructor( LanguageItemViewModel("Chinese") ) - - val recyclerViewAudioList: List by lazy { + val recyclerViewAudioLanguageList: List by lazy { audioLanguagesList } -} \ No newline at end of file + + val recyclerViewAppLanguageList: List by lazy { + appLanguagesList + } +} diff --git a/app/src/main/res/layout/app_language_fragment.xml b/app/src/main/res/layout/app_language_fragment.xml index 5f8d3e58c6a..0a74ee0de07 100644 --- a/app/src/main/res/layout/app_language_fragment.xml +++ b/app/src/main/res/layout/app_language_fragment.xml @@ -2,6 +2,12 @@ + + + + @@ -46,6 +52,7 @@ android:overScrollMode="never" android:paddingBottom="132dp" android:scrollbars="none" + app:list="@{viewModel.recyclerViewAppLanguageList}" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/audio_language_fragment.xml b/app/src/main/res/layout/audio_language_fragment.xml index ebe6abdce95..8b9d9b84e07 100644 --- a/app/src/main/res/layout/audio_language_fragment.xml +++ b/app/src/main/res/layout/audio_language_fragment.xml @@ -51,7 +51,7 @@ android:clipToPadding="false" android:overScrollMode="never" android:paddingBottom="132dp" - app:list="@{viewModel.recyclerViewAudioList}" + app:list="@{viewModel.recyclerViewAudioLanguageList}" android:scrollbars="none" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/language_items.xml b/app/src/main/res/layout/language_items.xml index 3ca720d0737..0b331bf9236 100755 --- a/app/src/main/res/layout/language_items.xml +++ b/app/src/main/res/layout/language_items.xml @@ -4,6 +4,9 @@ + @@ -26,7 +29,7 @@ android:layout_marginStart="24dp" android:layout_marginEnd="24dp" android:clickable="false" - android:checked="true" + android:checked="@{isChecked}" android:minWidth="20dp" android:minHeight="20dp" /> From 409ccb35a0492ec397f09f6be012b393f27313ff Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 5 Jan 2021 22:44:47 +0530 Subject: [PATCH 08/27] Updated BAZEL with new viewmodels --- app/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/BUILD.bazel b/app/BUILD.bazel index e89f2b735f4..e36160f031c 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -177,6 +177,8 @@ VIEW_MODELS = [ "src/main/java/org/oppia/android/app/onboarding/ViewPagerSlide.kt", "src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt", "src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListViewModel.kt", + "src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt", + "src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt", "src/main/java/org/oppia/android/app/options/OptionControlsViewModel.kt", "src/main/java/org/oppia/android/app/options/OptionsAppLanguageViewModel.kt", "src/main/java/org/oppia/android/app/options/OptionsAudioLanguageViewModel.kt", From e73d04d85286cf73950942ef48569c34058a8fc0 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 5 Jan 2021 22:59:54 +0530 Subject: [PATCH 09/27] Reformatting code and making changes in other configuration --- app/src/main/res/layout-land/app_language_fragment.xml | 7 +++++++ .../main/res/layout-land/audio_language_fragment.xml | 10 +++++++++- .../main/res/layout-sw600dp/app_language_fragment.xml | 10 +++++++++- .../res/layout-sw600dp/audio_language_fragment.xml | 10 +++++++++- app/src/main/res/layout/app_language_fragment.xml | 9 +++++---- app/src/main/res/layout/audio_language_fragment.xml | 7 ++++--- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/src/main/res/layout-land/app_language_fragment.xml b/app/src/main/res/layout-land/app_language_fragment.xml index f535b077c77..5cad9b3a693 100644 --- a/app/src/main/res/layout-land/app_language_fragment.xml +++ b/app/src/main/res/layout-land/app_language_fragment.xml @@ -2,6 +2,12 @@ + + + + @@ -46,6 +52,7 @@ android:overScrollMode="never" android:paddingBottom="96dp" android:scrollbars="none" + app:list="@{viewModel.recyclerViewAppLanguageList}" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout-land/audio_language_fragment.xml b/app/src/main/res/layout-land/audio_language_fragment.xml index a117ade8013..dfe7fcc80c0 100644 --- a/app/src/main/res/layout-land/audio_language_fragment.xml +++ b/app/src/main/res/layout-land/audio_language_fragment.xml @@ -2,6 +2,13 @@ + + + + + @@ -50,7 +57,8 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAudioLanguageList}" /> + + + + + @@ -27,7 +34,8 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAppLanguageList}" /> diff --git a/app/src/main/res/layout-sw600dp/audio_language_fragment.xml b/app/src/main/res/layout-sw600dp/audio_language_fragment.xml index 1b7763de8b8..41780c3b494 100644 --- a/app/src/main/res/layout-sw600dp/audio_language_fragment.xml +++ b/app/src/main/res/layout-sw600dp/audio_language_fragment.xml @@ -2,6 +2,13 @@ + + + + + @@ -27,7 +34,8 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAudioLanguageList}" /> diff --git a/app/src/main/res/layout/app_language_fragment.xml b/app/src/main/res/layout/app_language_fragment.xml index 0a74ee0de07..44b3cab385f 100644 --- a/app/src/main/res/layout/app_language_fragment.xml +++ b/app/src/main/res/layout/app_language_fragment.xml @@ -3,9 +3,10 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + + type="org.oppia.android.app.options.LanguageSelectionViewModel" /> @@ -52,12 +53,12 @@ android:overScrollMode="never" android:paddingBottom="132dp" android:scrollbars="none" - app:list="@{viewModel.recyclerViewAppLanguageList}" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAppLanguageList}" /> + + type="org.oppia.android.app.options.LanguageSelectionViewModel" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAudioLanguageList}" /> Date: Thu, 7 Jan 2021 01:31:42 +0530 Subject: [PATCH 10/27] Fixed the Tablet issue --- .../app/options/AppLanguageFragmentPresenter.kt | 11 +++++++++++ .../app/options/AudioLanguageFragmentPresenter.kt | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 728fe1b91b6..023ca088941 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -73,6 +73,7 @@ class AppLanguageFragmentPresenter @Inject constructor( binding.viewModel = model binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language + updateAppLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, @@ -82,6 +83,16 @@ class AppLanguageFragmentPresenter @Inject constructor( ) } + private fun updateAppLanguage(appLanguage: String) { + // The first branch of (when) will be used in the case of multipane + when (val parentActivity = fragment.activity) { + is OptionsActivity -> parentActivity.optionActivityPresenter.updateAppLanguage(appLanguage) + is AppLanguageActivity -> parentActivity.appLanguageActivityPresenter.setLanguageSelected( + appLanguage + ) + } + } + private enum class ViewType { VIEW_TYPE_LANGUAGE } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 98401ab57d0..a4a825167ba 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -73,8 +73,8 @@ class AudioLanguageFragmentPresenter @Inject constructor( ) { binding.viewModel = model binding.radioContainer.setOnClickListener { - prefSummaryValue = model.language languageSelectionViewModel.selectedLanguage.value = model.language + updateAudioLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, @@ -84,6 +84,16 @@ class AudioLanguageFragmentPresenter @Inject constructor( ) } + private fun updateAudioLanguage(audioLanguage: String) { + // The first branch of (when) will be used in the case of multipane + when (val parentActivity = fragment.activity) { + is OptionsActivity -> + parentActivity.optionActivityPresenter.updateAudioLanguage(audioLanguage) + is AudioLanguageActivity -> + parentActivity.audioLanguageActivityPresenter.setLanguageSelected(audioLanguage) + } + } + private enum class ViewType { VIEW_TYPE_LANGUAGE } From 8da06e936ddaa31aafedf29ef91e7a835e05e739 Mon Sep 17 00:00:00 2001 From: farees Date: Fri, 8 Jan 2021 20:12:58 +0530 Subject: [PATCH 11/27] Adding Requested changes --- .../app/options/AppLanguageFragmentPresenter.kt | 4 ++-- .../app/options/AudioLanguageFragmentPresenter.kt | 4 ++-- .../android/app/options/LanguageItemViewModel.kt | 1 + .../android/app/options/LanguageSelectionViewModel.kt | 5 +++-- .../main/res/layout-land/app_language_fragment.xml | 7 ++++--- app/src/main/res/layout-land/language_items.xml | 11 ++++++++--- app/src/main/res/layout-land/option_app_language.xml | 2 +- .../main/res/layout-sw600dp/option_app_language.xml | 4 ++-- app/src/main/res/layout/language_items.xml | 7 +++---- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 023ca088941..933461dffd5 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -55,14 +55,14 @@ class AppLanguageFragmentPresenter @Inject constructor( private fun createRecyclerViewAdapter(): BindableAdapter { return BindableAdapter.MultiTypeBuilder - .newBuilder { viewModel -> + .newBuilder { ViewType.VIEW_TYPE_LANGUAGE } .registerViewDataBinder( viewType = ViewType.VIEW_TYPE_LANGUAGE, inflateDataBinding = LanguageItemsBinding::inflate, setViewModel = this::bindSkillView, - transformViewModel = { it as LanguageItemViewModel } + transformViewModel = { it } ).build() } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index a4a825167ba..6e1e9fd90ec 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -46,7 +46,7 @@ class AudioLanguageFragmentPresenter @Inject constructor( (fragment.activity as AudioLanguageActivity).setResult(REQUEST_CODE_AUDIO_LANGUAGE, intent) (fragment.activity as AudioLanguageActivity).finish() } -// createAdapter() + return binding.root } @@ -63,7 +63,7 @@ class AudioLanguageFragmentPresenter @Inject constructor( viewType = ViewType.VIEW_TYPE_LANGUAGE, inflateDataBinding = LanguageItemsBinding::inflate, setViewModel = this::bindSkillView, - transformViewModel = { it as LanguageItemViewModel } + transformViewModel = { it } ).build() } diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index e11952c9731..9c0c0fc421d 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -2,4 +2,5 @@ package org.oppia.android.app.options import org.oppia.android.app.viewmodel.ObservableViewModel +/** Language item view model for the recycler view in [AppLanguageFragment] and [AudioLanguageFragment]. */ class LanguageItemViewModel(val language: String) : ObservableViewModel() diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt index 96d6f2815ae..d31181fb675 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt @@ -6,6 +6,7 @@ import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.viewmodel.ObservableViewModel import javax.inject.Inject +/** Language list view model for the recycler view in [AppLanguageFragment] and [AudioLanguageFragment]. */ @FragmentScope class LanguageSelectionViewModel @Inject constructor( val activity: AppCompatActivity @@ -13,13 +14,13 @@ class LanguageSelectionViewModel @Inject constructor( val selectedLanguage = MutableLiveData() - val appLanguagesList = listOf( + private val appLanguagesList = listOf( LanguageItemViewModel("English"), LanguageItemViewModel("French"), LanguageItemViewModel("Hindi"), LanguageItemViewModel("Chinese") ) - val audioLanguagesList = listOf( + private val audioLanguagesList = listOf( LanguageItemViewModel("No Audio"), LanguageItemViewModel("English"), LanguageItemViewModel("French"), diff --git a/app/src/main/res/layout-land/app_language_fragment.xml b/app/src/main/res/layout-land/app_language_fragment.xml index 5cad9b3a693..27eeb35b804 100644 --- a/app/src/main/res/layout-land/app_language_fragment.xml +++ b/app/src/main/res/layout-land/app_language_fragment.xml @@ -3,9 +3,10 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + + type="org.oppia.android.app.options.LanguageSelectionViewModel" /> + app:layout_constraintTop_toBottomOf="@id/toolbar_shadow_view" + app:list="@{viewModel.recyclerViewAppLanguageList}" /> + name="isChecked" + type="Boolean" /> + + @@ -33,7 +38,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="24dp" android:fontFamily="sans-serif" - android:text="@{languageString}" + android:text="@{viewModel.language}" android:textColor="@color/oppiaPrimaryText" android:textSize="16sp" /> diff --git a/app/src/main/res/layout-land/option_app_language.xml b/app/src/main/res/layout-land/option_app_language.xml index 92a36cbf95e..df4d3807c0f 100644 --- a/app/src/main/res/layout-land/option_app_language.xml +++ b/app/src/main/res/layout-land/option_app_language.xml @@ -27,8 +27,8 @@ android:layout_height="wrap_content" android:fontFamily="sans-serif" android:text="@string/app_language" - android:textColor="@color/oppiaPrimaryTextDark" android:textAlignment="viewStart" + android:textColor="@color/oppiaPrimaryTextDark" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@id/app_language_text_view" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout-sw600dp/option_app_language.xml b/app/src/main/res/layout-sw600dp/option_app_language.xml index 7b86cfe4078..430489be0a1 100644 --- a/app/src/main/res/layout-sw600dp/option_app_language.xml +++ b/app/src/main/res/layout-sw600dp/option_app_language.xml @@ -17,8 +17,8 @@ android:id="@+id/app_language_item_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="48dp" android:background="@{commonViewModel.selectedFragmentIndex == viewModel.itemIndex ? @drawable/general_item_background_border_cyan : @drawable/general_item_background_border}" + android:minHeight="48dp" android:onClick="@{(v) -> viewModel.onAppLanguageClicked()}" android:paddingStart="16dp" android:paddingTop="20dp" @@ -31,11 +31,11 @@ android:layout_height="wrap_content" android:fontFamily="sans-serif" android:text="@string/app_language" + android:textAlignment="viewStart" android:textColor="@color/oppiaPrimaryTextDark" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@id/app_language_text_view" app:layout_constraintEnd_toEndOf="parent" - android:textAlignment="viewStart" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/language_items.xml b/app/src/main/res/layout/language_items.xml index 0b331bf9236..ca5abed4c6d 100755 --- a/app/src/main/res/layout/language_items.xml +++ b/app/src/main/res/layout/language_items.xml @@ -1,12 +1,11 @@ - + + @@ -28,8 +27,8 @@ android:layout_height="wrap_content" android:layout_marginStart="24dp" android:layout_marginEnd="24dp" - android:clickable="false" android:checked="@{isChecked}" + android:clickable="false" android:minWidth="20dp" android:minHeight="20dp" /> From f658450cd5aa2e0a06b55dffe4721c7342d2a71b Mon Sep 17 00:00:00 2001 From: farees Date: Mon, 11 Jan 2021 21:06:54 +0530 Subject: [PATCH 12/27] Resolving requested changes --- .../android/app/options/AudioLanguageFragmentPresenter.kt | 6 +++--- .../org/oppia/android/app/options/LanguageItemViewModel.kt | 5 ++++- .../oppia/android/app/options/LanguageSelectionViewModel.kt | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 6e1e9fd90ec..b69068694fc 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -50,13 +50,13 @@ class AudioLanguageFragmentPresenter @Inject constructor( return binding.root } - fun getLanguageSelected(): String { - return languageSelectionViewModel.selectedLanguage.value!! + fun getLanguageSelected(): String? { + return languageSelectionViewModel.selectedLanguage.value } private fun createRecyclerViewAdapter(): BindableAdapter { return BindableAdapter.MultiTypeBuilder - .newBuilder { viewModel -> + .newBuilder { ViewType.VIEW_TYPE_LANGUAGE } .registerViewDataBinder( diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index 9c0c0fc421d..bc15a4237a6 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -2,5 +2,8 @@ package org.oppia.android.app.options import org.oppia.android.app.viewmodel.ObservableViewModel -/** Language item view model for the recycler view in [AppLanguageFragment] and [AudioLanguageFragment]. */ +/** + * Language item view model for the recycler view in [AppLanguageFragment] and + * [AudioLanguageFragment]. + */ class LanguageItemViewModel(val language: String) : ObservableViewModel() diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt index d31181fb675..2ed56997b7a 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt @@ -6,7 +6,10 @@ import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.viewmodel.ObservableViewModel import javax.inject.Inject -/** Language list view model for the recycler view in [AppLanguageFragment] and [AudioLanguageFragment]. */ +/** + * Language list view model for the recycler view in [AppLanguageFragment] and + * [AudioLanguageFragment]. + */ @FragmentScope class LanguageSelectionViewModel @Inject constructor( val activity: AppCompatActivity From 2d0da65a8cd455de27b0a39635d8a6dda19c6f0a Mon Sep 17 00:00:00 2001 From: farees Date: Mon, 11 Jan 2021 21:09:15 +0530 Subject: [PATCH 13/27] NIT fix --- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 933461dffd5..3064621f375 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -49,8 +49,8 @@ class AppLanguageFragmentPresenter @Inject constructor( return binding.root } - fun getLanguageSelected(): String { - return languageSelectionViewModel.selectedLanguage.value!! + fun getLanguageSelected(): String? { + return languageSelectionViewModel.selectedLanguage.value } private fun createRecyclerViewAdapter(): BindableAdapter { From 6199e2de7ab1eb5cd79d48d0d004a29417d04906 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 12 Jan 2021 12:28:41 +0530 Subject: [PATCH 14/27] Resolving requested changes --- .../options/AppLanguageFragmentPresenter.kt | 17 ++++------------- .../options/AudioLanguageFragmentPresenter.kt | 19 +++++-------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 3064621f375..4010a476f9b 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -54,15 +54,11 @@ class AppLanguageFragmentPresenter @Inject constructor( } private fun createRecyclerViewAdapter(): BindableAdapter { - return BindableAdapter.MultiTypeBuilder - .newBuilder { - ViewType.VIEW_TYPE_LANGUAGE - } - .registerViewDataBinder( - viewType = ViewType.VIEW_TYPE_LANGUAGE, + return BindableAdapter.SingleTypeBuilder + .newBuilder() + .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindSkillView, - transformViewModel = { it } + setViewModel = this::bindSkillView ).build() } @@ -70,7 +66,6 @@ class AppLanguageFragmentPresenter @Inject constructor( binding: LanguageItemsBinding, model: LanguageItemViewModel ) { - binding.viewModel = model binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language updateAppLanguage(model.language) @@ -93,10 +88,6 @@ class AppLanguageFragmentPresenter @Inject constructor( } } - private enum class ViewType { - VIEW_TYPE_LANGUAGE - } - private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index b69068694fc..7c991bcb61b 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -55,15 +55,11 @@ class AudioLanguageFragmentPresenter @Inject constructor( } private fun createRecyclerViewAdapter(): BindableAdapter { - return BindableAdapter.MultiTypeBuilder - .newBuilder { - ViewType.VIEW_TYPE_LANGUAGE - } - .registerViewDataBinder( - viewType = ViewType.VIEW_TYPE_LANGUAGE, + return BindableAdapter.SingleTypeBuilder + .newBuilder() + .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindSkillView, - transformViewModel = { it } + setViewModel = this::bindSkillView ).build() } @@ -71,15 +67,14 @@ class AudioLanguageFragmentPresenter @Inject constructor( binding: LanguageItemsBinding, model: LanguageItemViewModel ) { - binding.viewModel = model binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language - updateAudioLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, Observer { binding.isChecked = model.language == it + updateAudioLanguage(model.language) } ) } @@ -94,10 +89,6 @@ class AudioLanguageFragmentPresenter @Inject constructor( } } - private enum class ViewType { - VIEW_TYPE_LANGUAGE - } - private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } From 7b532cd8fb610a5b08ca8174b70e075908bdafe7 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 12 Jan 2021 13:45:35 +0530 Subject: [PATCH 15/27] NIT fix --- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 4010a476f9b..249287d13c4 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -68,12 +68,12 @@ class AppLanguageFragmentPresenter @Inject constructor( ) { binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language - updateAppLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, Observer { binding.isChecked = model.language == it + updateAppLanguage(model.language) } ) } From 678c8464f3647d61dd4bc525115f425e4cf06e90 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 12 Jan 2021 14:25:48 +0530 Subject: [PATCH 16/27] NIT fix --- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 2 +- .../oppia/android/app/options/AudioLanguageFragmentPresenter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 249287d13c4..4010a476f9b 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -68,12 +68,12 @@ class AppLanguageFragmentPresenter @Inject constructor( ) { binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language + updateAppLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, Observer { binding.isChecked = model.language == it - updateAppLanguage(model.language) } ) } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 7c991bcb61b..97445b5c65e 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -69,12 +69,12 @@ class AudioLanguageFragmentPresenter @Inject constructor( ) { binding.radioContainer.setOnClickListener { languageSelectionViewModel.selectedLanguage.value = model.language + updateAudioLanguage(model.language) } languageSelectionViewModel.selectedLanguage.observe( fragment, Observer { binding.isChecked = model.language == it - updateAudioLanguage(model.language) } ) } From 173255a6723fbbbac06a25b800bc4b991280e4e0 Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 20 Jan 2021 13:24:20 +0530 Subject: [PATCH 17/27] update fun name --- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 4 ++-- .../android/app/options/AudioLanguageFragmentPresenter.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 4010a476f9b..5b65986edbc 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -58,11 +58,11 @@ class AppLanguageFragmentPresenter @Inject constructor( .newBuilder() .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindSkillView + setViewModel = this::bindLanguageView ).build() } - private fun bindSkillView( + private fun bindLanguageView( binding: LanguageItemsBinding, model: LanguageItemViewModel ) { diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 97445b5c65e..872cddd158c 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -59,11 +59,11 @@ class AudioLanguageFragmentPresenter @Inject constructor( .newBuilder() .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindSkillView + setViewModel = this::bindLanguageView ).build() } - private fun bindSkillView( + private fun bindLanguageView( binding: LanguageItemsBinding, model: LanguageItemViewModel ) { From 60e22eab9fd65faf6a5b3f3bcb7db25ebbbe9334 Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 20 Jan 2021 14:40:24 +0530 Subject: [PATCH 18/27] using databinding for audio language selection --- .../app/options/AudioLanguageFragment.kt | 8 ++++- .../options/AudioLanguageFragmentPresenter.kt | 31 +++++++++---------- .../app/options/LanguageItemViewModel.kt | 12 ++++++- .../options/LanguageRadioButtonListener.kt | 5 +++ .../app/options/LanguageSelectionViewModel.kt | 23 ++++++++------ app/src/main/res/layout/language_items.xml | 7 ++--- 6 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt 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 87510ab1c7a..2e51c079710 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 @@ -15,7 +15,9 @@ private const val SELECTED_AUDIO_LANGUAGE_SAVED_KEY = "AudioLanguageFragment.selected_audio_language" /** The fragment to change the default audio language of the app. */ -class AudioLanguageFragment : InjectableFragment() { +class AudioLanguageFragment : + InjectableFragment(), + LanguageRadioButtonListener { @Inject lateinit var audioLanguageFragmentPresenter: AudioLanguageFragmentPresenter @@ -68,4 +70,8 @@ class AudioLanguageFragment : InjectableFragment() { audioLanguageFragmentPresenter.getLanguageSelected() ) } + + override fun onLanguageSelected(selectedLanguage: String) { + audioLanguageFragmentPresenter.onLanguageSelected(selectedLanguage) + } } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 872cddd158c..8ca379b96b7 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -1,6 +1,7 @@ package org.oppia.android.app.options import android.content.Intent +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -47,6 +48,13 @@ class AudioLanguageFragmentPresenter @Inject constructor( (fragment.activity as AudioLanguageActivity).finish() } + languageSelectionViewModel.selectedLanguage.observe( + fragment, + Observer { + Log.d("selectedLanguage", "selected language -> $it") + } + ) + return binding.root } @@ -59,26 +67,10 @@ class AudioLanguageFragmentPresenter @Inject constructor( .newBuilder() .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindLanguageView + setViewModel = LanguageItemsBinding::setViewModel ).build() } - private fun bindLanguageView( - binding: LanguageItemsBinding, - model: LanguageItemViewModel - ) { - binding.radioContainer.setOnClickListener { - languageSelectionViewModel.selectedLanguage.value = model.language - updateAudioLanguage(model.language) - } - languageSelectionViewModel.selectedLanguage.observe( - fragment, - Observer { - binding.isChecked = model.language == it - } - ) - } - private fun updateAudioLanguage(audioLanguage: String) { // The first branch of (when) will be used in the case of multipane when (val parentActivity = fragment.activity) { @@ -89,6 +81,11 @@ class AudioLanguageFragmentPresenter @Inject constructor( } } + fun onLanguageSelected(selectedLanguage: String) { + languageSelectionViewModel.selectedLanguage.value = selectedLanguage + updateAudioLanguage(selectedLanguage) + } + private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index bc15a4237a6..1719ced13c3 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -1,9 +1,19 @@ package org.oppia.android.app.options +import androidx.lifecycle.LiveData +import androidx.lifecycle.Transformations import org.oppia.android.app.viewmodel.ObservableViewModel /** * Language item view model for the recycler view in [AppLanguageFragment] and * [AudioLanguageFragment]. */ -class LanguageItemViewModel(val language: String) : ObservableViewModel() +class LanguageItemViewModel( + val language: String, + val selectedLanguage: LiveData, + val languageRadioButtonListener: LanguageRadioButtonListener +) : ObservableViewModel() { + val isLanguageSelected: LiveData by lazy { + Transformations.map(selectedLanguage) { it == language } + } +} diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt b/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt new file mode 100644 index 00000000000..0dd8824997b --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt @@ -0,0 +1,5 @@ +package org.oppia.android.app.options + +interface LanguageRadioButtonListener { + fun onLanguageSelected(selectedLanguage: String) +} diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt index 2ed56997b7a..83ced75d498 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageSelectionViewModel.kt @@ -1,6 +1,7 @@ package org.oppia.android.app.options import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment import androidx.lifecycle.MutableLiveData import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.viewmodel.ObservableViewModel @@ -12,23 +13,25 @@ import javax.inject.Inject */ @FragmentScope class LanguageSelectionViewModel @Inject constructor( - val activity: AppCompatActivity + val activity: AppCompatActivity, + val fragment: Fragment ) : ObservableViewModel() { val selectedLanguage = MutableLiveData() + val languageRadioButtonListener = fragment as LanguageRadioButtonListener private val appLanguagesList = listOf( - LanguageItemViewModel("English"), - LanguageItemViewModel("French"), - LanguageItemViewModel("Hindi"), - LanguageItemViewModel("Chinese") + LanguageItemViewModel("English", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("French", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("Hindi", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("Chinese", selectedLanguage, languageRadioButtonListener) ) private val audioLanguagesList = listOf( - LanguageItemViewModel("No Audio"), - LanguageItemViewModel("English"), - LanguageItemViewModel("French"), - LanguageItemViewModel("Hindi"), - LanguageItemViewModel("Chinese") + LanguageItemViewModel("No Audio", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("English", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("French", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("Hindi", selectedLanguage, languageRadioButtonListener), + LanguageItemViewModel("Chinese", selectedLanguage, languageRadioButtonListener) ) val recyclerViewAudioLanguageList: List by lazy { diff --git a/app/src/main/res/layout/language_items.xml b/app/src/main/res/layout/language_items.xml index ca5abed4c6d..96d2bd7a90a 100755 --- a/app/src/main/res/layout/language_items.xml +++ b/app/src/main/res/layout/language_items.xml @@ -2,10 +2,6 @@ - - @@ -18,6 +14,7 @@ android:background="@drawable/general_item_background_border_light" android:gravity="center_vertical" android:minHeight="48dp" + android:onClick="@{() -> viewModel.languageRadioButtonListener.onLanguageSelected(viewModel.language)}" android:orientation="horizontal"> From d65bb2fea990478bed5fda0d2ecba5d5deb3c0a0 Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 20 Jan 2021 14:45:28 +0530 Subject: [PATCH 19/27] using databinding for app language selection --- .../app/options/AppLanguageFragment.kt | 9 +++++++- .../options/AppLanguageFragmentPresenter.kt | 22 +++++-------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt index 64593ae6388..24faf20529b 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt @@ -14,7 +14,10 @@ private const val KEY_APP_LANGUAGE_PREFERENCE_SUMMARY_VALUE = private const val SELECTED_LANGUAGE_SAVED_KEY = "AppLanguageFragment.selected_language" /** The fragment to change the language of the app. */ -class AppLanguageFragment : InjectableFragment() { +class AppLanguageFragment : + InjectableFragment(), + LanguageRadioButtonListener +{ @Inject lateinit var appLanguageFragmentPresenter: AppLanguageFragmentPresenter @@ -63,4 +66,8 @@ class AppLanguageFragment : InjectableFragment() { appLanguageFragmentPresenter.getLanguageSelected() ) } + + override fun onLanguageSelected(selectedLanguage: String) { + appLanguageFragmentPresenter.onLanguageSelected(selectedLanguage) + } } diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 5b65986edbc..3d29401c563 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -58,26 +58,10 @@ class AppLanguageFragmentPresenter @Inject constructor( .newBuilder() .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = this::bindLanguageView + setViewModel = LanguageItemsBinding::setViewModel ).build() } - private fun bindLanguageView( - binding: LanguageItemsBinding, - model: LanguageItemViewModel - ) { - binding.radioContainer.setOnClickListener { - languageSelectionViewModel.selectedLanguage.value = model.language - updateAppLanguage(model.language) - } - languageSelectionViewModel.selectedLanguage.observe( - fragment, - Observer { - binding.isChecked = model.language == it - } - ) - } - private fun updateAppLanguage(appLanguage: String) { // The first branch of (when) will be used in the case of multipane when (val parentActivity = fragment.activity) { @@ -88,6 +72,10 @@ class AppLanguageFragmentPresenter @Inject constructor( } } + fun onLanguageSelected(selectedLanguage: String){ + languageSelectionViewModel.selectedLanguage.value = selectedLanguage + } + private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) } From d4bf82ea5d53468f95be939b657451a46c74b9ec Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 20 Jan 2021 14:47:19 +0530 Subject: [PATCH 20/27] ktlint fix --- .../java/org/oppia/android/app/options/AppLanguageFragment.kt | 3 +-- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt index 24faf20529b..6c61523b3db 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt @@ -16,8 +16,7 @@ private const val SELECTED_LANGUAGE_SAVED_KEY = "AppLanguageFragment.selected_la /** The fragment to change the language of the app. */ class AppLanguageFragment : InjectableFragment(), - LanguageRadioButtonListener -{ + LanguageRadioButtonListener { @Inject lateinit var appLanguageFragmentPresenter: AppLanguageFragmentPresenter diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 3d29401c563..7262e1be978 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -5,7 +5,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import org.oppia.android.app.recyclerview.BindableAdapter import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AppLanguageFragmentBinding @@ -72,7 +71,7 @@ class AppLanguageFragmentPresenter @Inject constructor( } } - fun onLanguageSelected(selectedLanguage: String){ + fun onLanguageSelected(selectedLanguage: String) { languageSelectionViewModel.selectedLanguage.value = selectedLanguage } From a2ab17cb99f8fc0285de738c5e3d1027cb7af745 Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 20 Jan 2021 16:10:54 +0530 Subject: [PATCH 21/27] Fix bazel check --- app/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/app/BUILD.bazel b/app/BUILD.bazel index 8c7acf1d095..c423966b65d 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -63,6 +63,7 @@ LISTENERS = [ "src/main/java/org/oppia/android/app/options/LoadAppLanguageListListener.kt", "src/main/java/org/oppia/android/app/options/LoadAudioLanguageListListener.kt", "src/main/java/org/oppia/android/app/options/LoadReadingTextSizeListener.kt", + "src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt", "src/main/java/org/oppia/android/app/options/RouteToAppLanguageListListener.kt", "src/main/java/org/oppia/android/app/options/RouteToAudioLanguageListListener.kt", "src/main/java/org/oppia/android/app/options/RouteToReadingTextSizeListener.kt", From ea70b99c43730780449c6c9d3401e225d1ed3209 Mon Sep 17 00:00:00 2001 From: farees Date: Thu, 21 Jan 2021 07:44:00 +0530 Subject: [PATCH 22/27] Resolving Requested changes --- .../org/oppia/android/app/options/LanguageItemViewModel.kt | 2 +- .../android/app/options/LanguageRadioButtonListener.kt | 4 ++++ app/src/main/res/layout-land/language_items.xml | 7 ++----- app/src/main/res/layout/language_items.xml | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index 1719ced13c3..05fabe0cfe2 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -10,7 +10,7 @@ import org.oppia.android.app.viewmodel.ObservableViewModel */ class LanguageItemViewModel( val language: String, - val selectedLanguage: LiveData, + private val selectedLanguage: LiveData, val languageRadioButtonListener: LanguageRadioButtonListener ) : ObservableViewModel() { val isLanguageSelected: LiveData by lazy { diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt b/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt index 0dd8824997b..5eff5d5e21c 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageRadioButtonListener.kt @@ -1,5 +1,9 @@ package org.oppia.android.app.options +/** + * Listener for when the language is selected from the [AppLanguageFragment] or + * [AudioLanguageFragment]. + */ interface LanguageRadioButtonListener { fun onLanguageSelected(selectedLanguage: String) } diff --git a/app/src/main/res/layout-land/language_items.xml b/app/src/main/res/layout-land/language_items.xml index ca5abed4c6d..6bdb022d7d6 100644 --- a/app/src/main/res/layout-land/language_items.xml +++ b/app/src/main/res/layout-land/language_items.xml @@ -2,10 +2,6 @@ - - @@ -18,6 +14,7 @@ android:background="@drawable/general_item_background_border_light" android:gravity="center_vertical" android:minHeight="48dp" + android:onClick="@{() -> viewModel.languageRadioButtonListener.onLanguageSelected(viewModel.language)}" android:orientation="horizontal"> diff --git a/app/src/main/res/layout/language_items.xml b/app/src/main/res/layout/language_items.xml index 96d2bd7a90a..6bdb022d7d6 100755 --- a/app/src/main/res/layout/language_items.xml +++ b/app/src/main/res/layout/language_items.xml @@ -24,7 +24,7 @@ android:layout_height="wrap_content" android:layout_marginStart="24dp" android:layout_marginEnd="24dp" - android:checked="@{viewModel.isLanguageSelected()}" + android:checked="@{viewModel.isLanguageSelected}" android:clickable="false" android:minWidth="20dp" android:minHeight="20dp" /> From c7481dd7777d6ee6a07113c5ec56002e2629666a Mon Sep 17 00:00:00 2001 From: farees Date: Thu, 21 Jan 2021 07:45:26 +0530 Subject: [PATCH 23/27] Nit fix --- .../app/options/AudioLanguageFragmentPresenter.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 8ca379b96b7..1bef1a0bc49 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -1,12 +1,10 @@ package org.oppia.android.app.options import android.content.Intent -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import org.oppia.android.app.recyclerview.BindableAdapter import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AudioLanguageFragmentBinding @@ -48,13 +46,6 @@ class AudioLanguageFragmentPresenter @Inject constructor( (fragment.activity as AudioLanguageActivity).finish() } - languageSelectionViewModel.selectedLanguage.observe( - fragment, - Observer { - Log.d("selectedLanguage", "selected language -> $it") - } - ) - return binding.root } From 8a6ac34b71934ddbc937f68cdc44453cda207a7a Mon Sep 17 00:00:00 2001 From: farees Date: Thu, 21 Jan 2021 23:45:40 +0530 Subject: [PATCH 24/27] Radio Button fix --- .../android/app/options/LanguageItemViewModel.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index 05fabe0cfe2..6767bf8a5cc 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -1,7 +1,7 @@ package org.oppia.android.app.options +import androidx.databinding.ObservableBoolean import androidx.lifecycle.LiveData -import androidx.lifecycle.Transformations import org.oppia.android.app.viewmodel.ObservableViewModel /** @@ -10,10 +10,13 @@ import org.oppia.android.app.viewmodel.ObservableViewModel */ class LanguageItemViewModel( val language: String, - private val selectedLanguage: LiveData, + selectedLanguage: LiveData, val languageRadioButtonListener: LanguageRadioButtonListener ) : ObservableViewModel() { - val isLanguageSelected: LiveData by lazy { - Transformations.map(selectedLanguage) { it == language } + val isLanguageSelected = ObservableBoolean() + init { + selectedLanguage.observeForever { + isLanguageSelected.set(it == language) + } } } From d6d0185ac38b3e3ee2ff8ada80e976de026dc114 Mon Sep 17 00:00:00 2001 From: farees Date: Fri, 22 Jan 2021 00:30:00 +0530 Subject: [PATCH 25/27] NIT fix --- .../app/options/AppLanguageFragmentPresenter.kt | 10 ++-------- .../app/options/AudioLanguageFragmentPresenter.kt | 10 +--------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 7262e1be978..9b8d382f758 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AppLanguageFragmentBinding import org.oppia.android.databinding.LanguageItemsBinding import javax.inject.Inject @@ -14,10 +13,9 @@ import javax.inject.Inject /** The presenter for [AppLanguageFragment]. */ class AppLanguageFragmentPresenter @Inject constructor( private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider + private val languageSelectionViewModel: LanguageSelectionViewModel ) { private lateinit var prefSummaryValue: String - private lateinit var languageSelectionViewModel: LanguageSelectionViewModel fun handleOnCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -30,7 +28,6 @@ class AppLanguageFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) this.prefSummaryValue = prefSummaryValue - languageSelectionViewModel = getLanguageSelectionViewModel() binding.viewModel = languageSelectionViewModel languageSelectionViewModel.selectedLanguage.value = prefSummaryValue binding.languageRecyclerView.apply { @@ -73,9 +70,6 @@ class AppLanguageFragmentPresenter @Inject constructor( fun onLanguageSelected(selectedLanguage: String) { languageSelectionViewModel.selectedLanguage.value = selectedLanguage - } - - private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { - return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) + updateAppLanguage(selectedLanguage) } } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 1bef1a0bc49..2166fee1312 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AudioLanguageFragmentBinding import org.oppia.android.databinding.LanguageItemsBinding import javax.inject.Inject @@ -14,11 +13,9 @@ import javax.inject.Inject /** The presenter for [AudioLanguageFragment]. */ class AudioLanguageFragmentPresenter @Inject constructor( private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider + private val languageSelectionViewModel: LanguageSelectionViewModel ) { - private lateinit var prefSummaryValue: String - private lateinit var languageSelectionViewModel: LanguageSelectionViewModel fun handleOnCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -30,7 +27,6 @@ class AudioLanguageFragmentPresenter @Inject constructor( container, /* attachToRoot= */ false ) - languageSelectionViewModel = getLanguageSelectionViewModel() binding.viewModel = languageSelectionViewModel prefSummaryValue = prefValue languageSelectionViewModel.selectedLanguage.value = prefSummaryValue @@ -76,8 +72,4 @@ class AudioLanguageFragmentPresenter @Inject constructor( languageSelectionViewModel.selectedLanguage.value = selectedLanguage updateAudioLanguage(selectedLanguage) } - - private fun getLanguageSelectionViewModel(): LanguageSelectionViewModel { - return viewModelProvider.getForFragment(fragment, LanguageSelectionViewModel::class.java) - } } From 29e9fe10562370e5764286806ba4c26a3e0b197b Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 2 Feb 2021 22:51:29 +0530 Subject: [PATCH 26/27] Using lifecycle owner to update the radio button --- .../app/options/AppLanguageFragmentPresenter.kt | 3 ++- .../app/options/AudioLanguageFragmentPresenter.kt | 1 + .../android/app/options/LanguageItemViewModel.kt | 11 ++++------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 9b8d382f758..98888f8bd5c 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -52,9 +52,10 @@ class AppLanguageFragmentPresenter @Inject constructor( private fun createRecyclerViewAdapter(): BindableAdapter { return BindableAdapter.SingleTypeBuilder .newBuilder() + .setLifecycleOwner(fragment) .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = LanguageItemsBinding::setViewModel + setViewModel = LanguageItemsBinding::setViewModel, ).build() } diff --git a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt index 2166fee1312..f20c27a8b71 100644 --- a/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AudioLanguageFragmentPresenter.kt @@ -52,6 +52,7 @@ class AudioLanguageFragmentPresenter @Inject constructor( private fun createRecyclerViewAdapter(): BindableAdapter { return BindableAdapter.SingleTypeBuilder .newBuilder() + .setLifecycleOwner(fragment) .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, setViewModel = LanguageItemsBinding::setViewModel diff --git a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt index 6767bf8a5cc..05fabe0cfe2 100644 --- a/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/options/LanguageItemViewModel.kt @@ -1,7 +1,7 @@ package org.oppia.android.app.options -import androidx.databinding.ObservableBoolean import androidx.lifecycle.LiveData +import androidx.lifecycle.Transformations import org.oppia.android.app.viewmodel.ObservableViewModel /** @@ -10,13 +10,10 @@ import org.oppia.android.app.viewmodel.ObservableViewModel */ class LanguageItemViewModel( val language: String, - selectedLanguage: LiveData, + private val selectedLanguage: LiveData, val languageRadioButtonListener: LanguageRadioButtonListener ) : ObservableViewModel() { - val isLanguageSelected = ObservableBoolean() - init { - selectedLanguage.observeForever { - isLanguageSelected.set(it == language) - } + val isLanguageSelected: LiveData by lazy { + Transformations.map(selectedLanguage) { it == language } } } From 09809a2dacf20703de2effb31300bcc00ac1a673 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 2 Feb 2021 22:52:07 +0530 Subject: [PATCH 27/27] Nit fix --- .../oppia/android/app/options/AppLanguageFragmentPresenter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt index 98888f8bd5c..a8ea5580504 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragmentPresenter.kt @@ -55,7 +55,7 @@ class AppLanguageFragmentPresenter @Inject constructor( .setLifecycleOwner(fragment) .registerViewDataBinderWithSameModelType( inflateDataBinding = LanguageItemsBinding::inflate, - setViewModel = LanguageItemsBinding::setViewModel, + setViewModel = LanguageItemsBinding::setViewModel ).build() }