From 672ac062c77effc0d7223eef6ae34e28dc2e619e Mon Sep 17 00:00:00 2001 From: limuyang Date: Tue, 25 Feb 2020 20:48:24 +0800 Subject: [PATCH] fix #3001 --- .../adapter/DataBindingAdapter.java | 6 +----- .../adapter/DragAndSwipeAdapter.java | 5 ++--- .../adapter/EmptyViewAdapter.java | 3 +-- .../adapter/HomeAdapter.kt | 7 ++----- .../adapter/SectionQuickAdapter.java | 10 +++------- .../adapter/UpFetchAdapter.java | 6 +++--- .../adapter/diffUtil/DiffUtilAdapter.java | 3 +-- .../adapter/multi/DelegateMultiAdapter.java | 5 ++--- .../adapter/node/tree/provider/FirstProvider.java | 5 ++--- .../adapter/node/tree/provider/SecondProvider.java | 5 ++--- .../adapter/node/tree/provider/ThirdProvider.java | 6 +++--- .../library/adapter/base/BaseProviderMultiAdapter.kt | 4 ++-- .../com/chad/library/adapter/base/BaseQuickAdapter.kt | 10 +++++++--- .../library/adapter/base/BaseSectionQuickAdapter.kt | 4 ++-- .../library/adapter/base/provider/BaseItemProvider.kt | 4 ++-- 15 files changed, 35 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DataBindingAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DataBindingAdapter.java index 82eac1c49..1b98e6a43 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DataBindingAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DataBindingAdapter.java @@ -10,7 +10,6 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author: limuyang @@ -33,10 +32,7 @@ protected void onItemViewHolderCreated(@NotNull BaseViewHolder viewHolder, int v } @Override - protected void convert(@NotNull BaseViewHolder helper, @Nullable Movie item) { - if (item == null) { - return; - } + protected void convert(@NotNull BaseViewHolder helper, @NotNull Movie item) { // 获取 Binding ItemMovieBinding binding = helper.getBinding(); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DragAndSwipeAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DragAndSwipeAdapter.java index d65d9f061..39b1c191d 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DragAndSwipeAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/DragAndSwipeAdapter.java @@ -2,11 +2,10 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.chad.library.adapter.base.module.DraggableModule; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -17,7 +16,7 @@ public DragAndSwipeAdapter(List data) { } @Override - protected void convert(@NotNull BaseViewHolder helper, @Nullable String item) { + protected void convert(@NotNull BaseViewHolder helper, @NotNull String item) { switch (helper.getLayoutPosition() % 3) { case 0: helper.setImageResource(R.id.iv_head, R.mipmap.head_img0); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/EmptyViewAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/EmptyViewAdapter.java index 2078495f3..a12a0c08e 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/EmptyViewAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/EmptyViewAdapter.java @@ -6,7 +6,6 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class EmptyViewAdapter extends BaseQuickAdapter { @@ -15,7 +14,7 @@ public EmptyViewAdapter() { } @Override - protected void convert(@NotNull BaseViewHolder helper, @Nullable Status item) { + protected void convert(@NotNull BaseViewHolder helper, @NotNull Status item) { switch (helper.getLayoutPosition() % 3) { case 0: helper.setImageResource(R.id.img, R.mipmap.animation_img1); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/HomeAdapter.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/HomeAdapter.kt index 18da0260f..3caa6c115 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/HomeAdapter.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/HomeAdapter.kt @@ -11,16 +11,13 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder class HomeAdapter(data: MutableList) : BaseSectionQuickAdapter(R.layout.def_section_head, R.layout.home_item_view, data) { - override fun convert(helper: BaseViewHolder, item: HomeEntity?) { - if (item == null) { - return - } + override fun convert(helper: BaseViewHolder, item: HomeEntity) { helper.setText(R.id.text, item.name) helper.setImageResource(R.id.icon, item.imageResource) } - override fun convertHeader(helper: BaseViewHolder, item: HomeEntity?) { + override fun convertHeader(helper: BaseViewHolder, item: HomeEntity) { helper.setGone(R.id.more, true) helper.setText(R.id.header, item?.headerTitle) } diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/SectionQuickAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/SectionQuickAdapter.java index b3661f104..c788aa225 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/SectionQuickAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/SectionQuickAdapter.java @@ -1,7 +1,5 @@ package com.chad.baserecyclerviewadapterhelper.adapter; -import androidx.annotation.NonNull; - import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.entity.MySection; import com.chad.baserecyclerviewadapterhelper.entity.Video; @@ -9,7 +7,6 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -33,16 +30,15 @@ public SectionQuickAdapter(int layoutResId, int sectionHeadResId, List payloads) { + protected void convert(@NotNull BaseViewHolder helper, @NotNull DiffUtilDemoEntity item, @NotNull List payloads) { for (Object p : payloads) { int payload = (int) p; if (payload == ITEM_0_PAYLOAD) { diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/multi/DelegateMultiAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/multi/DelegateMultiAdapter.java index 9f871dca8..2509f6142 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/multi/DelegateMultiAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/multi/DelegateMultiAdapter.java @@ -4,11 +4,10 @@ import com.chad.baserecyclerviewadapterhelper.entity.DelegateMultiEntity; import com.chad.baserecyclerviewadapterhelper.entity.QuickMultipleEntity; import com.chad.library.adapter.base.BaseDelegateMultiAdapter; -import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -47,7 +46,7 @@ public int getItemType(@NotNull List data, int po } @Override - protected void convert(@NotNull BaseViewHolder helper, @Nullable DelegateMultiEntity item) { + protected void convert(@NotNull BaseViewHolder helper, @NotNull DelegateMultiEntity item) { switch (helper.getItemViewType()) { case QuickMultipleEntity.TEXT: helper.setText(R.id.tv, "CymChad " + helper.getAdapterPosition()); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java index 5b5ec1ed0..49c502a6e 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java @@ -14,7 +14,6 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -31,7 +30,7 @@ public int getLayoutId() { } @Override - public void convert(@NotNull BaseViewHolder helper, @Nullable BaseNode data) { + public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data) { FirstNode entity = (FirstNode) data; helper.setText(R.id.title, entity.getTitle()); helper.setImageResource(R.id.iv, R.mipmap.arrow_r); @@ -40,7 +39,7 @@ public void convert(@NotNull BaseViewHolder helper, @Nullable BaseNode data) { } @Override - public void convert(@NotNull BaseViewHolder helper, @Nullable BaseNode data, @NotNull List payloads) { + public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data, @NotNull List payloads) { for (Object payload : payloads) { if (payload instanceof Integer && (int) payload == NodeTreeAdapter.EXPAND_COLLAPSE_PAYLOAD) { // 增量刷新,使用动画变化箭头 diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/SecondProvider.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/SecondProvider.java index 05fa4e079..cf579457a 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/SecondProvider.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/SecondProvider.java @@ -4,12 +4,11 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.entity.node.tree.SecondNode; -import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.chad.library.adapter.base.entity.node.BaseNode; import com.chad.library.adapter.base.provider.BaseNodeProvider; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class SecondProvider extends BaseNodeProvider { @@ -24,7 +23,7 @@ public int getLayoutId() { } @Override - public void convert(@NotNull BaseViewHolder helper, @Nullable BaseNode data) { + public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data) { SecondNode entity = (SecondNode) data; helper.setText(R.id.title, entity.getTitle()); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/ThirdProvider.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/ThirdProvider.java index 3aad11af6..49f726ee8 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/ThirdProvider.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/ThirdProvider.java @@ -2,11 +2,11 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.entity.node.tree.ThirdNode; -import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.chad.library.adapter.base.entity.node.BaseNode; import com.chad.library.adapter.base.provider.BaseNodeProvider; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; + import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class ThirdProvider extends BaseNodeProvider { @@ -21,7 +21,7 @@ public int getLayoutId() { } @Override - public void convert(@NotNull BaseViewHolder helper, @Nullable BaseNode data) { + public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data) { ThirdNode entity = (ThirdNode) data; helper.setText(R.id.title, entity.getTitle()); } 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 1af830f9a..031f0fa7c 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 @@ -53,11 +53,11 @@ abstract class BaseProviderMultiAdapter(data: MutableList? = null) : return getItemType(data, position) } - override fun convert(helper: BaseViewHolder, item: T?) { + override fun convert(helper: BaseViewHolder, item: T) { getItemProvider(helper.itemViewType)!!.convert(helper, item) } - override fun convert(helper: BaseViewHolder, item: T?, payloads: List) { + override fun convert(helper: BaseViewHolder, item: T, payloads: List) { getItemProvider(helper.itemViewType)!!.convert(helper, item, payloads) } 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 bb3a78e78..bcfdea539 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 @@ -188,7 +188,7 @@ abstract class BaseQuickAdapter * @param helper A fully initialized helper. * @param item The item that needs to be displayed. */ - protected abstract fun convert(helper: VH, item: T?) + protected abstract fun convert(helper: VH, item: T) /** * Optional implementation this method and use the helper to adapt the view to the given item. @@ -202,7 +202,7 @@ abstract class BaseQuickAdapter * @param item The item that needs to be displayed. * @param payloads payload info. */ - protected open fun convert(helper: VH, item: T?, payloads: List) {} + protected open fun convert(helper: VH, item: T, payloads: List) {} /** * (可选重写)当 item 的 ViewHolder创建完毕后,执行此方法。 @@ -424,7 +424,11 @@ abstract class BaseQuickAdapter * data set. * @return The data at the specified position. */ - open fun getItem(@IntRange(from = 0) position: Int): T? { + open fun getItem(@IntRange(from = 0) position: Int): T { + return data[position] + } + + open fun getItemOrNull(@IntRange(from = 0) position: Int): T? { return data.getOrNull(position) } 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 4f07b8506..14a8aee1d 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 @@ -32,7 +32,7 @@ abstract class BaseSectionQuickAdapter * @param helper ViewHolder * @param item data */ - protected abstract fun convertHeader(helper: VH, item: T?) + protected abstract fun convertHeader(helper: VH, item: T) /** * 重写此处,设置 Diff Header @@ -40,7 +40,7 @@ abstract class BaseSectionQuickAdapter * @param item T? * @param payloads MutableList */ - protected open fun convertHeader(helper: VH, item: T?, payloads: MutableList) {} + protected open fun convertHeader(helper: VH, item: T, payloads: MutableList) {} /** * 如果 item 不是多布局,可以使用此方法快速设置 item layout diff --git a/library/src/main/java/com/chad/library/adapter/base/provider/BaseItemProvider.kt b/library/src/main/java/com/chad/library/adapter/base/provider/BaseItemProvider.kt index 68ed0fe29..f1d7c8edf 100644 --- a/library/src/main/java/com/chad/library/adapter/base/provider/BaseItemProvider.kt +++ b/library/src/main/java/com/chad/library/adapter/base/provider/BaseItemProvider.kt @@ -36,9 +36,9 @@ abstract class BaseItemProvider { @LayoutRes get - abstract fun convert(helper: BaseViewHolder, data: T?) + abstract fun convert(helper: BaseViewHolder, data: T) - open fun convert(helper: BaseViewHolder, data: T?, payloads: List) {} + open fun convert(helper: BaseViewHolder, data: T, payloads: List) {} /** * (可选重写)创建 ViewHolder。