mirror of
https://github.com/AdrianKuta/Expandable-RecyclerView.git
synced 2025-04-19 23:19:02 +02:00
Sample with README.md
This commit is contained in:
parent
12e70f0a6a
commit
7494ec14da
@ -4,8 +4,11 @@
|
||||
[](https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/LICENSE)
|
||||
[](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" />
|
||||
|
||||
Final version will be released soon.
|
||||
This RecyclerViewAdapter use Tree(Data Structure) to keep all objects.
|
||||
## Download
|
||||
|
||||

|
||||
implementation "com.github.adriankuta:expandable-recyclerView:$latest_versions"
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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<String>,
|
||||
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<String>, nestLevel: Int) {
|
||||
override fun bind(
|
||||
node: ExpandableTreeNode<String>,
|
||||
onClickListener: ((ExpandableTreeNode<String>) -> Unit)?
|
||||
) {
|
||||
binding.node = node
|
||||
binding.root.setOnClickListener { onClickListener?.invoke(node) }
|
||||
}
|
||||
}
|
||||
|
||||
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.isLastItem = isLastItem(node)
|
||||
binding.root.setOnClickListener { onClickListener?.invoke(node) }
|
||||
}
|
||||
}
|
||||
|
||||
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.isLastItem = isLastItem(node)
|
||||
binding.root.setOnClickListener { onClickListener?.invoke(node) }
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun bind(node: ExpandableTreeNode<String>, nestLevel: Int)
|
||||
|
||||
fun isLastItem(node: ExpandableTreeNode<String>): 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<String>,
|
||||
onClickListener: ((ExpandableTreeNode<String>) -> Unit)? = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
private fun ViewGroup.inflateLevel1(): ItemLevel1Binding {
|
||||
|
@ -1,38 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="node"
|
||||
type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" />
|
||||
<import type="android.view.View"/>
|
||||
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/expand_icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
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:visibility="@{node.children.empty ? View.GONE : View.VISIBLE}"
|
||||
app:layout_constraintBottom_toBottomOf="@id/textView"
|
||||
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
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:padding="8dp"
|
||||
android:text="@{node.value}"
|
||||
tools:text="@tools:sample/full_names"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
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>
|
||||
</layout>
|
@ -2,13 +2,11 @@
|
||||
<layout>
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="isLastItem"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="node"
|
||||
type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" />
|
||||
<import type="android.view.View"/>
|
||||
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
@ -17,37 +15,30 @@
|
||||
android:layout_width="match_parent"
|
||||
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
|
||||
android:id="@+id/expand_icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="24dp"
|
||||
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}"
|
||||
tools:src="@drawable/ic_expand_less_black_24dp"
|
||||
app:layout_constraintStart_toEndOf="@id/tree_icon"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:text="@{node.value}"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:padding="8dp"
|
||||
android:text="@{node.value}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/expand_icon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_goneMarginStart="48dp"
|
||||
tools:text="@tools:sample/full_names" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
@ -2,11 +2,6 @@
|
||||
<layout>
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="isLastItem"
|
||||
type="Boolean" />
|
||||
|
||||
<variable
|
||||
name="node"
|
||||
type="com.github.adriankuta.expandable_recyclerview.ExpandableTreeNode<String>" />
|
||||
@ -20,41 +15,25 @@
|
||||
android:layout_width="match_parent"
|
||||
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
|
||||
android:id="@+id/expand_icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="48dp"
|
||||
android:scaleType="centerInside"
|
||||
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_constraintStart_toEndOf="@id/tree_icon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:padding="8dp"
|
||||
app:layout_goneMarginStart="96dp"
|
||||
android:text="@{node.value}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user