Skip to content

Commit

Permalink
fix #3009
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang committed Dec 30, 2019
1 parent b4176a0 commit 885f070
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
//Do not move position, need to change before LoadMoreView binding
loadMoreModule?.autoLoadMore(position)
when (holder.itemViewType) {
LOAD_MORE_VIEW -> loadMoreModule?.loadMoreView?.convert(holder, position)
LOAD_MORE_VIEW -> {
loadMoreModule?.let {
it.loadMoreView.convert(holder, position, it.loadMoreStatus)
}
}
HEADER_VIEW, EMPTY_VIEW, FOOTER_VIEW -> return
else -> convert(holder, data.getOrNull(position - getHeaderLayoutCount()))
}
Expand All @@ -346,7 +350,11 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
//Do not move position, need to change before LoadMoreView binding
loadMoreModule?.autoLoadMore(position)
when (holder.itemViewType) {
LOAD_MORE_VIEW -> loadMoreModule?.loadMoreView?.convert(holder, position)
LOAD_MORE_VIEW -> {
loadMoreModule?.let {
it.loadMoreView.convert(holder, position, it.loadMoreStatus)
}
}
HEADER_VIEW, EMPTY_VIEW, FOOTER_VIEW -> return
else -> convert(holder, data.getOrNull(position - getHeaderLayoutCount()), payloads)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.Executor

class BrvahAsyncDiffer<T>(private val adapter: BaseQuickAdapter<T, *>,
private val config: BrvahAsyncDifferConfig<T>) : DifferImp<T> {
private var mUpdateCallback: ListUpdateCallback = BrvahListUpdateCallback(adapter)
private val mUpdateCallback: ListUpdateCallback = BrvahListUpdateCallback(adapter)
private var mMainThreadExecutor: Executor

private class MainThreadExecutor internal constructor() : Executor {
Expand All @@ -29,7 +29,7 @@ class BrvahAsyncDiffer<T>(private val adapter: BaseQuickAdapter<T, *>,

private val mListeners: MutableList<ListChangeListener<T>> = CopyOnWriteArrayList()

var mMaxScheduledGeneration = 0
private var mMaxScheduledGeneration = 0

@JvmOverloads
fun submitList(newList: MutableList<T>?, commitCallback: Runnable? = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,78 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder
*
* @author limuyang
*/
abstract class BaseLoadMoreView {

enum class Status {
Complete, Loading, Fail, End
}

var loadMoreStatus = Status.Complete
internal set
enum class LoadMoreStatus {
Complete, Loading, Fail, End
}

var isLoadEndMoreGone: Boolean = false
internal set
/**
* 继承此类,实行自定义loadMore视图
*/
abstract class BaseLoadMoreView {

/**
* 根布局
* @param parent ViewGroup
* @return View
*/
abstract fun getRootView(parent: ViewGroup): View

/**
* 布局中的 加载更多视图
* @param holder BaseViewHolder
* @return View
*/
abstract fun getLoadingView(holder: BaseViewHolder): View

/**
* 布局中的 加载完成布局
* @param holder BaseViewHolder
* @return View
*/
abstract fun getLoadComplete(holder: BaseViewHolder): View

/**
* 布局中的 加载结束布局
* @param holder BaseViewHolder
* @return View
*/
abstract fun getLoadEndView(holder: BaseViewHolder): View

/**
* 布局中的 加载失败布局
* @param holder BaseViewHolder
* @return View
*/
abstract fun getLoadFailView(holder: BaseViewHolder): View

open fun convert(holder: BaseViewHolder, position: Int) {
/**
* 可重写此方式,实行自定义逻辑
* @param holder BaseViewHolder
* @param position Int
* @param loadMoreStatus LoadMoreStatus
*/
open fun convert(holder: BaseViewHolder, position: Int, loadMoreStatus: LoadMoreStatus) {
when (loadMoreStatus) {
Status.Complete -> {
LoadMoreStatus.Complete -> {
getLoadingView(holder).isVisible(false)
getLoadComplete(holder).isVisible(true)
getLoadFailView(holder).isVisible(false)
getLoadEndView(holder).isVisible(false)
}
Status.Loading -> {
LoadMoreStatus.Loading -> {
getLoadingView(holder).isVisible(true)
getLoadComplete(holder).isVisible(false)
getLoadFailView(holder).isVisible(false)
getLoadEndView(holder).isVisible(false)
}
Status.Fail -> {
LoadMoreStatus.Fail -> {
getLoadingView(holder).isVisible(false)
getLoadComplete(holder).isVisible(false)
getLoadFailView(holder).isVisible(true)
getLoadEndView(holder).isVisible(false)
}
Status.End -> {
LoadMoreStatus.End -> {
getLoadingView(holder).isVisible(false)
getLoadComplete(holder).isVisible(false)
getLoadFailView(holder).isVisible(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.LoadMoreListenerImp
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.chad.library.adapter.base.loadmore.BaseLoadMoreView
import com.chad.library.adapter.base.loadmore.LoadMoreStatus
import com.chad.library.adapter.base.loadmore.SimpleLoadMoreView
import com.chad.library.adapter.base.viewholder.BaseViewHolder

Expand Down Expand Up @@ -39,6 +40,12 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
/** 不满一屏时,是否可以继续加载的标记位 */
private var mNextLoadEnable = true

var loadMoreStatus = LoadMoreStatus.Complete
private set

var isLoadEndMoreGone: Boolean = false
private set

/** 设置加载更多布局 */
var loadMoreView = LoadMoreModuleConfig.defLoadMoreView
/** 加载完成后是否允许点击 */
Expand All @@ -61,7 +68,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
*/
val isLoading: Boolean
get() {
return loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.Loading
return loadMoreStatus == LoadMoreStatus.Loading
}

/**
Expand Down Expand Up @@ -94,7 +101,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
}
} else {
if (newHasLoadMore) {
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Complete
loadMoreStatus = LoadMoreStatus.Complete
baseQuickAdapter.notifyItemInserted(loadMoreViewPosition)
}
}
Expand All @@ -103,11 +110,11 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,

internal fun setupViewHolder(viewHolder: BaseViewHolder) {
viewHolder.itemView.setOnClickListener {
if (loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.Fail) {
if (loadMoreStatus == LoadMoreStatus.Fail) {
loadMoreToLoading()
} else if (loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.Complete) {
} else if (loadMoreStatus == LoadMoreStatus.Complete) {
loadMoreToLoading()
} else if (enableLoadMoreEndClick && loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.End) {
} else if (enableLoadMoreEndClick && loadMoreStatus == LoadMoreStatus.End) {
loadMoreToLoading()
}
}
Expand All @@ -117,10 +124,10 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
* The notification starts the callback and loads more
*/
fun loadMoreToLoading() {
if (loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.Loading) {
if (loadMoreStatus == LoadMoreStatus.Loading) {
return
}
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Loading
loadMoreStatus = LoadMoreStatus.Loading
baseQuickAdapter.notifyItemChanged(loadMoreViewPosition)
invokeLoadMoreListener()
}
Expand All @@ -130,7 +137,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
if (mLoadMoreListener == null || !isEnableLoadMore) {
return false
}
if (loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.End && loadMoreView.isLoadEndMoreGone) {
if (loadMoreStatus == LoadMoreStatus.End && isLoadEndMoreGone) {
return false
}
return baseQuickAdapter.data.isNotEmpty()
Expand All @@ -151,10 +158,10 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
if (position < baseQuickAdapter.itemCount - preLoadNumber) {
return
}
if (loadMoreView.loadMoreStatus != BaseLoadMoreView.Status.Complete) {
if (loadMoreStatus != LoadMoreStatus.Complete) {
return
}
if (loadMoreView.loadMoreStatus == BaseLoadMoreView.Status.Loading) {
if (loadMoreStatus == LoadMoreStatus.Loading) {
return
}
if (!mNextLoadEnable) {
Expand All @@ -168,7 +175,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
* 触发加载更多监听
*/
private fun invokeLoadMoreListener() {
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Loading
loadMoreStatus = LoadMoreStatus.Loading
baseQuickAdapter.weakRecyclerView.get()?.let {
it.post { mLoadMoreListener?.onLoadMore() }
} ?: mLoadMoreListener?.onLoadMore()
Expand Down Expand Up @@ -236,9 +243,9 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
return
}
// mNextLoadEnable = false
loadMoreView.isLoadEndMoreGone = gone
isLoadEndMoreGone = gone

loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.End
loadMoreStatus = LoadMoreStatus.End

if (gone) {
baseQuickAdapter.notifyItemRemoved(loadMoreViewPosition)
Expand All @@ -255,7 +262,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
return
}
// mNextLoadEnable = true
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Complete
loadMoreStatus = LoadMoreStatus.Complete

baseQuickAdapter.notifyItemChanged(loadMoreViewPosition)

Expand All @@ -269,7 +276,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
if (!hasLoadMoreView()) {
return
}
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Fail
loadMoreStatus = LoadMoreStatus.Fail
baseQuickAdapter.notifyItemChanged(loadMoreViewPosition)
}

Expand All @@ -288,7 +295,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
internal fun reset() {
if (mLoadMoreListener != null) {
isEnableLoadMore = true
loadMoreView.loadMoreStatus = BaseLoadMoreView.Status.Complete
loadMoreStatus = LoadMoreStatus.Complete
}
}
}

0 comments on commit 885f070

Please sign in to comment.