Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Enable explicitApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jun 26, 2024
1 parent 2fe64ae commit d8527b9
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 66 deletions.
4 changes: 4 additions & 0 deletions adapter/rv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ android {
buildFeatures.dataBinding = true
}

kotlin {
explicitApi()
}

dependencies {
api(libs.kotlinX.immutable)
api(libs.androidX.collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import io.github.goooler.adapter.rv.internal.IMutableRvAdapter
* @since 1.0.0
*/
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
abstract class BaseRvAdapter<M : IVhModelType> private constructor(
public abstract class BaseRvAdapter<M : IVhModelType> private constructor(
private val delegate: IMutableRvAdapter.Impl<M, BaseRvAdapter<M>>,
) : RecyclerView.Adapter<BindingViewHolder>(),
IRvBinding<M>,
IMutableRvAdapter<M> by delegate {

constructor() : this(IMutableRvAdapter.Impl()) {
public constructor() : this(IMutableRvAdapter.Impl()) {
@Suppress("LeakingThis")
delegate.adapter = this
}

override var list: List<M>
public override var list: List<M>
get() = delegate.list
set(value) {
delegate.list = value
@Suppress("NotifyDataSetChanged")
notifyDataSetChanged()
}

override fun getItemCount(): Int = delegate.list.size
public override fun getItemCount(): Int = delegate.list.size
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import androidx.recyclerview.widget.RecyclerView
* @version 1.0.0
* @since 1.0.0
*/
class BindingViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
public class BindingViewHolder(public val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {

companion object {
fun create(parent: ViewGroup, @LayoutRes viewType: Int): BindingViewHolder {
public companion object {
public fun create(parent: ViewGroup, @LayoutRes viewType: Int): BindingViewHolder {
val binding = DataBindingUtil.inflate<ViewDataBinding>(
LayoutInflater.from(parent.context),
viewType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package io.github.goooler.adapter.rv.core

import androidx.databinding.ViewDataBinding

interface IRvBinding<M : IVhModelType> {
public interface IRvBinding<M : IVhModelType> {

/**
* What to do when creating the viewHolder.
*
* @param binding ViewDataBinding
*/
fun onCreateVH(binding: ViewDataBinding)
public fun onCreateVH(binding: ViewDataBinding)

/**
* What to do when binding the viewHolder.
*
* @param binding ViewDataBinding
* @param model model
*/
fun onBindVH(binding: ViewDataBinding, model: M, payloads: List<Any>)
public fun onBindVH(binding: ViewDataBinding, model: M, payloads: List<Any>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
* @version 1.0.0
* @since 1.0.0
*/
interface ISpanSize {
public interface ISpanSize {
/**
* Get span size. How many lattices does a model occupy.
*/
val spanSize: Int get() = SPAN_SIZE_SINGLE
public val spanSize: Int get() = SPAN_SIZE_SINGLE

companion object {
public companion object {
/**
* fill one line.
*/
const val SPAN_SIZE_FULL = -1
const val SPAN_SIZE_SINGLE = 1
const val SPAN_SIZE_DOUBLE = 2
const val SPAN_SIZE_TRIPLE = 3
const val SPAN_SIZE_QUADRUPLE = 4
const val SPAN_SIZE_QUINTUPLE = 5
public const val SPAN_SIZE_FULL: Int = -1
public const val SPAN_SIZE_SINGLE: Int = 1
public const val SPAN_SIZE_DOUBLE: Int = 2
public const val SPAN_SIZE_TRIPLE: Int = 3
public const val SPAN_SIZE_QUADRUPLE: Int = 4
public const val SPAN_SIZE_QUINTUPLE: Int = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import androidx.annotation.LayoutRes
* @version 1.0.0
* @since 1.0.0
*/
interface IVhModelType {
public interface IVhModelType {

/**
* Get the viewType. You can treat layout ID as viewType.
*/
@get:LayoutRes
val viewType: Int
public val viewType: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package io.github.goooler.adapter.rv.core
* @version 1.0.0
* @since 1.0.0
*/
interface IVhModelWrapper<M : IVhModelType> : IVhModelType {
public interface IVhModelWrapper<M : IVhModelType> : IVhModelType {

/**
* If [viewType] return value is not -1, this [IVhModelWrapper] self will be as a node.
Expand All @@ -19,5 +19,5 @@ interface IVhModelWrapper<M : IVhModelType> : IVhModelType {
/**
* As sub model list.
*/
val subList: Iterable<M>
public val subList: Iterable<M>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package io.github.goooler.adapter.rv.core
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView

class ItemTouchHelperCallback(
public class ItemTouchHelperCallback(
private val listener: ItemChangeListener,
private val longPressDragEnabled: Boolean = true,
private val itemViewSwipeEnabled: Boolean = false,
) : ItemTouchHelper.Callback() {

override fun isLongPressDragEnabled(): Boolean = longPressDragEnabled
public override fun isLongPressDragEnabled(): Boolean = longPressDragEnabled

override fun isItemViewSwipeEnabled(): Boolean = itemViewSwipeEnabled
public override fun isItemViewSwipeEnabled(): Boolean = itemViewSwipeEnabled

override fun getMovementFlags(
public override fun getMovementFlags(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
): Int {
Expand All @@ -23,7 +23,7 @@ class ItemTouchHelperCallback(
return makeMovementFlags(dragFlags, swipeFlags)
}

override fun onMove(
public override fun onMove(
recyclerView: RecyclerView,
from: RecyclerView.ViewHolder,
to: RecyclerView.ViewHolder,
Expand All @@ -32,14 +32,14 @@ class ItemTouchHelperCallback(
return true
}

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
public override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
listener.onItemDismiss(viewHolder.bindingAdapterPosition)
}

interface ItemChangeListener {
public interface ItemChangeListener {

fun onItemMove(fromPosition: Int, toPosition: Int)
public fun onItemMove(fromPosition: Int, toPosition: Int)

fun onItemDismiss(position: Int)
public fun onItemDismiss(position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import io.github.goooler.adapter.rv.internal.IMutableRvAdapter
* @since 1.0.0
*/
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
abstract class BaseRvDiffAdapter<M : IDiffVhModelType> private constructor(
public abstract class BaseRvDiffAdapter<M : IDiffVhModelType> private constructor(
asyncDifferConfig: AsyncDifferConfig<M>,
private val delegate: IMutableRvAdapter.Impl<M, BaseRvDiffAdapter<M>>,
) : ListAdapter<M, BindingViewHolder>(asyncDifferConfig),
IRvBinding<M>,
IMutableRvAdapter<M> by delegate {

constructor(callback: DiffCallback<M> = DiffCallback()) : this(
public constructor(callback: DiffCallback<M> = DiffCallback()) : this(
AsyncDifferConfig.Builder(callback).build(),
IMutableRvAdapter.Impl(),
) {
@Suppress("LeakingThis")
delegate.adapter = this
}

constructor(config: AsyncDifferConfig<M>) : this(config, IMutableRvAdapter.Impl()) {
public constructor(config: AsyncDifferConfig<M>) : this(config, IMutableRvAdapter.Impl()) {
@Suppress("LeakingThis")
delegate.adapter = this
}

override var list: List<M>
public override var list: List<M>
get() = delegate.list
set(value) {
delegate.list = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package io.github.goooler.adapter.rv.diff

import androidx.recyclerview.widget.DiffUtil

open class DiffCallback<M : IDiffVhModelType> : DiffUtil.ItemCallback<M>() {
public open class DiffCallback<M : IDiffVhModelType> : DiffUtil.ItemCallback<M>() {

/**
* Call this first.
*/
override fun areItemsTheSame(oldItem: M, newItem: M): Boolean = oldItem.isItemTheSame(newItem)
public override fun areItemsTheSame(oldItem: M, newItem: M): Boolean = oldItem.isItemTheSame(newItem)

/**
* Call this second.
*/
override fun areContentsTheSame(oldItem: M, newItem: M): Boolean =
public override fun areContentsTheSame(oldItem: M, newItem: M): Boolean =
oldItem.isContentTheSame(newItem)

override fun getChangePayload(oldItem: M, newItem: M): Any? = oldItem.getPayloads(newItem)
public override fun getChangePayload(oldItem: M, newItem: M): Any? = oldItem.getPayloads(newItem)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.github.goooler.adapter.rv.core.IVhModelType
* @version 1.0.0
* @since 1.0.0
*/
interface IDiffVhModelType : IVhModelType {
public interface IDiffVhModelType : IVhModelType {

/**
* Whether the item ([ViewHolder]) is the same.
Expand All @@ -19,7 +19,7 @@ interface IDiffVhModelType : IVhModelType {
* @param that other model
* @return by default, the same object is the same item.
*/
fun isItemTheSame(that: IDiffVhModelType): Boolean = this === that
public fun isItemTheSame(that: IDiffVhModelType): Boolean = this === that

/**
* Whether the content is the same.
Expand All @@ -28,7 +28,7 @@ interface IDiffVhModelType : IVhModelType {
* @param that other model
* @return by default, checking if they are equals.
*/
fun isContentTheSame(that: IDiffVhModelType): Boolean = this == that
public fun isContentTheSame(that: IDiffVhModelType): Boolean = this == that

fun getPayloads(that: IDiffVhModelType): Any? = null
public fun getPayloads(that: IDiffVhModelType): Any? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState
import io.github.goooler.adapter.rv.diff.IDiffVhModelType

abstract class BasePagingSource<T : IDiffVhModelType> : PagingSource<Int, T>() {
public abstract class BasePagingSource<T : IDiffVhModelType> : PagingSource<Int, T>() {

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, T> = try {
public override suspend fun load(params: LoadParams<Int>): LoadResult<Int, T> = try {
val currentPage = params.key ?: 1
val fetchedList = fetchListData(currentPage)
if (fetchedList.isEmpty()) {
Expand All @@ -27,7 +27,7 @@ abstract class BasePagingSource<T : IDiffVhModelType> : PagingSource<Int, T>() {
LoadResult.Error(e)
}

abstract suspend fun fetchListData(@IntRange(from = 1) page: Int): List<T>
public abstract suspend fun fetchListData(@IntRange(from = 1) page: Int): List<T>

override fun getRefreshKey(state: PagingState<Int, T>): Int? = null
public override fun getRefreshKey(state: PagingState<Int, T>): Int? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ import io.github.goooler.adapter.rv.internal.IRvAdapter
* @since 1.0.0
*/
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
abstract class BaseRvPagingAdapter<M : IDiffVhModelType> private constructor(
public abstract class BaseRvPagingAdapter<M : IDiffVhModelType> private constructor(
callback: DiffCallback<M>,
private val delegate: IRvAdapter.Impl<M, BaseRvPagingAdapter<M>>,
) : PagingDataAdapter<M, BindingViewHolder>(callback),
IRvBinding<M>,
IRvAdapter<M> by delegate {

var onLoadStatusListener: OnLoadStatusListener? = null
public var onLoadStatusListener: OnLoadStatusListener? = null

override val list: List<M> get() = snapshot().items
public override val list: List<M> get() = snapshot().items

constructor(callback: DiffCallback<M> = DiffCallback()) : this(callback, IRvAdapter.Impl()) {
public constructor(callback: DiffCallback<M> = DiffCallback()) : this(callback, IRvAdapter.Impl()) {
@Suppress("LeakingThis")
delegate.adapter = this
}

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
public override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
delegate.onAttachedToRecyclerView(recyclerView)
addLoadStateListener(loadStateListener)
}

override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
public override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
delegate.onDetachedFromRecyclerView(recyclerView)
removeLoadStateListener(loadStateListener)
}

@LayoutRes
override fun getItemViewType(position: Int): Int = getItem(position)?.viewType ?: 0
public override fun getItemViewType(position: Int): Int = getItem(position)?.viewType ?: 0

override operator fun get(position: Int): M? = getItem(position)
public override operator fun get(position: Int): M? = getItem(position)

private val loadStateListener: (CombinedLoadStates) -> Unit = {
when {
Expand All @@ -74,28 +74,28 @@ abstract class BaseRvPagingAdapter<M : IDiffVhModelType> private constructor(
}
}

interface OnLoadStatusListener {
fun onRefresh() {}
fun onLoadMore() {}
public interface OnLoadStatusListener {
public fun onRefresh() {}
public fun onLoadMore() {}

/**
* Not loading
*/
fun onNotLoading()
public fun onNotLoading()

/**
* No more data
*/
fun onNoMoreData()
public fun onNoMoreData()

/**
* Empty data
*/
fun onEmpty()
public fun onEmpty()

/**
* Error occurred
*/
fun onError(t: Throwable)
public fun onError(t: Throwable)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.goooler.adapter.rv.paging

sealed class PagingSourceException : Exception() {
data object EmptyDataException : PagingSourceException()
data object NoMoreDataException : PagingSourceException()
public sealed class PagingSourceException : Exception() {
public data object EmptyDataException : PagingSourceException()
public data object NoMoreDataException : PagingSourceException()
}

0 comments on commit d8527b9

Please sign in to comment.