pull/401/head
gedoor 4 years ago
parent 03bc45ee9a
commit 64e17732e8
  1. 14
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt

@ -15,17 +15,17 @@ import java.util.*
*
* 通用的adapter 可添加headerfooter以及不同类型item
*/
abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) :
RecyclerView.Adapter<ItemViewHolder>() {
constructor(context: Context, vararg delegates: ItemViewDelegate<ITEM>): this(context) {
constructor(context: Context, vararg delegates: ItemViewDelegate<ITEM>) : this(context) {
addItemViewDelegates(*delegates)
}
constructor(
context: Context,
vararg delegates: Pair<Int, ItemViewDelegate<ITEM>>
): this(context) {
) : this(context) {
addItemViewDelegates(*delegates)
}
@ -57,15 +57,15 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
recyclerView.adapter = this
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegate(viewType: Int, delegate: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegate(viewType: Int, delegate: DELEGATE) {
itemDelegates[viewType] = delegate
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegate(delegate: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegate(delegate: DELEGATE) {
itemDelegates[itemDelegates.size] = delegate
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegates(vararg delegates: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegates(vararg delegates: DELEGATE) {
delegates.forEach {
addItemViewDelegate(it)
}
@ -365,7 +365,7 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
super.onAttachedToRecyclerView(recyclerView)
val manager = recyclerView.layoutManager
if (manager is GridLayoutManager) {
manager.spanSizeLookup = object: GridLayoutManager.SpanSizeLookup() {
manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return getItem(position)?.let {
if (isHeader(position) || isFooter(position)) manager.spanCount else getSpanSize(

Loading…
Cancel
Save