diff --git a/library/build.gradle b/library/build.gradle index 7ee2088b6..497920d4a 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,7 +1,7 @@ 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 diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt index 590405c06..b4780a890 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt @@ -113,7 +113,7 @@ abstract class BaseNodeAdapter(nodeList: MutableList? = 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? = 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? = 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? = 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? = 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()) { diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseProviderMultiAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseProviderMultiAdapter.kt index 107aae013..d28379a68 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseProviderMultiAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseProviderMultiAdapter.kt @@ -76,7 +76,7 @@ abstract class BaseProviderMultiAdapter(data: MutableList? = 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(data: MutableList? = 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(data: MutableList? = 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(data: MutableList? = null) : if (position == RecyclerView.NO_POSITION) { return@setOnLongClickListener false } - position -= getHeaderLayoutCount() + position -= headerLayoutCount provider.onChildLongClick(viewHolder, v, data[position], position) } } diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt index 07866644b..fbd06993e 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt @@ -273,7 +273,7 @@ abstract class BaseQuickAdapter } else { 0 } - return getHeaderLayoutCount() + getDefItemCount() + getFooterLayoutCount() + loadMoreCount + return headerLayoutCount + getDefItemCount() + footerLayoutCount + loadMoreCount } } @@ -336,7 +336,7 @@ abstract class BaseQuickAdapter } } 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 } } 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 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 if (position == RecyclerView.NO_POSITION) { return@setOnClickListener } - position -= getHeaderLayoutCount() + position -= headerLayoutCount setOnItemClick(v, position) } } @@ -496,7 +496,7 @@ abstract class BaseQuickAdapter if (position == RecyclerView.NO_POSITION) { return@setOnLongClickListener false } - position -= getHeaderLayoutCount() + position -= headerLayoutCount setOnItemLongClick(v, position) } } @@ -512,7 +512,7 @@ abstract class BaseQuickAdapter if (position == RecyclerView.NO_POSITION) { return@setOnClickListener } - position -= getHeaderLayoutCount() + position -= headerLayoutCount setOnItemChildClick(v, position) } } @@ -529,7 +529,7 @@ abstract class BaseQuickAdapter if (position == RecyclerView.NO_POSITION) { return@setOnLongClickListener false } - position -= getHeaderLayoutCount() + position -= headerLayoutCount setOnItemChildLongClick(v, position) } } @@ -712,7 +712,7 @@ abstract class BaseQuickAdapter } 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 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 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 } 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 } } - 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 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 * * @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 */ 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 */ 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 */ open fun addData(@IntRange(from = 0) position: Int, newData: Collection) { this.data.addAll(position, newData) - notifyItemRangeInserted(position + getHeaderLayoutCount(), newData.size) + notifyItemRangeInserted(position + headerLayoutCount, newData.size) compatibilityDataSizeChanged(newData.size) } open fun addData(@NonNull newData: Collection) { 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 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 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 return } this.data[index] = data - notifyItemChanged(index + getHeaderLayoutCount()) + notifyItemChanged(index + headerLayoutCount) } /** diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.kt index de456c643..cff8efc6d 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.kt @@ -66,7 +66,7 @@ abstract class BaseSectionQuickAdapter 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 } 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) } diff --git a/library/src/main/java/com/chad/library/adapter/base/diff/BrvahListUpdateCallback.kt b/library/src/main/java/com/chad/library/adapter/base/diff/BrvahListUpdateCallback.kt index 2feaa036f..f9a580d97 100644 --- a/library/src/main/java/com/chad/library/adapter/base/diff/BrvahListUpdateCallback.kt +++ b/library/src/main/java/com/chad/library/adapter/base/diff/BrvahListUpdateCallback.kt @@ -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 diff --git a/library/src/main/java/com/chad/library/adapter/base/module/DraggableModule.kt b/library/src/main/java/com/chad/library/adapter/base/module/DraggableModule.kt index d26bf3fef..2d9676312 100644 --- a/library/src/main/java/com/chad/library/adapter/base/module/DraggableModule.kt +++ b/library/src/main/java/com/chad/library/adapter/base/module/DraggableModule.kt @@ -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 *************************/ diff --git a/library/src/main/java/com/chad/library/adapter/base/module/LoadMoreModule.kt b/library/src/main/java/com/chad/library/adapter/base/module/LoadMoreModule.kt index f0aaa72fe..b0a5f0443 100644 --- a/library/src/main/java/com/chad/library/adapter/base/module/LoadMoreModule.kt +++ b/library/src/main/java/com/chad/library/adapter/base/module/LoadMoreModule.kt @@ -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 } }