Updated Sample

This commit is contained in:
Adrian Kuta 2020-01-28 20:33:11 +01:00
parent 210d96c616
commit 76aacc0c3f
3 changed files with 8 additions and 6 deletions

BIN
Demo.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

After

Width:  |  Height:  |  Size: 157 KiB

View File

@ -1,8 +1,7 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android { android {
compileSdkVersion 29 compileSdkVersion 29
@ -32,7 +31,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.github.adriankuta:expandable-recyclerView:0.0.1-beta02' implementation 'com.github.adriankuta:expandable-recyclerView:1.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

View File

@ -7,12 +7,12 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.adriankuta.databinding.ItemLevel1Binding import com.github.adriankuta.databinding.ItemLevel1Binding
import com.github.adriankuta.databinding.ItemLevel2Binding import com.github.adriankuta.databinding.ItemLevel2Binding
import com.github.adriankuta.databinding.ItemLevel3Binding import com.github.adriankuta.databinding.ItemLevel3Binding
import com.github.adriankuta.expandable_recyclerview.ExpandableRecyclerViewAdapter
import com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode import com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode
import com.github.adriankuta.expandable_recyclerview.MultilevelRecyclerViewAdapter
import com.github.adriankuta.expandable_recyclerview.expandableTree import com.github.adriankuta.expandable_recyclerview.expandableTree
class ExpandableAdapter : class ExpandableAdapter :
MultilevelRecyclerViewAdapter<String, ExpandableAdapter.ExpandableViewHolder>() { ExpandableRecyclerViewAdapter<String, ExpandableAdapter.ExpandableViewHolder>() {
private var tree: ExpandableTreeNode<String>? = null private var tree: ExpandableTreeNode<String>? = null
@ -21,7 +21,7 @@ class ExpandableAdapter :
notifyDataSetChanged() notifyDataSetChanged()
} }
override fun getTreeNodes(): ExpandableTreeNode<String> = tree ?: expandableTree("") {} override fun getTreeNodes(): ExpandableTreeNode<String> = tree ?: expandableTree("")
override fun onCreateViewHolder(parent: ViewGroup, nestLevel: Int): ExpandableViewHolder { override fun onCreateViewHolder(parent: ViewGroup, nestLevel: Int): ExpandableViewHolder {
return when (nestLevel) { return when (nestLevel) {
@ -51,6 +51,7 @@ class ExpandableAdapter :
) { ) {
binding.node = node binding.node = node
binding.root.setOnClickListener { onClickListener?.invoke(node) } binding.root.setOnClickListener { onClickListener?.invoke(node) }
binding.executePendingBindings()
} }
} }
@ -61,6 +62,7 @@ class ExpandableAdapter :
) { ) {
binding.node = node binding.node = node
binding.root.setOnClickListener { onClickListener?.invoke(node) } binding.root.setOnClickListener { onClickListener?.invoke(node) }
binding.executePendingBindings()
} }
} }
@ -71,6 +73,7 @@ class ExpandableAdapter :
) { ) {
binding.node = node binding.node = node
binding.root.setOnClickListener { onClickListener?.invoke(node) } binding.root.setOnClickListener { onClickListener?.invoke(node) }
binding.executePendingBindings()
} }
} }