Skip to content

Commit

Permalink
doc comments & new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Miha-x64 committed Jun 19, 2022
1 parent 2e8e231 commit 0d1af93
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
...
dependencies {
implementation("com.github.Miha-x64:Delegapter:742956d0")
implementation("com.github.Miha-x64:Delegapter:0.9")
}
```
Expand Down
5 changes: 3 additions & 2 deletions delegapter/src/main/java/net/aquadc/delegapter/RrAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

/**
* ArrayList with public removeRange().
* @author Mike Gorünóv
*/
public /*effectively-internal*/ class RrAL<E> extends ArrayList<E> {
public class RrAL<E> extends ArrayList<E> {
private RrAL() { super(); }
private RrAL(int initialCapacity) { super(initialCapacity); }
public RrAL(Collection<? extends E> copyFrom) { super(copyFrom); }
public /*called from .adapter package*/ RrAL(Collection<? extends E> copyFrom) { super(copyFrom); }
static <E> RrAL<E> create(int initialCapacity) {
return initialCapacity < 0 ? new RrAL<>() : new RrAL<>(initialCapacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Delegate<*>> = RrAL.create(initialCapacity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
5 changes: 4 additions & 1 deletion delegapter/src/main/kotlin/net/aquadc/delegapter/VH.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<out V : View, out B, in D>(view: V, val binding: B) : RecyclerView.ViewHolder(view) {
@Suppress("UNCHECKED_CAST")
inline val view: V get() = itemView as V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,5 +45,11 @@ class RepeatAdapter<D>(

}

fun RepeatAdapter(view: View, size: Int = 1): RepeatAdapter<Unit> =
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)
Original file line number Diff line number Diff line change
Expand Up @@ -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<D>(
private val delegate: Delegate<D>,
items: List<D> = emptyList(),
Expand All @@ -19,7 +23,7 @@ class SingleTypeAdapter<D>(

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

val items: MutableList<D> = ObservableList(RrAL(items), this)
val items: MutableList<D> = ObservableList(items, this)

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

private class ObservableList<D>(
private val list: RrAL<D>,
list: List<D>,
private val callback: Adapter<*>, // maybe use ListUpdateCallback and make this class public?
) : AbstractMutableList<D>() {

private val list = RrAL(list)

override val size: Int
get() = list.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VHT : VH<*, *, *>> : RecyclerView.Adapter<VHT>() {

// re-abstracted, don't forget to override it plz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions delegapter/src/main/kotlin/net/aquadc/delegapter/functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ inline operator fun <T, R> 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) }

Expand Down

0 comments on commit 0d1af93

Please sign in to comment.