Expandable ReyclerView module

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

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)
}
}