Skip to content

Commit

Permalink
fix #3001
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang committed Feb 25, 2020
1 parent ba4984c commit 672ac06
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author: limuyang
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,7 +16,7 @@ public DragAndSwipeAdapter(List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Status, BaseViewHolder> {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder
class HomeAdapter(data: MutableList<HomeEntity>) :
BaseSectionQuickAdapter<HomeEntity, BaseViewHolder>(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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
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;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand All @@ -33,16 +30,15 @@ public SectionQuickAdapter(int layoutResId, int sectionHeadResId, List<MySection
}

@Override
protected void convertHeader(@NotNull BaseViewHolder helper, @Nullable MySection item) {
if (item != null && item.getObject() instanceof String) {
protected void convertHeader(@NotNull BaseViewHolder helper, @NotNull MySection item) {
if (item.getObject() instanceof String) {
helper.setText(R.id.header, (String) item.getObject());
}
}



@Override
protected void convert(@NonNull BaseViewHolder helper, MySection item) {
protected void convert(@NotNull BaseViewHolder helper, @NotNull MySection item) {
Video video = (Video) item.getObject();
switch (helper.getLayoutPosition() % 2) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.entity.Movie;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chad.library.adapter.base.module.UpFetchModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author: limuyang
Expand All @@ -20,7 +20,7 @@ public UpFetchAdapter() {
}

@Override
protected void convert(@NotNull BaseViewHolder helper, @Nullable Movie item) {
protected void convert(@NotNull BaseViewHolder helper, @NotNull Movie item) {
switch (helper.getLayoutPosition() %
3) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand Down Expand Up @@ -39,7 +38,7 @@ protected void convert(@NonNull BaseViewHolder helper, DiffUtilDemoEntity item)
* @param payloads payload info.
*/
@Override
protected void convert(@NotNull BaseViewHolder helper, @Nullable DiffUtilDemoEntity item, @NotNull 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,7 +46,7 @@ public int getItemType(@NotNull List<? extends DelegateMultiEntity> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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) {
// 增量刷新,使用动画变化箭头
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = 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<Any>) {
override fun convert(helper: BaseViewHolder, item: T, payloads: List<Any>) {
getItemProvider(helper.itemViewType)!!.convert(helper, item, payloads)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
* @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.
Expand All @@ -202,7 +202,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
* @param item The item that needs to be displayed.
* @param payloads payload info.
*/
protected open fun convert(helper: VH, item: T?, payloads: List<Any>) {}
protected open fun convert(helper: VH, item: T, payloads: List<Any>) {}

/**
* (可选重写)当 item 的 ViewHolder创建完毕后,执行此方法。
Expand Down Expand Up @@ -424,7 +424,11 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
* 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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ abstract class BaseSectionQuickAdapter<T : SectionEntity, VH : BaseViewHolder>
* @param helper ViewHolder
* @param item data
*/
protected abstract fun convertHeader(helper: VH, item: T?)
protected abstract fun convertHeader(helper: VH, item: T)

/**
* 重写此处,设置 Diff Header
* @param helper VH
* @param item T?
* @param payloads MutableList<Any>
*/
protected open fun convertHeader(helper: VH, item: T?, payloads: MutableList<Any>) {}
protected open fun convertHeader(helper: VH, item: T, payloads: MutableList<Any>) {}

/**
* 如果 item 不是多布局,可以使用此方法快速设置 item layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ abstract class BaseItemProvider<T> {
@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<Any>) {}
open fun convert(helper: BaseViewHolder, data: T, payloads: List<Any>) {}

/**
* (可选重写)创建 ViewHolder。
Expand Down

0 comments on commit 672ac06

Please sign in to comment.