diff --git a/README.md b/README.md index bcfa14a..b8bb355 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ repositories { ... dependencies { - implementation("com.github.Miha-x64:Delegapter:742956d0") + implementation("com.github.Miha-x64:Delegapter:0.9") } ``` diff --git a/delegapter/src/main/java/net/aquadc/delegapter/RrAL.java b/delegapter/src/main/java/net/aquadc/delegapter/RrAL.java index 6bc641f..d6f062f 100644 --- a/delegapter/src/main/java/net/aquadc/delegapter/RrAL.java +++ b/delegapter/src/main/java/net/aquadc/delegapter/RrAL.java @@ -5,11 +5,12 @@ /** * ArrayList with public removeRange(). + * @author Mike Gorünóv */ -public /*effectively-internal*/ class RrAL extends ArrayList { +public class RrAL extends ArrayList { private RrAL() { super(); } private RrAL(int initialCapacity) { super(initialCapacity); } - public RrAL(Collection copyFrom) { super(copyFrom); } + public /*called from .adapter package*/ RrAL(Collection copyFrom) { super(copyFrom); } static RrAL create(int initialCapacity) { return initialCapacity < 0 ? new RrAL<>() : new RrAL<>(initialCapacity); } diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/Delegapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/Delegapter.kt index c530da8..7be5ff2 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/Delegapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/Delegapter.kt @@ -5,7 +5,10 @@ import android.view.ViewGroup import androidx.recyclerview.widget.ListUpdateCallback import androidx.recyclerview.widget.RecyclerView - +/** + * Data structure for holding (delegate, item) pairs with agreed types. + * @author Mike Gorünóv + */ abstract class Delegapter protected constructor(initialCapacity: Int) { @JvmField protected var itemDelegates: RrAL> = RrAL.create(initialCapacity) diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/MutableDelegapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/MutableDelegapter.kt index 22fbf31..c523a36 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/MutableDelegapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/MutableDelegapter.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView import kotlin.collections.set /** + * Mutable data structure for holding (delegate, item) pairs with agreed types. * @author Mike Gorünóv */ class MutableDelegapter( diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/NullListUpdateCallback.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/NullListUpdateCallback.kt index 2700ccc..a026198 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/NullListUpdateCallback.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/NullListUpdateCallback.kt @@ -2,6 +2,11 @@ package net.aquadc.delegapter import androidx.recyclerview.widget.ListUpdateCallback +/** + * No-op implementation of [ListUpdateCallback]. + * Intended for use with parent [Delegapter]. + * @author Mike Gorünóv + */ object NullListUpdateCallback : ListUpdateCallback { override fun onInserted(position: Int, count: Int) {} override fun onRemoved(position: Int, count: Int) {} diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt index b1c3f61..38d1f0a 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt @@ -8,7 +8,10 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding - +/** + * Base ViewHolder with generified [view][V] and [binding/attachment][binding], and typed [bind] function. + * @author Mike Gorünóv + */ open class VH(view: V, val binding: B) : RecyclerView.ViewHolder(view) { @Suppress("UNCHECKED_CAST") inline val view: V get() = itemView as V diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/DelegatedAdapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/DelegatedAdapter.kt index 86ac6c4..0324ddb 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/DelegatedAdapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/DelegatedAdapter.kt @@ -6,7 +6,8 @@ import net.aquadc.delegapter.MutableDelegapter import net.aquadc.delegapter.VH /** - * An adapter implementation with Delegapter inside. + * An adapter implementation with [Delegapter] inside. + * @author Mike Gorünóv */ open class DelegatedAdapter @JvmOverloads constructor( parent: MutableDelegapter? = null, diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/RepeatAdapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/RepeatAdapter.kt index 8898656..768ed7a 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/RepeatAdapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/RepeatAdapter.kt @@ -1,9 +1,9 @@ -@file:Suppress("FunctionName") - +@file:JvmName("Adapters") package net.aquadc.delegapter.adapter import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView import net.aquadc.delegapter.Delegate import net.aquadc.delegapter.MutableDelegapter import net.aquadc.delegapter.VH @@ -45,5 +45,11 @@ class RepeatAdapter( } -fun RepeatAdapter(view: View, size: Int = 1): RepeatAdapter = - RepeatAdapter({ VH(view) }, Unit, size) +/** + * Adapter for a single [View]. + * @author Mike Gorünóv + */ +@Suppress("FunctionName") +@JvmName("singleItem") +fun SingleItemAdapter(view: View): RecyclerView.Adapter<*> = + RepeatAdapter({ VH(view) }, Unit, 1) diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/SingleTypeAdapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/SingleTypeAdapter.kt index 4c39ae9..687ce78 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/SingleTypeAdapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/SingleTypeAdapter.kt @@ -11,6 +11,10 @@ import net.aquadc.delegapter.commitRemovals import net.aquadc.delegapter.markForRemoval import java.util.function.Predicate +/** + * Adapter for a single viewType. + * @author Mike Gorünóv + */ class SingleTypeAdapter( private val delegate: Delegate, items: List = emptyList(), @@ -19,7 +23,7 @@ class SingleTypeAdapter( private val viewType = parent?.viewTypeFor(delegate) ?: 0 - val items: MutableList = ObservableList(RrAL(items), this) + val items: MutableList = ObservableList(items, this) override fun getItemCount(): Int = items.size @@ -36,10 +40,12 @@ class SingleTypeAdapter( } private class ObservableList( - private val list: RrAL, + list: List, private val callback: Adapter<*>, // maybe use ListUpdateCallback and make this class public? ) : AbstractMutableList() { + private val list = RrAL(list) + override val size: Int get() = list.size diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/VHAdapter.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/VHAdapter.kt index f1bc31f..41da827 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/VHAdapter.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/adapter/VHAdapter.kt @@ -4,7 +4,10 @@ import androidx.annotation.CallSuper import androidx.recyclerview.widget.RecyclerView import net.aquadc.delegapter.VH - +/** + * Base [RecyclerView.Adapter] for using with [VH]. + * @author Mike Gorünóv + */ abstract class VHAdapter> : RecyclerView.Adapter() { // re-abstracted, don't forget to override it plz diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/BoundsNegotiation.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/BoundsNegotiation.kt index 7491388..ccfb385 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/BoundsNegotiation.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/BoundsNegotiation.kt @@ -4,6 +4,7 @@ import androidx.annotation.Size /** * Specifies how to negotiate two different pairs of bounds. + * @author Mike Gorünóv */ enum class BoundsNegotiation { diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/ViewBounds.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/ViewBounds.kt index bef28cd..f0e7e98 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/ViewBounds.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/ViewBounds.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView /** * Enumerates different (left, top, right, bottom) positions for any [android.view.View]. + * @author Mike Gorünóv */ enum class ViewBounds { diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/decor.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/decor.kt index 97e06c8..3d32749 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/decor.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/decor/decor.kt @@ -33,6 +33,7 @@ import kotlin.math.min * @param forAdapter if specified, consider only items from this adapter * @param debugDelegates draw delegate names (debug feature) * @param debugSpaces draw space sizes (debug feature) + * @author Mike Gorünóv */ @RequiresApi(18) inline fun MutableDelegapter.decor( @RecyclerView.Orientation orientation: Int, @@ -49,6 +50,7 @@ import kotlin.math.min * Build an [RecyclerView.ItemDecoration] for [this] adapter. * @param debugDelegates draw delegate names (debug feature) * @param debugSpaces draw space sizes (debug feature) + * @author Mike Gorünóv */ @RequiresApi(18) inline fun DelegatedAdapter.decor( @RecyclerView.Orientation orientation: Int, diff --git a/delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt b/delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt index 8822ce5..60adcda 100644 --- a/delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt +++ b/delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt @@ -17,6 +17,8 @@ inline operator fun String.invoke(crossinline function: (T) -> R): (T) -> final override fun toString(): String = name } +// used by DebugDecor + internal fun StringBuilder.appendFun(function: Function<*>): StringBuilder = function.toString().let { toS -> append(toS, toS.eatFunctionPrefix, toS.eatFunctionPostfix) }