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 #138: Topic train fragment Low-fi UI (Part 2) #202

Merged
merged 7 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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

// TODO(#172): Make use of generic data-binding-enabled RecyclerView adapter.
/** Adapter to bind skills to [RecyclerView] inside [TopicTrainFragment]. */
class SkillSelectionAdapter(
private val skillList: List<String>,
private val skillSelector: SkillSelector
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding =
DataBindingUtil.inflate<TopicTrainSkillViewBinding>(
inflater,
R.layout.topic_train_skill_view,
parent,
/* attachToParent= */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) {
skillSelector.skillSelected(skill)
} else {
skillSelector.skillUnselected(skill)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.oppia.app.topic.train

/** Interface to update the selectedSkillList in [TopicTrainFragmentPresenter]. */
interface SkillSelector {
/** 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)
}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/topic_train_skill_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="skill"
type="java.lang.String"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/skill_check_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:text="@{skill}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>