mirror of
https://github.com/AdrianKuta/Expandable-RecyclerView.git
synced 2025-04-19 23:19:02 +02:00
Adapter concept
This commit is contained in:
parent
43eadad8f6
commit
1f9152a838
86
.circleci/config.yml
Normal file
86
.circleci/config.yml
Normal file
@ -0,0 +1,86 @@
|
||||
version: 2.1
|
||||
jobs:
|
||||
build:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- run:
|
||||
name: Download Dependencies
|
||||
command: ./gradlew androidDependencies
|
||||
- save_cache:
|
||||
paths:
|
||||
- ~/.gradle
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
|
||||
tests:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- store_artifacts:
|
||||
path: app/build/reports
|
||||
destination: reports
|
||||
- run:
|
||||
name: Run Lint Test
|
||||
command: ./gradlew lint
|
||||
- run:
|
||||
name: Run Tests
|
||||
command: ./gradlew lint test
|
||||
- store_artifacts:
|
||||
path: app/build/reports
|
||||
destination: reports
|
||||
- store_test_results:
|
||||
path: app/build/test-results
|
||||
|
||||
deploy:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- run:
|
||||
name: Build Library
|
||||
command: ./gradlew :expandable-recyclerview:assembleRelease
|
||||
- run:
|
||||
name: Export key
|
||||
command: |
|
||||
mkdir treedatastructure/maven
|
||||
echo ${GPG_KEY_CONTENTS} | base64 -d --ignore-garbage > treedatastructure/maven/secret.gpg
|
||||
- run:
|
||||
name: Staging
|
||||
command: ./gradlew :expandable-recyclerview:publishReleasePublicationToSonatypeRepository
|
||||
- run:
|
||||
name: Release Library
|
||||
command: ./gradlew closeAndReleaseRepository
|
||||
|
||||
workflows:
|
||||
version: 2.1
|
||||
build-and-deploy:
|
||||
jobs:
|
||||
- build:
|
||||
filters: # required since `deploy` has tag filters AND requires `build`
|
||||
tags:
|
||||
only: /.*/
|
||||
- deploy:
|
||||
requires:
|
||||
- build
|
||||
filters:
|
||||
tags:
|
||||
only: /v[0-9]{1,3}\.[0-9]{1,3}\.?[0-9]{0,3}/
|
||||
branches:
|
||||
ignore: /.*/
|
@ -15,7 +15,7 @@ android {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "0.0.1-alpha01"
|
||||
versionName "0.0.1-alpha02"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
@ -35,7 +35,7 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation "androidx.recyclerview:recyclerview:1.1.0"
|
||||
implementation "com.github.adriankuta:tree-structure:1.1.0"
|
||||
implementation "com.github.adriankuta:tree-structure:1.2.0"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.github.adriankuta.expandable_recyclerview
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.TreeNode
|
||||
|
||||
open class ExpandableGroup<T>(value: T) : TreeNode<T>(value) {
|
||||
|
||||
private var _isExpanded = false
|
||||
val isExpanded: Boolean
|
||||
get() = _isExpanded
|
||||
|
||||
|
||||
open fun expand() {
|
||||
_isExpanded = true
|
||||
}
|
||||
|
||||
open fun collapse() {
|
||||
_isExpanded = false
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.github.adriankuta.expandable_recyclerview
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class ExpandableRecyclerView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.github.adriankuta.expandable_recyclerview
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.ChildDeclaration
|
||||
import com.github.adriankuta.datastructure.tree.TreeNode
|
||||
|
||||
class ExpandableTreeNode<T>(value: T) : TreeNode<T>(value) {
|
||||
|
||||
var expanded: Boolean = true
|
||||
set(value) {
|
||||
field = value
|
||||
children.forEach {
|
||||
(it as ExpandableTreeNode).expanded = value
|
||||
}
|
||||
}
|
||||
|
||||
override fun child(value: T, childDeclaration: ChildDeclaration<T>?) {
|
||||
val newChild = ExpandableTreeNode(value)
|
||||
if (childDeclaration != null)
|
||||
newChild.childDeclaration()
|
||||
addChild(newChild)
|
||||
}
|
||||
|
||||
fun getVisibleNodeCount(): Int {
|
||||
return onlyVisibleItems()
|
||||
.size
|
||||
}
|
||||
|
||||
fun getVisibleNode(position: Int): ExpandableTreeNode<T> {
|
||||
return onlyVisibleItems()[position]
|
||||
}
|
||||
|
||||
private fun onlyVisibleItems(): List<ExpandableTreeNode<T>> {
|
||||
//Visible if parent of node is expanded.
|
||||
return map { it as ExpandableTreeNode }
|
||||
.filter { (it.parent as? ExpandableTreeNode)?.expanded ?: true }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.github.adriankuta.expandable_recyclerview
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.ChildDeclaration
|
||||
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun <reified T> expandableTree(
|
||||
value: T,
|
||||
childDeclaration: ChildDeclaration<T>
|
||||
): ExpandableTreeNode<T> {
|
||||
val treeNode = ExpandableTreeNode(value)
|
||||
treeNode.childDeclaration()
|
||||
return treeNode
|
||||
}
|
@ -3,24 +3,34 @@ package com.github.adriankuta.expandable_recyclerview
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
abstract class MultilevelRecyclerViewAdapter<T, VH: RecyclerView.ViewHolder>: RecyclerView.Adapter<VH>() {
|
||||
abstract class MultilevelRecyclerViewAdapter<T, VH : RecyclerView.ViewHolder> :
|
||||
RecyclerView.Adapter<VH>() {
|
||||
|
||||
abstract fun getExpandableGroups(): ExpandableGroup<T>
|
||||
private lateinit var treeNodes: ExpandableTreeNode<T>
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
|
||||
abstract override fun onCreateViewHolder(parent: ViewGroup, nestLevel: Int): VH
|
||||
|
||||
final override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
onBindViewHolder(holder, treeNodes.getVisibleNode(position))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
getExpandableGroups().toList()
|
||||
return getExpandableGroups().nodeCount()
|
||||
abstract fun onBindViewHolder(holder: VH, treeNode: ExpandableTreeNode<T>)
|
||||
|
||||
abstract fun getTreeNodes(): ExpandableTreeNode<T>
|
||||
|
||||
final override fun getItemCount(): Int {
|
||||
treeNodes = getTreeNodes()
|
||||
return treeNodes.getVisibleNodeCount()
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
final override fun getItemViewType(position: Int): Int {
|
||||
|
||||
return treeNodes.getVisibleNode(position).depth()
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return super.getItemViewType(position)
|
||||
fun toggleGroup(expandableTreeNode: ExpandableTreeNode<T>) {
|
||||
expandableTreeNode.expanded = !expandableTreeNode.expanded
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.github.adriankuta.expandable_recyclerview;
|
||||
|
||||
public class Temp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExpandableGroup<String> group = new ExpandableGroup<>("");
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user