Skip to content

Commit 0d1af93

Browse files
committedJun 19, 2022
doc comments & new version
1 parent 2e8e231 commit 0d1af93

14 files changed

+48
-13
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
...
1111
1212
dependencies {
13-
implementation("com.github.Miha-x64:Delegapter:742956d0")
13+
implementation("com.github.Miha-x64:Delegapter:0.9")
1414
}
1515
1616
```

‎delegapter/src/main/java/net/aquadc/delegapter/RrAL.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
/**
77
* ArrayList with public removeRange().
8+
* @author Mike Gorünóv
89
*/
9-
public /*effectively-internal*/ class RrAL<E> extends ArrayList<E> {
10+
public class RrAL<E> extends ArrayList<E> {
1011
private RrAL() { super(); }
1112
private RrAL(int initialCapacity) { super(initialCapacity); }
12-
public RrAL(Collection<? extends E> copyFrom) { super(copyFrom); }
13+
public /*called from .adapter package*/ RrAL(Collection<? extends E> copyFrom) { super(copyFrom); }
1314
static <E> RrAL<E> create(int initialCapacity) {
1415
return initialCapacity < 0 ? new RrAL<>() : new RrAL<>(initialCapacity);
1516
}

‎delegapter/src/main/kotlin/net/aquadc/delegapter/Delegapter.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import android.view.ViewGroup
55
import androidx.recyclerview.widget.ListUpdateCallback
66
import androidx.recyclerview.widget.RecyclerView
77

8-
8+
/**
9+
* Data structure for holding (delegate, item) pairs with agreed types.
10+
* @author Mike Gorünóv
11+
*/
912
abstract class Delegapter protected constructor(initialCapacity: Int) {
1013

1114
@JvmField protected var itemDelegates: RrAL<Delegate<*>> = RrAL.create(initialCapacity)

‎delegapter/src/main/kotlin/net/aquadc/delegapter/MutableDelegapter.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView
88
import kotlin.collections.set
99

1010
/**
11+
* Mutable data structure for holding (delegate, item) pairs with agreed types.
1112
* @author Mike Gorünóv
1213
*/
1314
class MutableDelegapter(

‎delegapter/src/main/kotlin/net/aquadc/delegapter/NullListUpdateCallback.kt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package net.aquadc.delegapter
22

33
import androidx.recyclerview.widget.ListUpdateCallback
44

5+
/**
6+
* No-op implementation of [ListUpdateCallback].
7+
* Intended for use with parent [Delegapter].
8+
* @author Mike Gorünóv
9+
*/
510
object NullListUpdateCallback : ListUpdateCallback {
611
override fun onInserted(position: Int, count: Int) {}
712
override fun onRemoved(position: Int, count: Int) {}

‎delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import android.view.ViewGroup
88
import androidx.recyclerview.widget.RecyclerView
99
import androidx.viewbinding.ViewBinding
1010

11-
11+
/**
12+
* Base ViewHolder with generified [view][V] and [binding/attachment][binding], and typed [bind] function.
13+
* @author Mike Gorünóv
14+
*/
1215
open class VH<out V : View, out B, in D>(view: V, val binding: B) : RecyclerView.ViewHolder(view) {
1316
@Suppress("UNCHECKED_CAST")
1417
inline val view: V get() = itemView as V

‎delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/DelegatedAdapter.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import net.aquadc.delegapter.MutableDelegapter
66
import net.aquadc.delegapter.VH
77

88
/**
9-
* An adapter implementation with Delegapter inside.
9+
* An adapter implementation with [Delegapter] inside.
10+
* @author Mike Gorünóv
1011
*/
1112
open class DelegatedAdapter @JvmOverloads constructor(
1213
parent: MutableDelegapter? = null,

‎delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/RepeatAdapter.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
@file:Suppress("FunctionName")
2-
1+
@file:JvmName("Adapters")
32
package net.aquadc.delegapter.adapter
43

54
import android.view.View
65
import android.view.ViewGroup
6+
import androidx.recyclerview.widget.RecyclerView
77
import net.aquadc.delegapter.Delegate
88
import net.aquadc.delegapter.MutableDelegapter
99
import net.aquadc.delegapter.VH
@@ -45,5 +45,11 @@ class RepeatAdapter<D>(
4545

4646
}
4747

48-
fun RepeatAdapter(view: View, size: Int = 1): RepeatAdapter<Unit> =
49-
RepeatAdapter({ VH(view) }, Unit, size)
48+
/**
49+
* Adapter for a single [View].
50+
* @author Mike Gorünóv
51+
*/
52+
@Suppress("FunctionName")
53+
@JvmName("singleItem")
54+
fun SingleItemAdapter(view: View): RecyclerView.Adapter<*> =
55+
RepeatAdapter({ VH(view) }, Unit, 1)

‎delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/SingleTypeAdapter.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import net.aquadc.delegapter.commitRemovals
1111
import net.aquadc.delegapter.markForRemoval
1212
import java.util.function.Predicate
1313

14+
/**
15+
* Adapter for a single viewType.
16+
* @author Mike Gorünóv
17+
*/
1418
class SingleTypeAdapter<D>(
1519
private val delegate: Delegate<D>,
1620
items: List<D> = emptyList(),
@@ -19,7 +23,7 @@ class SingleTypeAdapter<D>(
1923

2024
private val viewType = parent?.viewTypeFor(delegate) ?: 0
2125

22-
val items: MutableList<D> = ObservableList(RrAL(items), this)
26+
val items: MutableList<D> = ObservableList(items, this)
2327

2428
override fun getItemCount(): Int =
2529
items.size
@@ -36,10 +40,12 @@ class SingleTypeAdapter<D>(
3640
}
3741

3842
private class ObservableList<D>(
39-
private val list: RrAL<D>,
43+
list: List<D>,
4044
private val callback: Adapter<*>, // maybe use ListUpdateCallback and make this class public?
4145
) : AbstractMutableList<D>() {
4246

47+
private val list = RrAL(list)
48+
4349
override val size: Int
4450
get() = list.size
4551

‎delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/VHAdapter.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import androidx.annotation.CallSuper
44
import androidx.recyclerview.widget.RecyclerView
55
import net.aquadc.delegapter.VH
66

7-
7+
/**
8+
* Base [RecyclerView.Adapter] for using with [VH].
9+
* @author Mike Gorünóv
10+
*/
811
abstract class VHAdapter<VHT : VH<*, *, *>> : RecyclerView.Adapter<VHT>() {
912

1013
// re-abstracted, don't forget to override it plz

‎delegapter/src/main/kotlin/net/aquadc/delegapter/decor/BoundsNegotiation.kt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.annotation.Size
44

55
/**
66
* Specifies how to negotiate two different pairs of bounds.
7+
* @author Mike Gorünóv
78
*/
89
enum class BoundsNegotiation {
910

‎delegapter/src/main/kotlin/net/aquadc/delegapter/decor/ViewBounds.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView
88

99
/**
1010
* Enumerates different (left, top, right, bottom) positions for any [android.view.View].
11+
* @author Mike Gorünóv
1112
*/
1213
enum class ViewBounds {
1314

‎delegapter/src/main/kotlin/net/aquadc/delegapter/decor/decor.kt

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlin.math.min
3333
* @param forAdapter if specified, consider only items from this adapter
3434
* @param debugDelegates draw delegate names (debug feature)
3535
* @param debugSpaces draw space sizes (debug feature)
36+
* @author Mike Gorünóv
3637
*/
3738
@RequiresApi(18) inline fun MutableDelegapter.decor(
3839
@RecyclerView.Orientation orientation: Int,
@@ -49,6 +50,7 @@ import kotlin.math.min
4950
* Build an [RecyclerView.ItemDecoration] for [this] adapter.
5051
* @param debugDelegates draw delegate names (debug feature)
5152
* @param debugSpaces draw space sizes (debug feature)
53+
* @author Mike Gorünóv
5254
*/
5355
@RequiresApi(18) inline fun DelegatedAdapter.decor(
5456
@RecyclerView.Orientation orientation: Int,

‎delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ inline operator fun <T, R> String.invoke(crossinline function: (T) -> R): (T) ->
1717
final override fun toString(): String = name
1818
}
1919

20+
// used by DebugDecor
21+
2022
internal fun StringBuilder.appendFun(function: Function<*>): StringBuilder =
2123
function.toString().let { toS -> append(toS, toS.eatFunctionPrefix, toS.eatFunctionPostfix) }
2224

0 commit comments

Comments
 (0)
Please sign in to comment.