mirror of
				https://github.com/AdrianKuta/Expandable-RecyclerView.git
				synced 2025-10-31 08:53:41 +01:00 
			
		
		
		
	Sample with README.md
This commit is contained in:
		| @@ -4,8 +4,11 @@ | |||||||
| [](https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/LICENSE) | [](https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/LICENSE) | ||||||
| [](https://circleci.com/gh/AdrianKuta/Expandable-RecyclerView) | [](https://circleci.com/gh/AdrianKuta/Expandable-RecyclerView) | ||||||
|  |  | ||||||
| Library is currently during implementation! It is **not** ready to use yet :/ | <img src="https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/Demo.gif" width="720" /> | ||||||
|  |  | ||||||
|  | This RecyclerViewAdapter use Tree(Data Structure) to keep all objects. | ||||||
|  | ## Download | ||||||
|  |  | ||||||
|  |     implementation "com.github.adriankuta:expandable-recyclerView:$latest_versions" | ||||||
|      |      | ||||||
| Final version will be released soon. |  | ||||||
|     |     | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,7 +32,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-beta01' |     implementation 'com.github.adriankuta:expandable-recyclerView:0.0.1-beta02' | ||||||
|     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' | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| package com.github.adriankuta | package com.github.adriankuta | ||||||
|  |  | ||||||
| import android.util.Log |  | ||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| @@ -38,39 +37,49 @@ class ExpandableAdapter : | |||||||
|         treeNode: ExpandableTreeNode<String>, |         treeNode: ExpandableTreeNode<String>, | ||||||
|         nestLevel: Int |         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) { |         class Level1(private val binding: ItemLevel1Binding) : ExpandableViewHolder(binding.root) { | ||||||
|             override fun bind(node: ExpandableTreeNode<String>, nestLevel: Int) { |             override fun bind( | ||||||
|  |                 node: ExpandableTreeNode<String>, | ||||||
|  |                 onClickListener: ((ExpandableTreeNode<String>) -> Unit)? | ||||||
|  |             ) { | ||||||
|                 binding.node = node |                 binding.node = node | ||||||
|  |                 binding.root.setOnClickListener { onClickListener?.invoke(node) } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         class Level2(private val binding: ItemLevel2Binding) : ExpandableViewHolder(binding.root) { |         class Level2(private val binding: ItemLevel2Binding) : ExpandableViewHolder(binding.root) { | ||||||
|             override fun bind(node: ExpandableTreeNode<String>, nestLevel: Int) { |             override fun bind( | ||||||
|  |                 node: ExpandableTreeNode<String>, | ||||||
|  |                 onClickListener: ((ExpandableTreeNode<String>) -> Unit)? | ||||||
|  |             ) { | ||||||
|                 binding.node = node |                 binding.node = node | ||||||
|                 binding.isLastItem = isLastItem(node) |                 binding.root.setOnClickListener { onClickListener?.invoke(node) } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         class Level3(private val binding: ItemLevel3Binding) : ExpandableViewHolder(binding.root) { |         class Level3(private val binding: ItemLevel3Binding) : ExpandableViewHolder(binding.root) { | ||||||
|             override fun bind(node: ExpandableTreeNode<String>, nestLevel: Int) { |             override fun bind( | ||||||
|  |                 node: ExpandableTreeNode<String>, | ||||||
|  |                 onClickListener: ((ExpandableTreeNode<String>) -> Unit)? | ||||||
|  |             ) { | ||||||
|                 binding.node = node |                 binding.node = node | ||||||
|                 binding.isLastItem = isLastItem(node) |                 binding.root.setOnClickListener { onClickListener?.invoke(node) } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         abstract fun bind(node: ExpandableTreeNode<String>, nestLevel: Int) |  | ||||||
|  |  | ||||||
|         fun isLastItem(node: ExpandableTreeNode<String>): Boolean { |         abstract fun bind( | ||||||
|             val parent = node.parent ?: throw IllegalArgumentException("This node hasn't parent") |             node: ExpandableTreeNode<String>, | ||||||
|             val childrenSize = parent.children.size |             onClickListener: ((ExpandableTreeNode<String>) -> Unit)? = null | ||||||
|             Log.d("DEBUG_TAG", node.value) |         ) | ||||||
|             return parent.children[childrenSize - 1] == node |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun ViewGroup.inflateLevel1(): ItemLevel1Binding { |     private fun ViewGroup.inflateLevel1(): ItemLevel1Binding { | ||||||
|   | |||||||
| @@ -1,38 +1,43 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <layout> | <layout> | ||||||
|  |  | ||||||
|     <data> |     <data> | ||||||
|  |  | ||||||
|         <variable |         <variable | ||||||
|             name="node" |             name="node" | ||||||
|             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> |             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> | ||||||
|         <import type="android.view.View"/> |  | ||||||
|  |         <import type="android.view.View" /> | ||||||
|     </data> |     </data> | ||||||
|  |  | ||||||
|     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|         xmlns:app="http://schemas.android.com/apk/res-auto" |         xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |         xmlns:tools="http://schemas.android.com/tools" | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="wrap_content" |         android:layout_height="wrap_content"> | ||||||
|         xmlns:tools="http://schemas.android.com/tools"> |  | ||||||
|  |  | ||||||
|         <ImageView |         <ImageView | ||||||
|             android:id="@+id/expand_icon" |             android:id="@+id/expand_icon" | ||||||
|             android:layout_width="48dp" |             android:layout_width="24dp" | ||||||
|             android:layout_height="48dp" |             android:layout_height="0dp" | ||||||
|             android:scaleType="centerInside" |             android:scaleType="centerInside" | ||||||
|             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" |  | ||||||
|             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" |             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" | ||||||
|  |             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" | ||||||
|  |             app:layout_constraintBottom_toBottomOf="@id/textView" | ||||||
|             app:layout_constraintStart_toStartOf="parent" |             app:layout_constraintStart_toStartOf="parent" | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |             app:layout_constraintTop_toTopOf="@id/textView" | ||||||
|  |             tools:src="@drawable/ic_expand_less_black_24dp" /> | ||||||
|  |  | ||||||
|         <TextView |         <TextView | ||||||
|             android:id="@+id/textView" |             android:id="@+id/textView" | ||||||
|             android:layout_width="0dp" |             android:layout_width="0dp" | ||||||
|             android:layout_height="wrap_content" |             android:layout_height="wrap_content" | ||||||
|             android:layout_marginStart="8dp" |             android:padding="8dp" | ||||||
|             android:text="@{node.value}" |             android:text="@{node.value}" | ||||||
|             tools:text="@tools:sample/full_names" |  | ||||||
|             app:layout_constraintBottom_toBottomOf="parent" |             app:layout_constraintBottom_toBottomOf="parent" | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |             app:layout_constraintEnd_toEndOf="parent" | ||||||
|             app:layout_constraintStart_toEndOf="@id/expand_icon" |             app:layout_constraintStart_toEndOf="@id/expand_icon" | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |             app:layout_constraintTop_toTopOf="parent" | ||||||
|  |             tools:text="@tools:sample/full_names" /> | ||||||
|     </androidx.constraintlayout.widget.ConstraintLayout> |     </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
| </layout> | </layout> | ||||||
| @@ -2,13 +2,11 @@ | |||||||
| <layout> | <layout> | ||||||
|  |  | ||||||
|     <data> |     <data> | ||||||
|         <variable |  | ||||||
|             name="isLastItem" |  | ||||||
|             type="Boolean" /> |  | ||||||
|         <variable |         <variable | ||||||
|             name="node" |             name="node" | ||||||
|             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> |             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> | ||||||
|         <import type="android.view.View"/> |  | ||||||
|  |         <import type="android.view.View" /> | ||||||
|     </data> |     </data> | ||||||
|  |  | ||||||
|     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
| @@ -17,37 +15,30 @@ | |||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="wrap_content"> |         android:layout_height="wrap_content"> | ||||||
|  |  | ||||||
|         <ImageView |  | ||||||
|             android:id="@+id/tree_icon" |  | ||||||
|             android:layout_width="48dp" |  | ||||||
|             android:layout_height="48dp" |  | ||||||
|             android:src="@{isLastItem ? @drawable/ic_last_element : @drawable/ic_middle_element}" |  | ||||||
|             tools:src="@drawable/ic_last_element" |  | ||||||
|             android:tint="@color/colorAccent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
|  |  | ||||||
|         <ImageView |         <ImageView | ||||||
|             android:id="@+id/expand_icon" |             android:id="@+id/expand_icon" | ||||||
|             android:layout_width="48dp" |             android:layout_width="24dp" | ||||||
|             android:layout_height="48dp" |             android:layout_height="0dp" | ||||||
|  |             android:layout_marginStart="24dp" | ||||||
|             android:scaleType="centerInside" |             android:scaleType="centerInside" | ||||||
|             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" |  | ||||||
|             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" |             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" | ||||||
|             tools:src="@drawable/ic_expand_less_black_24dp" |             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" | ||||||
|             app:layout_constraintStart_toEndOf="@id/tree_icon" |             app:layout_constraintBottom_toBottomOf="@id/textView" | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |             app:layout_constraintStart_toStartOf="parent" | ||||||
|  |             app:layout_constraintTop_toTopOf="@id/textView" | ||||||
|  |             tools:src="@drawable/ic_expand_less_black_24dp" /> | ||||||
|  |  | ||||||
|         <TextView |         <TextView | ||||||
|             android:id="@+id/textView" |             android:id="@+id/textView" | ||||||
|             android:layout_width="0dp" |             android:layout_width="0dp" | ||||||
|             android:text="@{node.value}" |  | ||||||
|             android:layout_height="wrap_content" |             android:layout_height="wrap_content" | ||||||
|             android:layout_marginStart="8dp" |             android:padding="8dp" | ||||||
|  |             android:text="@{node.value}" | ||||||
|             app:layout_constraintBottom_toBottomOf="parent" |             app:layout_constraintBottom_toBottomOf="parent" | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |             app:layout_constraintEnd_toEndOf="parent" | ||||||
|             app:layout_constraintStart_toEndOf="@id/expand_icon" |             app:layout_constraintStart_toEndOf="@id/expand_icon" | ||||||
|             app:layout_constraintTop_toTopOf="parent" |             app:layout_constraintTop_toTopOf="parent" | ||||||
|  |             app:layout_goneMarginStart="48dp" | ||||||
|             tools:text="@tools:sample/full_names" /> |             tools:text="@tools:sample/full_names" /> | ||||||
|     </androidx.constraintlayout.widget.ConstraintLayout> |     </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
| </layout> | </layout> | ||||||
| @@ -2,11 +2,6 @@ | |||||||
| <layout> | <layout> | ||||||
|  |  | ||||||
|     <data> |     <data> | ||||||
|  |  | ||||||
|         <variable |  | ||||||
|             name="isLastItem" |  | ||||||
|             type="Boolean" /> |  | ||||||
|  |  | ||||||
|         <variable |         <variable | ||||||
|             name="node" |             name="node" | ||||||
|             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> |             type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" /> | ||||||
| @@ -20,41 +15,25 @@ | |||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="wrap_content"> |         android:layout_height="wrap_content"> | ||||||
|  |  | ||||||
|         <ImageView |  | ||||||
|             android:id="@+id/line" |  | ||||||
|             android:layout_width="48dp" |  | ||||||
|             android:layout_height="48dp" |  | ||||||
|             android:src="@drawable/ic_vertical_line" |  | ||||||
|             android:tint="@color/colorAccent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
|  |  | ||||||
|         <ImageView |  | ||||||
|             android:id="@+id/tree_icon" |  | ||||||
|             android:layout_width="48dp" |  | ||||||
|             android:layout_height="48dp" |  | ||||||
|             android:src="@{isLastItem ? @drawable/ic_last_element : @drawable/ic_middle_element}" |  | ||||||
|             android:tint="@color/colorAccent" |  | ||||||
|             app:layout_constraintStart_toEndOf="@id/line" |  | ||||||
|             app:layout_constraintTop_toTopOf="parent" |  | ||||||
|             tools:src="@drawable/ic_last_element" /> |  | ||||||
|  |  | ||||||
|         <ImageView |         <ImageView | ||||||
|             android:id="@+id/expand_icon" |             android:id="@+id/expand_icon" | ||||||
|             android:layout_width="48dp" |             android:layout_width="24dp" | ||||||
|             android:layout_height="48dp" |             android:layout_height="0dp" | ||||||
|  |             android:layout_marginStart="48dp" | ||||||
|             android:scaleType="centerInside" |             android:scaleType="centerInside" | ||||||
|             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" |             android:src="@{node.expanded ? @drawable/ic_expand_more_black_24dp : @drawable/ic_expand_less_black_24dp}" | ||||||
|             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" |             android:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}" | ||||||
|             app:layout_constraintStart_toEndOf="@id/tree_icon" |             app:layout_constraintBottom_toBottomOf="@id/textView" | ||||||
|             app:layout_constraintTop_toTopOf="parent" |             app:layout_constraintStart_toStartOf="parent" | ||||||
|  |             app:layout_constraintTop_toTopOf="@id/textView" | ||||||
|             tools:src="@drawable/ic_expand_less_black_24dp" /> |             tools:src="@drawable/ic_expand_less_black_24dp" /> | ||||||
|  |  | ||||||
|         <TextView |         <TextView | ||||||
|             android:id="@+id/textView" |             android:id="@+id/textView" | ||||||
|             android:layout_width="0dp" |             android:layout_width="0dp" | ||||||
|             android:layout_height="wrap_content" |             android:layout_height="wrap_content" | ||||||
|             android:layout_marginStart="8dp" |             android:padding="8dp" | ||||||
|  |             app:layout_goneMarginStart="96dp" | ||||||
|             android:text="@{node.value}" |             android:text="@{node.value}" | ||||||
|             app:layout_constraintBottom_toBottomOf="parent" |             app:layout_constraintBottom_toBottomOf="parent" | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |             app:layout_constraintEnd_toEndOf="parent" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user