Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #632: Replace LanguageSelectionAdapter with BindableAdapter #2392

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5cf09d0
issue 2098
FareesHussain Nov 11, 2020
d3696f2
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Dec 3, 2020
f3483f8
test commit
FareesHussain Dec 31, 2020
e970871
Merge branch 'develop' of https://github.com/FareesHussain/oppia-andr…
FareesHussain Dec 31, 2020
2110cdf
Update gradle.xml
FareesHussain Dec 31, 2020
e09a602
Update misc.xml
FareesHussain Dec 31, 2020
38fb39f
Fix gradle.xml
FareesHussain Jan 1, 2021
4c4d22e
Merge branch 'develop' of https://github.com/FareesHussain/oppia-andr…
FareesHussain Jan 1, 2021
1abdd4c
Merge branch 'develop' of https://github.com/FareesHussain/oppia-andr…
FareesHussain Jan 1, 2021
7c8bdae
initial inmplementation
FareesHussain Jan 4, 2021
cc86c6a
Ready for Review
FareesHussain Jan 5, 2021
7fbe08a
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jan 5, 2021
409ccb3
Updated BAZEL with new viewmodels
FareesHussain Jan 5, 2021
e73d04d
Reformatting code and making changes in other configuration
FareesHussain Jan 5, 2021
e9a7532
Fixed the Tablet issue
FareesHussain Jan 6, 2021
8da06e9
Adding Requested changes
FareesHussain Jan 8, 2021
f658450
Resolving requested changes
FareesHussain Jan 11, 2021
2d0da65
NIT fix
FareesHussain Jan 11, 2021
6199e2d
Resolving requested changes
FareesHussain Jan 12, 2021
7b532cd
NIT fix
FareesHussain Jan 12, 2021
678c846
NIT fix
FareesHussain Jan 12, 2021
48ff579
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jan 12, 2021
93ad8da
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jan 20, 2021
173255a
update fun name
FareesHussain Jan 20, 2021
60e22ea
using databinding for audio language selection
FareesHussain Jan 20, 2021
d65bb2f
using databinding for app language selection
FareesHussain Jan 20, 2021
d4bf82e
ktlint fix
FareesHussain Jan 20, 2021
a2ab17c
Fix bazel check
FareesHussain Jan 20, 2021
ea70b99
Resolving Requested changes
FareesHussain Jan 21, 2021
c7481dd
Nit fix
FareesHussain Jan 21, 2021
8a6ac34
Radio Button fix
FareesHussain Jan 21, 2021
d6d0185
NIT fix
FareesHussain Jan 21, 2021
08f57c1
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 2, 2021
29e9fe1
Using lifecycle owner to update the radio button
FareesHussain Feb 2, 2021
09809a2
Nit fix
FareesHussain Feb 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<LanguageSelectionViewModel>
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
) {

private lateinit var prefSummaryValue: String
private lateinit var languageSelectionAdapter: LanguageSelectionAdapter
Expand All @@ -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 {
Expand All @@ -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()
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
return binding.root
}

Expand Down Expand Up @@ -69,4 +79,42 @@ class AudioLanguageFragmentPresenter @Inject constructor(private val fragment: F
languageSelectionAdapter.setLanguageList(languageList)
languageSelectionAdapter.setDefaultLanguageSelected(prefSummaryValue = prefSummaryValue)
}
rt4914 marked this conversation as resolved.
Show resolved Hide resolved

private fun createRecyclerViewAdapter(): BindableAdapter<LanguageItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<LanguageItemViewModel, ViewType> { viewModel ->
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
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
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
) {
binding.viewModel = model
// binding.isChecked = selectedSubtopicIdList.contains(model.subtopic.subtopicId)
// binding.subtopicCheckBox.setOnCheckedChangeListener { _, isChecked ->
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
// 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)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.oppia.android.app.options

import org.oppia.android.app.viewmodel.ObservableViewModel

class LanguageItemViewModel(val language: String): ObservableViewModel()
Original file line number Diff line number Diff line change
@@ -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(
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
val activity: AppCompatActivity
) :ObservableViewModel() {

var audioLanguagesList = listOf<LanguageItemViewModel>(
LanguageItemViewModel("No Audio"),
LanguageItemViewModel("English"),
LanguageItemViewModel("French"),
LanguageItemViewModel("Hindi"),
LanguageItemViewModel("Chinese")
)


val recyclerViewAudioList: List<LanguageItemViewModel> by lazy {
audioLanguagesList
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/audio_language_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
<variable
name="viewModel"
type="org.oppia.android.app.options.LanguageSelectionViewModel"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/layout/language_items.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<variable
name="languageString"
type="CharSequence" />
<variable
name="viewModel"
type="org.oppia.android.app.options.LanguageItemViewModel" />
</data>

<LinearLayout
Expand All @@ -24,6 +26,7 @@
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:clickable="false"
android:checked="true"
android:minWidth="20dp"
android:minHeight="20dp" />

Expand All @@ -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"
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
android:textSize="16sp" />
</LinearLayout>
Expand Down