|
|
@@ -44,7 +44,7 @@ abstract class BaseDataBindingAdapter<T, B : ViewDataBinding> :
|
|
|
*/
|
|
|
val data = mutableListOf<T>()
|
|
|
|
|
|
- open var emtpyView = R.layout.rv_empty
|
|
|
+ open var emtpyView = R.layout.rv_empty
|
|
|
|
|
|
/**
|
|
|
* 判断数据是否为空,如果没有数据,并且需要空布局,就返回1
|
|
|
@@ -73,7 +73,7 @@ abstract class BaseDataBindingAdapter<T, B : ViewDataBinding> :
|
|
|
val binding = DataBindingUtil.inflate<B>(
|
|
|
LayoutInflater.from(parent.context), layoutId, parent, false
|
|
|
)
|
|
|
- ViewTool.inflateFragmentPixels(parent.context, binding.root,1194, 834)
|
|
|
+ ViewTool.inflateFragmentPixels(parent.context, binding.root, 1194, 834)
|
|
|
ViewHolder(binding)
|
|
|
}
|
|
|
}
|
|
|
@@ -94,6 +94,15 @@ abstract class BaseDataBindingAdapter<T, B : ViewDataBinding> :
|
|
|
notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 清除数据
|
|
|
+ */
|
|
|
+ @SuppressLint("NotifyDataSetChanged")
|
|
|
+ fun clearData() {
|
|
|
+ data.clear()
|
|
|
+ notifyDataSetChanged()
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 增量更新数据
|
|
|
*/
|
|
|
@@ -105,7 +114,7 @@ abstract class BaseDataBindingAdapter<T, B : ViewDataBinding> :
|
|
|
|
|
|
final override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
|
- if(data.size == 0 && showEmptyView) {
|
|
|
+ if (data.size == 0 && showEmptyView) {
|
|
|
onBindEmptyViewHolder(holder.binding)
|
|
|
} else {
|
|
|
onBindViewHolder(holder.binding as B, data[position], position)
|
|
|
@@ -121,7 +130,8 @@ abstract class BaseDataBindingAdapter<T, B : ViewDataBinding> :
|
|
|
/**
|
|
|
* 显示空数据时使用。通过[binding]设置布局中对应的变量[item]更新数据。
|
|
|
*/
|
|
|
- open fun onBindEmptyViewHolder(binding: ViewDataBinding){}
|
|
|
+ open fun onBindEmptyViewHolder(binding: ViewDataBinding) {}
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否空布局
|
|
|
*/
|