Expandable ReyclerView module

This commit is contained in:
Adrian Kuta 2020-01-11 18:45:58 +01:00
parent 39358dd28d
commit 271ea2f575
12 changed files with 185 additions and 0 deletions

1
expandable-recyclerview/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,51 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
afterEvaluate {
generateReleaseBuildConfig.enabled = false
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "0.0.1-alpha01"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
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"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
ext {
PUBLISH_GROUP_ID = 'com.github.adriankuta'
PUBLISH_ARTIFACT_ID = 'expandable-recyclerView'
PUBLISH_VERSION = android.defaultConfig.versionName
}
apply from: "${rootProject.projectDir}/scripts/publish-mavencentral.gradle"

View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package com.github.adriankuta.expandable_recyclerview
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.github.adriankuta.expandable_recyclerview.test", appContext.packageName)
}
}

View File

@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.adriankuta.expandable_recyclerview" />

View File

@ -0,0 +1,19 @@
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
}
}

View File

@ -0,0 +1,12 @@
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) {
}

View File

@ -0,0 +1,26 @@
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 fun getExpandableGroups(): ExpandableGroup<T>
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getItemCount(): Int {
getExpandableGroups().toList()
return getExpandableGroups().nodeCount()
}
override fun onBindViewHolder(holder: VH, position: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getItemViewType(position: Int): Int {
return super.getItemViewType(position)
}
}

View File

@ -0,0 +1,9 @@
package com.github.adriankuta.expandable_recyclerview;
public class Temp {
public static void main(String[] args) {
ExpandableGroup<String> group = new ExpandableGroup<>("");
}
}

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Expandable RecyclerView</string>
</resources>

View File

@ -0,0 +1,17 @@
package com.github.adriankuta.expandable_recyclerview
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}