Commit 934f4830 authored by Antonia Wüst's avatar Antonia Wüst

fix #12

parent 280db5c5
Pipeline #1978 failed with stages
in 3 minutes and 16 seconds
......@@ -16,14 +16,20 @@ import de.akamu.tudarmstadt.model.Pool
import de.akamu.tudarmstadt.util.SortOrder
class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickHandler: QuestionPoolOnClickHandler)
: RecyclerView.Adapter<QuestionPoolsAdapter.QuestionPoolsViewHolder>() {
class QuestionPoolsAdapter(
var pools: ArrayList<Pool>,
var mQuestionPoolOnClickHandler: QuestionPoolOnClickHandler
) : RecyclerView.Adapter<QuestionPoolsAdapter.QuestionPoolsViewHolder>() {
private var selectedPools: ArrayList<Pool> =
pools.filter { p -> p.isSelected } as ArrayList<Pool>
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QuestionPoolsViewHolder {
val view = LayoutInflater
.from(parent.context)
.inflate(R.layout.item_question_pools, parent, false)
view.isFocusable = true
return QuestionPoolsViewHolder(view)
}
......@@ -36,9 +42,9 @@ class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickH
}
fun sort(order: SortOrder): Boolean {
return when(order) {
return when (order) {
SortOrder.ALPHABETIC -> {
pools.sortWith(compareBy{ it.name })
pools.sortWith(compareBy { it.name })
notifyDataSetChanged()
true
}
......@@ -66,7 +72,8 @@ class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickH
fun onExpandOrCollapseCard()
}
inner class QuestionPoolsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
inner class QuestionPoolsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
View.OnClickListener {
lateinit var mPool: Pool
var qpCardView: CardView? = null
......@@ -77,14 +84,14 @@ class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickH
var qpButtonExpand: ImageButton? = null
private var isExpanded: Boolean = false
private var selectedPools: ArrayList<Pool> = arrayListOf()
init {
qpCardView = itemView.findViewById(cardView_item_question_pool)
qpName = itemView.findViewById(textView_item_question_pool_name)
qpInfo = itemView.findViewById(textView_item_question_pool_expanded)
qpImage = itemView.findViewById(imageView_item_question_pool)
qpButtonAddOrRemove = itemView.findViewById(sparkButton_item_question_pool_add_or_remove)
qpButtonAddOrRemove =
itemView.findViewById(sparkButton_item_question_pool_add_or_remove)
qpButtonExpand = itemView.findViewById(imageButton_item_question_pool_expand)
qpCardView?.setOnClickListener(this)
......@@ -93,13 +100,13 @@ class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickH
qpName?.isSelected = true
selectedPools.addAll(pools)
}
override fun onClick(v: View?) {
if (v?.id == cardView_item_question_pool || v?.id == imageButton_item_question_pool_expand) {
val deg = if (qpButtonExpand?.rotation == 180f) 0f else 180f
qpButtonExpand?.animate()?.rotation(deg)?.interpolator = AccelerateDecelerateInterpolator()
qpButtonExpand?.animate()?.rotation(deg)?.interpolator =
AccelerateDecelerateInterpolator()
if (!isExpanded) {
qpInfo?.visibility = View.VISIBLE
qpInfo?.text = pools[adapterPosition].name
......@@ -116,6 +123,7 @@ class QuestionPoolsAdapter(var pools: ArrayList<Pool>, var mQuestionPoolOnClickH
mPool.isSelected = true
selectedPools.add(mPool)
mQuestionPoolOnClickHandler.onAddOrRemovePool(selectedPools)
} else {
mPool.isSelected = false
selectedPools.remove(mPool)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment