Skip to content

Commit

Permalink
Merge pull request #2139 from AllenCoder/master
Browse files Browse the repository at this point in the history
refactor multipleItemRvAdapter
  • Loading branch information
AllenCoder authored Apr 12, 2018
2 parents e1c2217 + 77f0dab commit b209c89
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.chad.baserecyclerviewadapterhelper.adapter.DemoMultipleItemRvAdapter;
import com.chad.baserecyclerviewadapterhelper.base.BaseActivity;
Expand All @@ -14,7 +17,6 @@
import java.util.List;

/**
* https://github.com/chaychan
*
* @author ChayChan
* @description: MultipleItemRvAdapter's usage
Expand Down Expand Up @@ -44,16 +46,52 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
int type = mData.get(position).type;
if (type == NormalMultipleEntity.SINGLE_TEXT){
if (type == NormalMultipleEntity.SINGLE_TEXT) {
return MultipleItem.TEXT_SPAN_SIZE;
}else if (type == NormalMultipleEntity.SINGLE_IMG){
} else if (type == NormalMultipleEntity.SINGLE_IMG) {
return MultipleItem.IMG_SPAN_SIZE;
}else{
} else {
return MultipleItem.IMG_TEXT_SPAN_SIZE;
}
}
});

/**
* The click event is distributed to the BaseItemProvider and can be overridden.
* if you need register itemchild click longClick
* you need to use https://github.com/CymChad/BaseRecyclerViewAdapterHelper/wiki/Add-OnItemClickLister#use-it-item-child-long-click
*/
/* @Override
protected void convert(BaseViewHolder helper, Status item) {
helper.setText(R.id.tweetName, item.getUserName())
.setText(R.id.tweetText, item.getText())
.setText(R.id.tweetDate, item.getCreatedAt())
.setVisible(R.id.tweetRT, item.isRetweet())
.addOnLongClickListener(R.id.tweetText)
.linkify(R.id.tweetText);
}
adapter.setOnItemChildLongClickListener(new BaseQuickAdapter.OnItemChildLongClickListener() {
@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
Log.d(TAG, "onItemChildLongClick: ");
Toast.makeText(ItemClickActivity.this, "onItemChildLongClick" + position, Toast.LENGTH_SHORT).show();
}
});*/
// multipleItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
// @Override
// public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
// Log.d(TAG, "onItemClick: ");
// Toast.makeText(MultipleItemRvAdapterUseActivity.this, "onItemClick" + position, Toast.LENGTH_SHORT).show();
// }
// });
// multipleItemAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
// @Override
// public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
// Log.d(TAG, "onItemClick: ");
// Toast.makeText(MultipleItemRvAdapterUseActivity.this, "onItemChildClick" + view.getId(), Toast.LENGTH_SHORT).show();
// }
// });
mRecyclerView.setAdapter(multipleItemAdapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import java.util.List;

/**
* https://github.com/chaychan
* @author ChayChan
* modify by AllenCoder 2018/04/11
* @description: MultipleItemRvAdapter demo
* @date 2018/3/30 11:28
*/

public class DemoMultipleItemRvAdapter extends MultipleItemRvAdapter<NormalMultipleEntity,BaseViewHolder> {
public class DemoMultipleItemRvAdapter extends MultipleItemRvAdapter<NormalMultipleEntity, BaseViewHolder> {

public static final int TYPE_TEXT = 100;
public static final int TYPE_IMG = 200;
Expand All @@ -45,11 +45,11 @@ protected int getViewType(NormalMultipleEntity entity) {
//根据实体类判断并返回对应的viewType,具体判断逻辑因业务不同,这里这是简单通过判断type属性
//According to the entity class to determine and return the corresponding viewType,
//the specific judgment logic is different because of the business, here is simply by judging the type attribute
if (entity.type == NormalMultipleEntity.SINGLE_TEXT){
if (entity.type == NormalMultipleEntity.SINGLE_TEXT) {
return TYPE_TEXT;
}else if (entity.type == NormalMultipleEntity.SINGLE_IMG){
} else if (entity.type == NormalMultipleEntity.SINGLE_IMG) {
return TYPE_IMG;
}else if (entity.type == NormalMultipleEntity.TEXT_IMG){
} else if (entity.type == NormalMultipleEntity.TEXT_IMG) {
return TYPE_TEXT_IMG;
}
return 0;
Expand Down

This file was deleted.

0 comments on commit b209c89

Please sign in to comment.