Skip to content

Instantly share code, notes, and snippets.

@worker8
Created October 20, 2018 08:09
Show Gist options
  • Save worker8/0f7d9bc5b7ebb2b6380957c99388835e to your computer and use it in GitHub Desktop.
Save worker8/0f7d9bc5b7ebb2b6380957c99388835e to your computer and use it in GitHub Desktop.
class RandomAdapter(val dataArray: List) : AccordionAdapter {
override fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder {
return TitleViewHolder.create(parent)
}
override fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder {
return ContentViewHolder.create(parent)
}
override fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: AccordionAdapter.ArrowDirection) {
val dataModel = dataArray[position]
(viewHolder as TitleViewHolder).itemView.apply {
titleTextView.text = dataModel.title
when (arrowDirection) {
AccordionAdapter.ArrowDirection.UP -> titleArrowIcon.text = "▲"
AccordionAdapter.ArrowDirection.DOWN -> titleArrowIcon.text = "▼"
AccordionAdapter.ArrowDirection.NONE -> titleArrowIcon.text = ""
}
}
}
override fun onBindViewForContent(viewHolder: AccordionView.ViewHolder, position: Int) {
val dataModel = dataArray[position]
(viewHolder as ContentViewHolder).itemView.apply {
contentTextView.text = dataModel.desc
}
}
override fun getItemCount() = dataArray.size
}
class TitleViewHolder(itemView: View) : AccordionView.ViewHolder(itemView) {
companion object {
fun create(parent: ViewGroup): TitleViewHolder {
return TitleViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_title, parent, false))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment