From 7494ec14dac327a41e6da5ef3fa9e6cd1398b1fe Mon Sep 17 00:00:00 2001 From: Adrian Kuta Date: Tue, 28 Jan 2020 17:53:19 +0100 Subject: [PATCH] Sample with README.md --- README.md | 9 +++-- app/build.gradle | 2 +- .../github/adriankuta/ExpandableAdapter.kt | 39 ++++++++++++------- app/src/main/res/layout/item_level_1.xml | 25 +++++++----- app/src/main/res/layout/item_level_2.xml | 35 +++++++---------- app/src/main/res/layout/item_level_3.xml | 37 ++++-------------- 6 files changed, 67 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 15070e9..0fe570b 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,11 @@ [![License](https://img.shields.io/github/license/AdrianKuta/Expandable-RecyclerView?style=plastic)](https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/LICENSE) [![CircleCI](https://img.shields.io/circleci/build/github/AdrianKuta/Expandable-RecyclerView/master?label=CircleCI&style=plastic&logo=circleci)](https://circleci.com/gh/AdrianKuta/Expandable-RecyclerView) -Library is currently during implementation! It is **not** ready to use yet :/ + -Final version will be released soon. +This RecyclerViewAdapter use Tree(Data Structure) to keep all objects. +## Download -![Release date](https://img.shields.io/date/1580493319?label=Expected%20release&style=for-the-badge) + implementation "com.github.adriankuta:expandable-recyclerView:$latest_versions" + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 8d17d4f..b09b45e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.github.adriankuta:expandable-recyclerView:0.0.1-beta01' + implementation 'com.github.adriankuta:expandable-recyclerView:0.0.1-beta02' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/src/main/java/com/github/adriankuta/ExpandableAdapter.kt b/app/src/main/java/com/github/adriankuta/ExpandableAdapter.kt index 9cae40c..82f2ff0 100644 --- a/app/src/main/java/com/github/adriankuta/ExpandableAdapter.kt +++ b/app/src/main/java/com/github/adriankuta/ExpandableAdapter.kt @@ -1,6 +1,5 @@ package com.github.adriankuta -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -38,39 +37,49 @@ class ExpandableAdapter : treeNode: ExpandableTreeNode, nestLevel: Int ) { - holder.bind(treeNode, nestLevel) + holder.bind(treeNode) { + toggleGroup(it) + } } - sealed class ExpandableViewHolder(val itemView: View) : RecyclerView.ViewHolder(itemView) { + sealed class ExpandableViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { class Level1(private val binding: ItemLevel1Binding) : ExpandableViewHolder(binding.root) { - override fun bind(node: ExpandableTreeNode, nestLevel: Int) { + override fun bind( + node: ExpandableTreeNode, + onClickListener: ((ExpandableTreeNode) -> Unit)? + ) { binding.node = node + binding.root.setOnClickListener { onClickListener?.invoke(node) } } } class Level2(private val binding: ItemLevel2Binding) : ExpandableViewHolder(binding.root) { - override fun bind(node: ExpandableTreeNode, nestLevel: Int) { + override fun bind( + node: ExpandableTreeNode, + onClickListener: ((ExpandableTreeNode) -> Unit)? + ) { binding.node = node - binding.isLastItem = isLastItem(node) + binding.root.setOnClickListener { onClickListener?.invoke(node) } } } class Level3(private val binding: ItemLevel3Binding) : ExpandableViewHolder(binding.root) { - override fun bind(node: ExpandableTreeNode, nestLevel: Int) { + override fun bind( + node: ExpandableTreeNode, + onClickListener: ((ExpandableTreeNode) -> Unit)? + ) { binding.node = node - binding.isLastItem = isLastItem(node) + binding.root.setOnClickListener { onClickListener?.invoke(node) } } } - abstract fun bind(node: ExpandableTreeNode, nestLevel: Int) - fun isLastItem(node: ExpandableTreeNode): Boolean { - val parent = node.parent ?: throw IllegalArgumentException("This node hasn't parent") - val childrenSize = parent.children.size - Log.d("DEBUG_TAG", node.value) - return parent.children[childrenSize - 1] == node - } + abstract fun bind( + node: ExpandableTreeNode, + onClickListener: ((ExpandableTreeNode) -> Unit)? = null + ) + } private fun ViewGroup.inflateLevel1(): ItemLevel1Binding { diff --git a/app/src/main/res/layout/item_level_1.xml b/app/src/main/res/layout/item_level_1.xml index 1f76dca..0941bfa 100644 --- a/app/src/main/res/layout/item_level_1.xml +++ b/app/src/main/res/layout/item_level_1.xml @@ -1,38 +1,43 @@ + + - + + + android:layout_height="wrap_content"> + app:layout_constraintTop_toTopOf="@id/textView" + tools:src="@drawable/ic_expand_less_black_24dp" /> + app:layout_constraintTop_toTopOf="parent" + tools:text="@tools:sample/full_names" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_level_2.xml b/app/src/main/res/layout/item_level_2.xml index 2f3c1c6..e093466 100644 --- a/app/src/main/res/layout/item_level_2.xml +++ b/app/src/main/res/layout/item_level_2.xml @@ -2,13 +2,11 @@ - - + + - - + android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" + app:layout_constraintBottom_toBottomOf="@id/textView" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/textView" + tools:src="@drawable/ic_expand_less_black_24dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_level_3.xml b/app/src/main/res/layout/item_level_3.xml index 0a222a0..cc2e3ae 100644 --- a/app/src/main/res/layout/item_level_3.xml +++ b/app/src/main/res/layout/item_level_3.xml @@ -2,11 +2,6 @@ - - - @@ -20,41 +15,25 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - -