提交 49a29ebf 编写于 作者: limuyang2's avatar limuyang2

Change method to property

上级 dedd9982
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
//apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
......
......@@ -113,7 +113,7 @@ abstract class BaseNodeAdapter(nodeList: MutableList<BaseNode>? = null)
*/
override fun remove(position: Int) {
val removeCount = removeAt(position)
notifyItemRangeRemoved(position + getHeaderLayoutCount(), removeCount)
notifyItemRangeRemoved(position + headerLayoutCount, removeCount)
compatibilityDataSizeChanged(0)
}
......@@ -130,10 +130,10 @@ abstract class BaseNodeAdapter(nodeList: MutableList<BaseNode>? = null)
this.data.addAll(index, newFlatData)
if (removeCount == newFlatData.size) {
notifyItemRangeChanged(index + getHeaderLayoutCount(), removeCount)
notifyItemRangeChanged(index + headerLayoutCount, removeCount)
} else {
notifyItemRangeRemoved(index + getHeaderLayoutCount(), removeCount)
notifyItemRangeInserted(index + getHeaderLayoutCount(), newFlatData.size)
notifyItemRangeRemoved(index + headerLayoutCount, removeCount)
notifyItemRangeInserted(index + headerLayoutCount, newFlatData.size)
// notifyItemRangeChanged(index + getHeaderLayoutCount(), max(removeCount, newFlatData.size)
}
......@@ -381,7 +381,7 @@ abstract class BaseNodeAdapter(nodeList: MutableList<BaseNode>? = null)
val newFlatData = flatData(newData)
this.data.addAll(parentIndex + 1, newFlatData)
val positionStart = parentIndex + 1 + getHeaderLayoutCount()
val positionStart = parentIndex + 1 + headerLayoutCount
if (removeCount == newFlatData.size) {
notifyItemRangeChanged(positionStart, removeCount)
} else {
......@@ -453,7 +453,7 @@ abstract class BaseNodeAdapter(nodeList: MutableList<BaseNode>? = null)
val node = this.data[position]
if (node is BaseExpandNode && node.isExpanded) {
val adapterPosition = position + getHeaderLayoutCount()
val adapterPosition = position + headerLayoutCount
node.isExpanded = false
if (node.childNode.isNullOrEmpty()) {
......@@ -493,7 +493,7 @@ abstract class BaseNodeAdapter(nodeList: MutableList<BaseNode>? = null)
val node = this.data[position]
if (node is BaseExpandNode && !node.isExpanded) {
val adapterPosition = position + getHeaderLayoutCount()
val adapterPosition = position + headerLayoutCount
node.isExpanded = true
if (node.childNode.isNullOrEmpty()) {
......
......@@ -76,7 +76,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
val itemViewType = viewHolder.itemViewType
val provider = mItemProviders.get(itemViewType)
......@@ -92,7 +92,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
val itemViewType = viewHolder.itemViewType
val provider = mItemProviders.get(itemViewType)
......@@ -115,7 +115,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
provider.onChildClick(viewHolder, v, data[position], position)
}
}
......@@ -134,7 +134,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
provider.onChildLongClick(viewHolder, v, data[position], position)
}
}
......
......@@ -273,7 +273,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
} else {
0
}
return getHeaderLayoutCount() + getDefItemCount() + getFooterLayoutCount() + loadMoreCount
return headerLayoutCount + getDefItemCount() + footerLayoutCount + loadMoreCount
}
}
......@@ -336,7 +336,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
}
HEADER_VIEW, EMPTY_VIEW, FOOTER_VIEW -> return
else -> convert(holder, data.getOrNull(position - getHeaderLayoutCount()))
else -> convert(holder, data.getOrNull(position - headerLayoutCount))
}
}
......@@ -356,7 +356,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
}
HEADER_VIEW, EMPTY_VIEW, FOOTER_VIEW -> return
else -> convert(holder, data.getOrNull(position - getHeaderLayoutCount()), payloads)
else -> convert(holder, data.getOrNull(position - headerLayoutCount), payloads)
}
}
......@@ -405,7 +405,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (isFixedViewType(type))
manager.spanCount
else
mSpanSizeLookup!!.getSpanSize(manager, type, position - getHeaderLayoutCount())
mSpanSizeLookup!!.getSpanSize(manager, type, position - headerLayoutCount)
}
}
......@@ -486,7 +486,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
setOnItemClick(v, position)
}
}
......@@ -496,7 +496,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
setOnItemLongClick(v, position)
}
}
......@@ -512,7 +512,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
setOnItemChildClick(v, position)
}
}
......@@ -529,7 +529,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
position -= getHeaderLayoutCount()
position -= headerLayoutCount
setOnItemChildLongClick(v, position)
}
}
......@@ -712,7 +712,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
mHeaderLayout.addView(view, mIndex)
if (mHeaderLayout.childCount == 1) {
val position = getHeaderViewPosition()
val position = headerViewPosition
if (position != -1) {
notifyItemInserted(position)
}
......@@ -747,7 +747,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
mHeaderLayout.removeView(header)
if (mHeaderLayout.childCount == 0) {
val position = getHeaderViewPosition()
val position = headerViewPosition
if (position != -1) {
notifyItemRemoved(position)
}
......@@ -758,42 +758,49 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (!hasHeaderLayout()) return
mHeaderLayout.removeAllViews()
val position = getHeaderViewPosition()
val position = headerViewPosition
if (position != -1) {
notifyItemRemoved(position)
}
}
fun getHeaderViewPosition(): Int {
if (hasEmptyView()) {
if (headerWithEmptyEnable) {
val headerViewPosition: Int
get() {
if (hasEmptyView()) {
if (headerWithEmptyEnable) {
return 0
}
} else {
return 0
}
} else {
return 0
return -1
}
return -1
}
/**
* if addHeaderView will be return 1, if not will be return 0
*/
fun getHeaderLayoutCount(): Int =
if (hasHeaderLayout()) {
val headerLayoutCount: Int
get() {
return if (hasHeaderLayout()) {
1
} else {
0
}
}
/**
* 获取头布局
* @return LinearLayout?
*/
fun getHeaderLayout(): LinearLayout? = if (this::mHeaderLayout.isInitialized) {
mHeaderLayout
} else {
null
}
val headerLayout: LinearLayout?
get() {
return if (this::mHeaderLayout.isInitialized) {
mHeaderLayout
} else {
null
}
}
/********************************************************************************************/
/********************************* FooterView Method ****************************************/
......@@ -817,7 +824,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
mFooterLayout.addView(view, mIndex)
if (mFooterLayout.childCount == 1) {
val position = getFooterViewPosition()
val position = footerViewPosition
if (position != -1) {
notifyItemInserted(position)
}
......@@ -836,19 +843,12 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
}
fun hasFooterLayout(): Boolean {
if (this::mFooterLayout.isInitialized && mFooterLayout.childCount > 0) {
return true
}
return false
}
fun removeFooterView(footer: View) {
if (!hasFooterLayout()) return
mFooterLayout.removeView(footer)
if (mFooterLayout.childCount == 0) {
val position = getFooterViewPosition()
val position = footerViewPosition
if (position != -1) {
notifyItemRemoved(position)
}
......@@ -859,47 +859,59 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (!hasFooterLayout()) return
mFooterLayout.removeAllViews()
val position = getFooterViewPosition()
val position = footerViewPosition
if (position != -1) {
notifyItemRemoved(position)
}
}
fun getFooterViewPosition(): Int {
//Return to footer view notify position
if (hasEmptyView()) {
var position = 1
if (headerWithEmptyEnable && hasHeaderLayout()) {
position++
}
if (footerWithEmptyEnable) {
return position
}
} else {
return getHeaderLayoutCount() + data.size
fun hasFooterLayout(): Boolean {
if (this::mFooterLayout.isInitialized && mFooterLayout.childCount > 0) {
return true
}
return -1
return false
}
val footerViewPosition: Int
get() {
if (hasEmptyView()) {
var position = 1
if (headerWithEmptyEnable && hasHeaderLayout()) {
position++
}
if (footerWithEmptyEnable) {
return position
}
} else {
return headerLayoutCount + data.size
}
return -1
}
/**
* if addHeaderView will be return 1, if not will be return 0
*/
fun getFooterLayoutCount(): Int =
if (hasFooterLayout()) {
val footerLayoutCount: Int
get() {
return if (hasFooterLayout()) {
1
} else {
0
}
}
/**
* 获取脚布局
* @return LinearLayout?
*/
fun getFooterLayout(): LinearLayout? = if (this::mFooterLayout.isInitialized) {
mFooterLayout
} else {
null
}
val footerLayout: LinearLayout?
get() {
return if (this::mFooterLayout.isInitialized) {
mFooterLayout
} else {
null
}
}
/********************************************************************************************/
/********************************** EmptyView Method ****************************************/
......@@ -960,11 +972,15 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
*
* @return The view to show if the adapter is empty.
*/
fun getEmptyLayout(): FrameLayout? = if (this::mEmptyLayout.isInitialized) {
mEmptyLayout
} else {
null
}
val emptyLayout: FrameLayout?
get() {
return if (this::mEmptyLayout.isInitialized) {
mEmptyLayout
} else {
null
}
}
/*************************** Animation ******************************************/
......@@ -1046,7 +1062,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
*/
open fun addData(@IntRange(from = 0) position: Int, data: T) {
this.data.add(position, data)
notifyItemInserted(position + getHeaderLayoutCount())
notifyItemInserted(position + headerLayoutCount)
compatibilityDataSizeChanged(1)
}
......@@ -1056,7 +1072,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
*/
open fun addData(@NonNull data: T) {
this.data.add(data)
notifyItemInserted(this.data.size + getHeaderLayoutCount())
notifyItemInserted(this.data.size + headerLayoutCount)
compatibilityDataSizeChanged(1)
}
......@@ -1069,13 +1085,13 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
*/
open fun addData(@IntRange(from = 0) position: Int, newData: Collection<T>) {
this.data.addAll(position, newData)
notifyItemRangeInserted(position + getHeaderLayoutCount(), newData.size)
notifyItemRangeInserted(position + headerLayoutCount, newData.size)
compatibilityDataSizeChanged(newData.size)
}
open fun addData(@NonNull newData: Collection<T>) {
this.data.addAll(newData)
notifyItemRangeInserted(this.data.size - newData.size + getHeaderLayoutCount(), newData.size)
notifyItemRangeInserted(this.data.size - newData.size + headerLayoutCount, newData.size)
compatibilityDataSizeChanged(newData.size)
}
......@@ -1090,7 +1106,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
return
}
this.data.removeAt(position)
val internalPosition = position + getHeaderLayoutCount()
val internalPosition = position + headerLayoutCount
notifyItemRemoved(internalPosition)
compatibilityDataSizeChanged(0)
notifyItemRangeChanged(internalPosition, this.data.size - internalPosition)
......@@ -1098,7 +1114,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
open fun remove(data: T) {
val index = this.data.indexOf(data)
if(index == -1) {
if (index == -1) {
return
}
remove(index)
......@@ -1113,7 +1129,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
return
}
this.data[index] = data
notifyItemChanged(index + getHeaderLayoutCount())
notifyItemChanged(index + headerLayoutCount)
}
/**
......
......@@ -66,7 +66,7 @@ abstract class BaseSectionQuickAdapter<T : SectionEntity, VH : BaseViewHolder>
override fun onBindViewHolder(holder: VH, position: Int) {
if (holder.itemViewType == SectionEntity.HEADER_TYPE) {
// setFullSpan(holder)
convertHeader(holder, data.getOrNull(position - getHeaderLayoutCount()))
convertHeader(holder, data.getOrNull(position - headerLayoutCount))
} else {
super.onBindViewHolder(holder, position)
}
......@@ -79,7 +79,7 @@ abstract class BaseSectionQuickAdapter<T : SectionEntity, VH : BaseViewHolder>
}
if (holder.itemViewType == SectionEntity.HEADER_TYPE) {
convertHeader(holder, data.getOrNull(position - getHeaderLayoutCount()), payloads)
convertHeader(holder, data.getOrNull(position - headerLayoutCount), payloads)
} else {
super.onBindViewHolder(holder, position, payloads)
}
......
......@@ -6,19 +6,19 @@ import com.chad.library.adapter.base.BaseQuickAdapter
class BrvahListUpdateCallback(private val mAdapter: BaseQuickAdapter<*, *>) : ListUpdateCallback {
override fun onInserted(position: Int, count: Int) {
mAdapter.notifyItemRangeInserted(position + mAdapter.getHeaderLayoutCount(), count)
mAdapter.notifyItemRangeInserted(position + mAdapter.headerLayoutCount, count)
}
override fun onRemoved(position: Int, count: Int) {
mAdapter.notifyItemRangeRemoved(position + mAdapter.getHeaderLayoutCount(), count)
mAdapter.notifyItemRangeRemoved(position + mAdapter.headerLayoutCount, count)
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
mAdapter.notifyItemMoved(fromPosition + mAdapter.getHeaderLayoutCount(), toPosition + mAdapter.getHeaderLayoutCount())
mAdapter.notifyItemMoved(fromPosition + mAdapter.headerLayoutCount, toPosition + mAdapter.headerLayoutCount)
}
override fun onChanged(position: Int, count: Int, payload: Any?) {
mAdapter.notifyItemRangeChanged(position + mAdapter.getHeaderLayoutCount(), count, payload)
mAdapter.notifyItemRangeChanged(position + mAdapter.headerLayoutCount, count, payload)
}
}
\ No newline at end of file
......@@ -110,7 +110,7 @@ open class BaseDraggableModule(private val baseQuickAdapter: BaseQuickAdapter<*,
protected fun getViewHolderPosition(viewHolder: RecyclerView.ViewHolder): Int {
return viewHolder.adapterPosition - baseQuickAdapter.getHeaderLayoutCount()
return viewHolder.adapterPosition - baseQuickAdapter.headerLayoutCount
}
/************************* Drag *************************/
......
......@@ -82,7 +82,7 @@ open class BaseLoadMoreModule(private val baseQuickAdapter: BaseQuickAdapter<*,
return -1
}
return baseQuickAdapter.let {
it.getHeaderLayoutCount() + it.data.size + it.getFooterLayoutCount()
it.headerLayoutCount + it.data.size + it.footerLayoutCount
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册