Skip to content

Commit

Permalink
feat: 整理 EmptyView 代码
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Jul 18, 2022
1 parent 82c79ad commit edd1368
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
/***************************** Public property settings *************************************/

/** 是否使用空布局 */
var isUseEmpty = true
var isEmptyViewEnable = false

/**
* 是否打开动画
Expand Down Expand Up @@ -63,7 +63,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
}

/********************************* Private property *****************************************/
internal var mLastPosition = -1
private var mLastPosition = -1

private var mOnItemClickListener: OnItemClickListener<T>? = null
private var mOnItemLongClickListener: OnItemLongClickListener<T>? = null
Expand Down Expand Up @@ -199,7 +199,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(

final override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is EmptyLayoutVH) {
holder.changeEmptyView(emptyView!!)
holder.changeEmptyView(emptyView)
return
}

Expand All @@ -215,7 +215,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
}

if (holder is EmptyLayoutVH) {
holder.changeEmptyView(emptyView!!)
holder.changeEmptyView(emptyView)
return
}

Expand Down Expand Up @@ -431,7 +431,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
set(value) {
val oldDisplayEmptyLayout = displayEmptyView()
field = value
isUseEmpty = true
isEmptyViewEnable = true

val newDisplayEmptyLayout = displayEmptyView()

Expand All @@ -440,7 +440,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
} else if (newDisplayEmptyLayout && !oldDisplayEmptyLayout) {
notifyItemInserted(0)
} else if (oldDisplayEmptyLayout && newDisplayEmptyLayout) {
notifyItemChanged(0, "")
notifyItemChanged(0, 1)
}
}

Expand All @@ -464,7 +464,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
if (emptyView == null) {
return false
}
if (!isUseEmpty) {
if (!isEmptyViewEnable) {
return false
}
return items.isEmpty()
Expand Down Expand Up @@ -537,6 +537,7 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
return
}


this.items = list ?: emptyList()
mLastPosition = -1
notifyDataSetChanged()
Expand Down Expand Up @@ -627,6 +628,11 @@ abstract class BaseQuickAdapter<T, VH : RecyclerView.ViewHolder>(
notifyItemRemoved(position)
}

// 处理空视图的情况
if (displayEmptyView()) {
notifyItemInserted(0)
}

// compatibilityDataSizeChanged(0)
// notifyItemRangeChanged(position, this.data.size - position)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView

internal class EmptyLayoutVH(private val emptyLayout:FrameLayout ): RecyclerView.ViewHolder(emptyLayout) {
fun changeEmptyView(view: View) {
fun changeEmptyView(view: View?) {
if (view == null) return

val emptyLayoutVp: ViewParent? = view.parent
if (emptyLayoutVp is ViewGroup) {
emptyLayoutVp.removeView(view)
Expand Down

0 comments on commit edd1368

Please sign in to comment.