From 8cdfb3399a0f35f3c05f89643f3cbd8edf5e41ee Mon Sep 17 00:00:00 2001 From: Rajat Talesra Date: Thu, 3 Oct 2019 15:20:32 +0530 Subject: [PATCH 01/28] All xml files for topic-train except layout folder --- app/build.gradle | 1 + .../state_button_primary_background.xml | 9 +++++++ .../state_button_transparent_background.xml | 7 +++++ app/src/main/res/values/colors.xml | 4 +++ app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/values/styles.xml | 27 +++++++++++++++++++ 7 files changed, 52 insertions(+) create mode 100644 app/src/main/res/drawable/state_button_primary_background.xml create mode 100644 app/src/main/res/drawable/state_button_transparent_background.xml diff --git a/app/build.gradle b/app/build.gradle index 22479f62151..5fc0e640fc5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,6 +61,7 @@ dependencies { 'androidx.constraintlayout:constraintlayout:1.1.3', 'androidx.core:core-ktx:1.0.2', 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha03', + 'androidx.recyclerview:recyclerview:1.0.0', 'com.google.dagger:dagger:2.24', "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version", "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1", diff --git a/app/src/main/res/drawable/state_button_primary_background.xml b/app/src/main/res/drawable/state_button_primary_background.xml new file mode 100644 index 00000000000..c198754b5a8 --- /dev/null +++ b/app/src/main/res/drawable/state_button_primary_background.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/main/res/drawable/state_button_transparent_background.xml b/app/src/main/res/drawable/state_button_transparent_background.xml new file mode 100644 index 00000000000..96aa2dbe473 --- /dev/null +++ b/app/src/main/res/drawable/state_button_transparent_background.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1f75fbc6809..75cde50851b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -9,8 +9,12 @@ #26A69A #2D4A9D + #333333 + #666666 #FFFFFF @color/oppiaDarkBlue + + #56000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d9c61be15b7..c96810de821 100755 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -6,4 +6,5 @@ 8dp 32dp 24dp + 4dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 19d07509e27..de2c8830744 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,4 +12,7 @@ Currently on Cellular Data Streaming audio may use a lot of cellular data. Don\'t show this message again + Master These Skills + Select or unselect skills that you want to practice + Start diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f5695ca647d..c92ae2e725e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -43,4 +43,31 @@ @anim/slide_up @anim/slide_down + + + + + + From afd819626417fbffec8d0115703859535cbe0ca0 Mon Sep 17 00:00:00 2001 From: Rajat Talesra Date: Thu, 3 Oct 2019 15:24:56 +0530 Subject: [PATCH 02/28] Skill item related files --- .../oppia/app/topic/train/SkillInterface.kt | 9 ++++ .../app/topic/train/SkillSelectionAdapter.kt | 52 +++++++++++++++++++ .../res/layout/topic_train_skill_view.xml | 28 ++++++++++ 3 files changed, 89 insertions(+) create mode 100644 app/src/main/java/org/oppia/app/topic/train/SkillInterface.kt create mode 100644 app/src/main/java/org/oppia/app/topic/train/SkillSelectionAdapter.kt create mode 100644 app/src/main/res/layout/topic_train_skill_view.xml diff --git a/app/src/main/java/org/oppia/app/topic/train/SkillInterface.kt b/app/src/main/java/org/oppia/app/topic/train/SkillInterface.kt new file mode 100644 index 00000000000..113ed35f4bc --- /dev/null +++ b/app/src/main/java/org/oppia/app/topic/train/SkillInterface.kt @@ -0,0 +1,9 @@ +package org.oppia.app.topic.train + +/** Interface to update the selectedSkillList in [TopicTrainFragmentPresenter]. */ +interface SkillInterface { + /** This skill will get added to selectedSkillList in [TopicTrainFragmentPresenter] */ + fun skillSelected(skill: String) + /** This skill will get removed from selectedSkillList in [TopicTrainFragmentPresenter] */ + fun skillUnselected(skill: String) +} diff --git a/app/src/main/java/org/oppia/app/topic/train/SkillSelectionAdapter.kt b/app/src/main/java/org/oppia/app/topic/train/SkillSelectionAdapter.kt new file mode 100644 index 00000000000..5ddeb7d9f9f --- /dev/null +++ b/app/src/main/java/org/oppia/app/topic/train/SkillSelectionAdapter.kt @@ -0,0 +1,52 @@ +package org.oppia.app.topic.train; + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.databinding.ViewDataBinding +import androidx.databinding.library.baseAdapters.BR +import androidx.recyclerview.widget.RecyclerView +import kotlinx.android.synthetic.main.topic_train_skill_view.view.* +import org.oppia.app.R +import org.oppia.app.databinding.TopicTrainSkillViewBinding + +/** Adapter to bind skills to [RecyclerView] inside [TopicTrainFragment]. **/ +class SkillSelectionAdapter( + private val skillList: List, + private val skillInterface: SkillInterface +) : RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val inflater = LayoutInflater.from(parent.context) + val binding = + DataBindingUtil.inflate( + inflater, + R.layout.topic_train_skill_view, + parent, + false + ) + return SkillViewHolder(binding) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + (holder as SkillViewHolder).bind(skillList[position], position) + } + + override fun getItemCount(): Int { + return skillList.size + } + + private inner class SkillViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) { + internal fun bind(rawString: String?, position: Int) { + binding.setVariable(BR.skill, rawString) + binding.root.skill_check_box.setOnCheckedChangeListener { buttonView, isChecked -> + val skill = skillList[position] + if (isChecked) { + skillInterface.skillSelected(skill) + } else { + skillInterface.skillUnselected(skill) + } + } + } + } +} diff --git a/app/src/main/res/layout/topic_train_skill_view.xml b/app/src/main/res/layout/topic_train_skill_view.xml new file mode 100644 index 00000000000..a8ac2d9c8cb --- /dev/null +++ b/app/src/main/res/layout/topic_train_skill_view.xml @@ -0,0 +1,28 @@ + + + + + + + + + From 87977abdcc98f35dfed933c7efde1f7e9b03d9bc Mon Sep 17 00:00:00 2001 From: Rajat Talesra Date: Thu, 3 Oct 2019 15:28:18 +0530 Subject: [PATCH 03/28] TopicTrainFragment implementation --- .../app/topic/train/TopicTrainFragment.kt | 5 ++ .../train/TopicTrainFragmentPresenter.kt | 45 +++++++++++++- .../app/topic/train/TopicTrainViewModel.kt | 16 +++++ .../main/res/layout/topic_train_fragment.xml | 59 +++++++++++++++++-- 4 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/org/oppia/app/topic/train/TopicTrainViewModel.kt diff --git a/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragment.kt b/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragment.kt index 4d1a5062f9e..598852a3d56 100644 --- a/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragment.kt +++ b/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragment.kt @@ -21,4 +21,9 @@ class TopicTrainFragment : InjectableFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return topicTrainFragmentPresenter.handleCreateView(inflater, container) } + + fun submitButtonClicked(){ + // List of selected skills when submit button is clicked. + val skillList = topicTrainFragmentPresenter.getSelectedSkillList() + } } diff --git a/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragmentPresenter.kt b/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragmentPresenter.kt index af436a7e294..df846f1c27d 100644 --- a/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/topic/train/TopicTrainFragmentPresenter.kt @@ -4,20 +4,61 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager import org.oppia.app.databinding.TopicTrainFragmentBinding import org.oppia.app.fragment.FragmentScope +import org.oppia.app.viewmodel.ViewModelProvider import javax.inject.Inject /** The presenter for [TopicTrainFragment]. */ @FragmentScope class TopicTrainFragmentPresenter @Inject constructor( - private val fragment: Fragment -) { + private val fragment: Fragment, + private val viewModelProvider: ViewModelProvider +) : SkillInterface { + private val selectedSkillList = ArrayList() + fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { + val skillAdapter = SkillSelectionAdapter(dummySkillList(), this) + val binding = TopicTrainFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false) + binding.skillRecyclerView.apply { + adapter = skillAdapter + layoutManager = LinearLayoutManager(context) + } binding.let { + it.viewModel = getTopicTrainViewModel() it.lifecycleOwner = fragment } return binding.root } + + private fun getTopicTrainViewModel(): TopicTrainViewModel { + return viewModelProvider.getForFragment(fragment, TopicTrainViewModel::class.java) + } + + override fun skillSelected(skill: String) { + selectedSkillList.add(skill) + getTopicTrainViewModel().selectedSkillList(selectedSkillList) + } + + override fun skillUnselected(skill: String) { + selectedSkillList.remove(skill) + getTopicTrainViewModel().selectedSkillList(selectedSkillList) + } + + private fun dummySkillList(): List { + val skillList = ArrayList() + skillList.add("Identify the Parts of a Fraction") + skillList.add("Writing Fractions") + skillList.add("Equivalent Fractions") + skillList.add("Mixed Numbers and Improper Fractions") + skillList.add("Comparing Fractions") + skillList.add("Adding and Subtracting Fractions") + skillList.add("Multiplying Fractions") + skillList.add("Dividing Fractions") + return skillList + } + + fun getSelectedSkillList() = selectedSkillList } diff --git a/app/src/main/java/org/oppia/app/topic/train/TopicTrainViewModel.kt b/app/src/main/java/org/oppia/app/topic/train/TopicTrainViewModel.kt new file mode 100644 index 00000000000..6cbbb2d31c6 --- /dev/null +++ b/app/src/main/java/org/oppia/app/topic/train/TopicTrainViewModel.kt @@ -0,0 +1,16 @@ +package org.oppia.app.topic.train + +import androidx.databinding.ObservableField +import androidx.lifecycle.ViewModel +import org.oppia.app.fragment.FragmentScope +import javax.inject.Inject + +/** [ViewModel] for showing skills in train fragment. */ +@FragmentScope +class TopicTrainViewModel @Inject constructor() : ViewModel() { + var isSubmitButtonActive = ObservableField(false) + + fun selectedSkillList(selectedSkillList: ArrayList) { + isSubmitButtonActive.set(selectedSkillList.isNotEmpty()) + } +} diff --git a/app/src/main/res/layout/topic_train_fragment.xml b/app/src/main/res/layout/topic_train_fragment.xml index e9b0824c1b7..4668220c3d9 100644 --- a/app/src/main/res/layout/topic_train_fragment.xml +++ b/app/src/main/res/layout/topic_train_fragment.xml @@ -2,17 +2,64 @@ + + + + + - + app:layout_constraintTop_toTopOf="parent"> + + + + +