Skip to content

Commit

Permalink
Merge pull request #2831 from AllenCoder/androidx
Browse files Browse the repository at this point in the history
update Androidx
  • Loading branch information
AllenCoder authored Jul 28, 2019
2 parents 53d146a + 5db07fc commit a2a824f
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 85 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////

.DS_Store
ehthumbs.db
Thumbs.db

# Built application files
*.apk
*.ap_
Expand Down
40 changes: 35 additions & 5 deletions README-cn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
>RecyclerView作为Android最常用的控件,受益群体几乎是所有Android开发者,希望更多开发者能够一起来维护这个项目,把这个项目做得更好,帮助更多人。**Star我的项目可加Q群558178792,申请的时候把GitHub的账号名字备注上否则不予通过,谢谢配合。**中国有句古话叫“授人以鱼不如授人以渔”,不仅仅提供使用,还写了如何实现的原理:
>RecyclerView作为Android最常用的控件,受益群体几乎是所有Android开发者,希望更多开发者能够一起来维护这个项目,把这个项目做得更好,帮助更多人。中国有句古话叫“授人以鱼不如授人以渔”,不仅仅提供使用,还写了如何实现的原理:
-[RecyclerView.Adapter优化了吗?](http://www.jianshu.com/p/411ab861034f)
-[BaseRecyclerAdapter之添加动画](http://www.jianshu.com/p/fa3f97c19263)
-[BaseRecyclerAdapter之添加不同布局(头部尾部)](http://www.jianshu.com/p/9d75c22f0964)
Expand All @@ -14,7 +14,7 @@
![logo](http://upload-images.jianshu.io/upload_images/972352-1d77e0a75a4a7c0a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
一个强大并且灵活的RecyclerViewAdapter,欢迎使用。(喜欢的可以**Star**一下)
## Google Play Demo

## kotlin demo :[BRVAH_kotlin](https://github.com/AllenCoder/BRVAH_kotlin)
[![Get it on Google Play](https://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.chad.baserecyclerviewadapterhelper)
# 它能做什么?([下载 apk](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/raw/master/demo_res/demo.apk)
- **优化Adapter代码(减少百分之70%代码)**
Expand Down Expand Up @@ -42,10 +42,10 @@
然后在dependencies添加:
```
dependencies {
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46'
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.47'
}
```
## [androidX 迁移库版本](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/releases/tag/2.9.45-androidx)
## [androidX 迁移库版本](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/releases/tag/2.9.47-androidx)

# 如何使用它来创建Adapter?
![demo](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/demo_res/item_view.png)
Expand Down Expand Up @@ -272,6 +272,8 @@ public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter<Multiple
case MultipleItem.IMG:
helper.setImageUrl(R.id.iv, item.getContent());
break;
default:
break;
}
}

Expand Down Expand Up @@ -352,7 +354,7 @@ public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter<MultiItemEn
protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
switch (holder.getItemViewType()) {
case TYPE_LEVEL_0:
....

//set view content
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -371,6 +373,8 @@ public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter<MultiItemEn
case TYPE_PERSON:
//just set the content
break;
default:
break;
}
}
```
Expand Down Expand Up @@ -491,6 +495,32 @@ mAdapter.setNewDiffData(callback);
mAdapter.notifyItemChanged(0, "payload info");
```

## 异步Diff & 原始DiffUtil.Callback
用户可以直接使用`DiffUtil.Callback`,自己进行diff计算,将结果告知adapter即可。
所以adapter并不关心diff计算过程,用户可以同步或是异步进行。
使用如下方法:
```java
setNewDiffData(DiffUtil.DiffResult, List)}
```
例子:
```java
new Thread(new Runnable() {
@Override
public void run() {
final List<DiffUtilDemoEntity> newData = getNewList();
MyDiffCallback callback = new MyDiffCallback(newData, mAdapter.getData());
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(callback, false);
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.setNewDiffData(diffResult, newData);
}
});
}
}).start();
```
>警告:你应该自己进行多线程管理,防止内存泄漏


>**持续更新!,所以推荐Star项目**

Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ kotlin demo :[BRVAH_kotlin](https://github.com/AllenCoder/BRVAH_kotlin)
## [androidX stable version ](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/releases/tag/2.9.45-androidx)
# Document
- [English](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/wiki)
- [中文](http://www.jianshu.com/p/b343fcff51b0)
- [中文1](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/README-cn.md)
- [中文2](http://www.jianshu.com/p/b343fcff51b0)

## [UI](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/694)
## Demo
Expand All @@ -20,17 +21,10 @@ kotlin demo :[BRVAH_kotlin](https://github.com/AllenCoder/BRVAH_kotlin)
[国内下载地址](https://fir.im/s91g)

# proguard-rules.pro
```
-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers class **$** extends com.chad.library.adapter.base.BaseViewHolder {
<init>(...);
}
-keepattributes InnerClasses
```
> 此资源库自带混淆规则,并且会自动导入,正常情况下无需手动导入。
> The library comes with `proguard-rules.pro` rules and is automatically imported. Normally no manual import is required.
> You can also go here to view [proguard-rules](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/library/proguard-rules.pro)

# Extension library
[PinnedSectionItemDecoration](https://github.com/oubowu/PinnedSectionItemDecoration)
Expand Down
8 changes: 0 additions & 8 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,3 @@
# public *;
#}
#BaseRecyclerViewAdapterHelper
-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers public class * extends com.chad.library.adapter.base.BaseViewHolder {
<init>(android.view.View);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.os.Bundle;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

Expand Down Expand Up @@ -61,8 +59,34 @@ private void initClick() {
itemChangeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DiffDemoCallback callback = new DiffDemoCallback(getNewList());
List<DiffUtilDemoEntity> newData = getNewList();
DiffDemoCallback callback = new DiffDemoCallback(newData);
mAdapter.setNewDiffData(callback);

/*
Use async example.
The user performs the diff calculation in the child thread and informs the adapter of the result.
Warning: You should do multi-thread management yourself to prevent memory leaks.
异步使用diff刷新
用户自己在子线程中进行diff计算,将结果告知adapter即可
警告:你应该自己进行多线程管理,防止内存泄漏
*/
// new Thread(new Runnable() {
// @Override
// public void run() {
// final List<DiffUtilDemoEntity> newData = getNewList();
// MyDiffCallback callback = new MyDiffCallback(newData, mAdapter.getData());
// final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(callback, false);
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// mAdapter.setNewDiffData(diffResult, newData);
// }
// });
// }
// }).start();

}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.data.DataServer;
import com.chad.baserecyclerviewadapterhelper.entity.Status;
Expand All @@ -29,7 +31,7 @@ public AnimationAdapter() {
}

@Override
protected void convert(BaseViewHolder helper, Status item) {
protected void convert(@NonNull BaseViewHolder helper, Status item) {
helper.addOnClickListener(R.id.img).addOnClickListener(R.id.tweetName);
switch (helper.getLayoutPosition() % 3) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chad.baserecyclerviewadapterhelper.adapter;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import android.view.View;
Expand Down Expand Up @@ -29,7 +30,7 @@ public DataBindingUseAdapter(int layoutResId, List<Movie> data) {
}

@Override
protected void convert(MovieViewHolder helper, Movie item) {
protected void convert(@NonNull MovieViewHolder helper, Movie item) {
ViewDataBinding binding = helper.getBinding();
binding.setVariable(BR.movie, item);
binding.setVariable(BR.presenter, mPresenter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.entity.Level0Item;
import com.chad.baserecyclerviewadapterhelper.entity.Level1Item;
Expand Down Expand Up @@ -39,7 +41,7 @@ public ExpandableItemAdapter(List<MultiItemEntity> data) {


@Override
protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
protected void convert(@NonNull final BaseViewHolder holder, final MultiItemEntity item) {
switch (holder.getItemViewType()) {
case TYPE_LEVEL_0:
switch (holder.getLayoutPosition() % 3) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.chad.baserecyclerviewadapterhelper.adapter;


import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.data.DataServer;
import com.chad.baserecyclerviewadapterhelper.entity.Status;
Expand All @@ -16,7 +19,7 @@ public HeaderAndFooterAdapter(int dataSize) {
}

@Override
protected void convert(BaseViewHolder helper, Status item) {
protected void convert(@NonNull BaseViewHolder helper, Status item) {
switch (helper.getLayoutPosition() %
3) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.chad.baserecyclerviewadapterhelper.adapter;


import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.entity.HomeItem;
import com.chad.library.adapter.base.BaseQuickAdapter;
Expand All @@ -16,7 +19,7 @@ public HomeAdapter(int layoutResId, List data) {
}

@Override
protected void convert(BaseViewHolder helper, HomeItem item) {
protected void convert(@NonNull BaseViewHolder helper, HomeItem item) {
helper.setText(R.id.text, item.getTitle());
helper.setImageResource(R.id.icon, item.getImageResource());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chad.baserecyclerviewadapterhelper.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
Expand Down Expand Up @@ -33,7 +34,7 @@ public ItemClickAdapter(List<ClickEntity> data) {


@Override
protected void convert(final BaseViewHolder helper, final ClickEntity item) {
protected void convert(@NonNull final BaseViewHolder helper, final ClickEntity item) {
switch (helper.getItemViewType()) {
case ClickEntity.CLICK_ITEM_VIEW:
helper.addOnClickListener(R.id.btn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chad.baserecyclerviewadapterhelper.adapter;

import androidx.annotation.NonNull;
import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
Expand All @@ -15,7 +16,7 @@ public ItemDragAdapter(List data) {
}

@Override
protected void convert(BaseViewHolder helper, String item) {
protected void convert(@NonNull BaseViewHolder helper, 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
@@ -1,7 +1,7 @@
package com.chad.baserecyclerviewadapterhelper.adapter;

import android.content.Context;

import androidx.annotation.NonNull;
import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.entity.MultipleItem;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
Expand All @@ -23,7 +23,7 @@ public MultipleItemQuickAdapter(Context context, List data) {
}

@Override
protected void convert(BaseViewHolder helper, MultipleItem item) {
protected void convert(@NonNull BaseViewHolder helper, MultipleItem item) {
switch (helper.getItemViewType()) {
case MultipleItem.TEXT:
helper.setText(R.id.tv, item.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.data.DataServer;
import com.chad.baserecyclerviewadapterhelper.entity.Status;
Expand All @@ -29,7 +31,7 @@ public NestAdapter() {
}

@Override
protected void convert(BaseViewHolder helper, Status item) {
protected void convert(@NonNull BaseViewHolder helper, Status item) {
helper.addOnClickListener(R.id.tweetText);
switch (helper.getLayoutPosition() % 3) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.entity.Status;
import com.chad.baserecyclerviewadapterhelper.util.SpannableStringUtils;
Expand All @@ -28,7 +30,7 @@ public PullToRefreshAdapter() {
}

@Override
protected void convert(BaseViewHolder helper, Status item) {
protected void convert(@NonNull BaseViewHolder helper, 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
@@ -1,5 +1,7 @@
package com.chad.baserecyclerviewadapterhelper.adapter;


import androidx.annotation.NonNull;
import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.data.DataServer;
import com.chad.baserecyclerviewadapterhelper.entity.Status;
Expand All @@ -16,7 +18,7 @@ public QuickAdapter(int dataSize) {
}

@Override
protected void convert(BaseViewHolder helper, Status item) {
protected void convert(@NonNull BaseViewHolder helper, 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
@@ -1,5 +1,7 @@
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;
Expand Down Expand Up @@ -33,7 +35,7 @@ protected void convertHead(BaseViewHolder helper, final MySection item) {


@Override
protected void convert(BaseViewHolder helper, MySection item) {
protected void convert(@NonNull BaseViewHolder helper, MySection item) {
Video video = (Video) item.t;
switch (helper.getLayoutPosition() % 2) {
case 0:
Expand Down
Loading

0 comments on commit a2a824f

Please sign in to comment.