From 8cde08d0366548eb10505eb25efab906c0da8ef6 Mon Sep 17 00:00:00 2001 From: limuyang Date: Mon, 30 Oct 2023 16:33:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=99=90=E5=88=B6=E6=B3=9B=E5=9E=8BT?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E8=83=BD=E4=B8=BA=20null=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dragswipe/DragAndSwipeDifferActivity.kt | 2 +- .../adapter/HeaderAndFooterAdapter.kt | 2 +- .../home/adapter/HomeTopHeaderAdapter.kt | 2 +- .../upfetch/adapter/UpFetchAdapter.kt | 2 +- .../data/DataServer.kt | 119 +++++++++--------- .../library/adapter/base/BaseDifferAdapter.kt | 3 +- .../adapter/base/BaseMultiItemAdapter.kt | 4 +- .../library/adapter/base/BaseQuickAdapter.kt | 10 +- .../adapter/base/BaseSingleItemAdapter.kt | 20 +-- .../adapter/base/util/ItemClickUtils.kt | 6 +- 10 files changed, 82 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/dragswipe/DragAndSwipeDifferActivity.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/dragswipe/DragAndSwipeDifferActivity.kt index cf352e0d2..b1e055bb3 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/dragswipe/DragAndSwipeDifferActivity.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/dragswipe/DragAndSwipeDifferActivity.kt @@ -52,7 +52,7 @@ class DragAndSwipeDifferActivity : BaseViewBindingActivity) : - BaseQuickAdapter(list) { + BaseQuickAdapter(list) { class VH(var binding: ItemHeaderAndFooterBinding) : RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/home/adapter/HomeTopHeaderAdapter.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/home/adapter/HomeTopHeaderAdapter.kt index 62d11f259..59e0c807a 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/home/adapter/HomeTopHeaderAdapter.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/home/adapter/HomeTopHeaderAdapter.kt @@ -24,7 +24,7 @@ class HomeTopHeaderAdapter : BaseSingleItemAdapter override fun onBindViewHolder(holder: VH, item: Any?) { } - override fun getItemViewType(position: Int, list: List): Int { + override fun getItemViewType(position: Int, list: List): Int { return HEAD_VIEWTYPE } diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/upfetch/adapter/UpFetchAdapter.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/upfetch/adapter/UpFetchAdapter.kt index f07cc04fa..35b2ffd66 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/upfetch/adapter/UpFetchAdapter.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/upfetch/adapter/UpFetchAdapter.kt @@ -14,7 +14,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter * @date: 2019-12-06 * @Description: */ -class UpFetchAdapter : BaseQuickAdapter() { +class UpFetchAdapter : BaseQuickAdapter() { class VH( parent: ViewGroup, val viewBinding: ItemHeaderAndFooterBinding = ItemHeaderAndFooterBinding.inflate( diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/data/DataServer.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/data/DataServer.kt index 57ff2176e..8eaca6252 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/data/DataServer.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/data/DataServer.kt @@ -1,77 +1,70 @@ -package com.chad.baserecyclerviewadapterhelper.data; +package com.chad.baserecyclerviewadapterhelper.data - -import com.chad.baserecyclerviewadapterhelper.entity.DiffEntity; -import com.chad.baserecyclerviewadapterhelper.entity.Status; - -import java.util.ArrayList; -import java.util.List; +import com.chad.baserecyclerviewadapterhelper.entity.DiffEntity +import com.chad.baserecyclerviewadapterhelper.entity.Status /** * https://github.com/CymChad/BaseRecyclerViewAdapterHelper */ -public class DataServer { - - public static final String HTTPS_AVATARS1_GITHUBUSERCONTENT_COM_LINK = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"; - public static final String CYM_CHAD = "CymChad"; - public static final String CHAY_CHAN = "ChayChan"; - - private DataServer() { - } - - public static List getSampleData(int lenth) { - List list = new ArrayList<>(); - for (int i = 0; i < lenth; i++) { - Status status = new Status(); - status.setUserName("Chad" + i); - status.setCreatedAt("04/05/" + i); - status.setRetweet(i % 2 == 0); - status.setUserAvatar("https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"); - status.setText("BaseRecyclerViewAdpaterHelper https://www.recyclerview.org"); - list.add(status); +object DataServer { + const val HTTPS_AVATARS1_GITHUBUSERCONTENT_COM_LINK = + "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460" + const val CYM_CHAD = "CymChad" + const val CHAY_CHAN = "ChayChan" + fun getSampleData(lenth: Int): List { + val list: MutableList = ArrayList() + for (i in 0 until lenth) { + val status = Status() + status.userName = "Chad$i" + status.createdAt = "04/05/$i" + status.isRetweet = i % 2 == 0 + status.userAvatar = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460" + status.text = "BaseRecyclerViewAdpaterHelper https://www.recyclerview.org" + list.add(status) } - return list; + return list } - public static List addData(List list, int dataSize) { - for (int i = 0; i < dataSize; i++) { - Status status = new Status(); - status.setUserName("Chad" + i); - status.setCreatedAt("04/05/" + i); - status.setRetweet(i % 2 == 0); - status.setUserAvatar("https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"); - status.setText("Powerful and flexible RecyclerAdapter https://github.com/CymChad/BaseRecyclerViewAdapterHelper"); - list.add(status); + fun addData(list: MutableList, dataSize: Int): List { + for (i in 0 until dataSize) { + val status = Status() + status.userName = "Chad$i" + status.createdAt = "04/05/$i" + status.isRetweet = i % 2 == 0 + status.userAvatar = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460" + status.text = + "Powerful and flexible RecyclerAdapter https://github.com/CymChad/BaseRecyclerViewAdapterHelper" + list.add(status) } - - return list; + return list } - - - public static List getStrData() { - List list = new ArrayList<>(); - for (int i = 0; i < 20; i++) { - String str = HTTPS_AVATARS1_GITHUBUSERCONTENT_COM_LINK; - if (i % 2 == 0) { - str = CYM_CHAD; + val strData: List + get() { + val list: MutableList = ArrayList() + for (i in 0..19) { + var str = HTTPS_AVATARS1_GITHUBUSERCONTENT_COM_LINK + if (i % 2 == 0) { + str = CYM_CHAD + } + list.add(str) } - list.add(str); + return list } - return list; - } - - - public static List getDiffUtilDemoEntities() { - List list = new ArrayList<>(); - for (int i = 0; i < 10; i++){ - list.add(new DiffEntity( - i, - "Item " + i, - "This item " + i + " content", - "06-12") - ); + @JvmStatic + val diffUtilDemoEntities: List + get() { + val list: MutableList = ArrayList() + for (i in 0..9) { + list.add( + DiffEntity( + i, + "Item $i", + "This item $i content", + "06-12" + ) + ) + } + return list } - return list; - } -} +} \ No newline at end of file diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseDifferAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseDifferAdapter.kt index 56c4ab265..dd712e2fd 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseDifferAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseDifferAdapter.kt @@ -1,5 +1,6 @@ package com.chad.library.adapter.base +import androidx.annotation.IntRange import androidx.recyclerview.widget.* import androidx.recyclerview.widget.AsyncListDiffer.ListListener import java.util.* @@ -12,7 +13,7 @@ import java.util.* * @param T 数据类型 * @param VH ViewHolder 类型 */ -abstract class BaseDifferAdapter( +abstract class BaseDifferAdapter( config: AsyncDifferConfig, items: List ) : BaseQuickAdapter() { diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemAdapter.kt index 19ec4ce2e..f7d9a5574 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemAdapter.kt @@ -12,7 +12,7 @@ import java.lang.ref.WeakReference * 多类型布局 * */ -abstract class BaseMultiItemAdapter(items: List = emptyList()) : +abstract class BaseMultiItemAdapter(items: List = emptyList()) : BaseQuickAdapter(items) { private val typeViewHolders = @@ -142,7 +142,7 @@ abstract class BaseMultiItemAdapter(items: List = emptyList()) : * @param V * @constructor Create empty On multi item */ - abstract class OnMultiItem : OnMultiItemAdapterListener { + abstract class OnMultiItem : OnMultiItemAdapterListener { internal var weakA: WeakReference>? = null val adapter: BaseMultiItemAdapter? 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 99c177cad..d374a0263 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 @@ -28,7 +28,7 @@ import java.util.Collections * @param VH : BaseViewHolder * @constructor layoutId, data(Can null parameters, the default is empty data) */ -abstract class BaseQuickAdapter( +abstract class BaseQuickAdapter( open var items: List = emptyList() ) : RecyclerView.Adapter() { @@ -742,19 +742,19 @@ abstract class BaseQuickAdapter( } - fun interface OnItemClickListener { + fun interface OnItemClickListener { fun onClick(adapter: BaseQuickAdapter, view: View, position: Int) } - fun interface OnItemLongClickListener { + fun interface OnItemLongClickListener { fun onLongClick(adapter: BaseQuickAdapter, view: View, position: Int): Boolean } - fun interface OnItemChildClickListener { + fun interface OnItemChildClickListener { fun onItemClick(adapter: BaseQuickAdapter, view: View, position: Int) } - fun interface OnItemChildLongClickListener { + fun interface OnItemChildLongClickListener { fun onItemLongClick(adapter: BaseQuickAdapter, view: View, position: Int): Boolean } diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseSingleItemAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseSingleItemAdapter.kt index 4ce7f80bb..03f1d12dc 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseSingleItemAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseSingleItemAdapter.kt @@ -10,8 +10,8 @@ import androidx.recyclerview.widget.RecyclerView * @param VH viewHolder类型 type of the viewHolder * @property mItem 数据 data */ -abstract class BaseSingleItemAdapter(private var mItem: T? = null) : - BaseQuickAdapter() { +abstract class BaseSingleItemAdapter(private var mItem: T? = null) : + BaseQuickAdapter() { protected abstract fun onBindViewHolder(holder: VH, item: T?) @@ -27,7 +27,7 @@ abstract class BaseSingleItemAdapter(private va onBindViewHolder(holder, mItem, payloads) } - final override fun getItemCount(items: List): Int { + final override fun getItemCount(items: List): Int { return 1 } @@ -52,27 +52,27 @@ abstract class BaseSingleItemAdapter(private va notifyItemChanged(0) } - override fun submitList(list: List?) { + override fun submitList(list: List?) { throw RuntimeException("Please use setItem()") } - override fun add(data: Any?) { + override fun add(data: Any) { throw RuntimeException("Please use setItem()") } - override fun add(position: Int, data: Any?) { + override fun add(position: Int, data: Any) { throw RuntimeException("Please use setItem()") } - override fun addAll(collection: Collection) { + override fun addAll(collection: Collection) { throw RuntimeException("Please use setItem()") } - override fun addAll(position: Int, collection: Collection) { + override fun addAll(position: Int, collection: Collection) { throw RuntimeException("Please use setItem()") } - override fun remove(data: Any?) { + override fun remove(data: Any) { throw RuntimeException("Please use setItem()") } @@ -80,7 +80,7 @@ abstract class BaseSingleItemAdapter(private va throw RuntimeException("Please use setItem()") } - override fun set(position: Int, data: Any?) { + override fun set(position: Int, data: Any) { throw RuntimeException("Please use setItem()") } } \ No newline at end of file diff --git a/library/src/main/java/com/chad/library/adapter/base/util/ItemClickUtils.kt b/library/src/main/java/com/chad/library/adapter/base/util/ItemClickUtils.kt index 02561c1e1..ff0d433f2 100644 --- a/library/src/main/java/com/chad/library/adapter/base/util/ItemClickUtils.kt +++ b/library/src/main/java/com/chad/library/adapter/base/util/ItemClickUtils.kt @@ -11,7 +11,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter * @date 2023/5/29 * @description */ -private abstract class DebouncedClickListener(private val interval: Long) : +private abstract class DebouncedClickListener(private val interval: Long) : BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener { private var mLastClickTime: Long = 0 @@ -46,7 +46,7 @@ private abstract class DebouncedClickListener(private val interval: Long) : * @param block * @receiver */ -fun BaseQuickAdapter.setOnDebouncedItemClick( +fun BaseQuickAdapter.setOnDebouncedItemClick( time: Long = 500, block: BaseQuickAdapter.OnItemClickListener ) = this.setOnItemClickListener(object : DebouncedClickListener(time) { @@ -62,7 +62,7 @@ fun BaseQuickAdapter.setOnDebouncedItem * @param block * @receiver */ -fun BaseQuickAdapter.addOnDebouncedChildClick( +fun BaseQuickAdapter.addOnDebouncedChildClick( @IdRes id: Int, time: Long = 500, block: BaseQuickAdapter.OnItemChildClickListener