Skip to content

Commit

Permalink
添加常见问题
Browse files Browse the repository at this point in the history
  • Loading branch information
scwang90 committed Mar 18, 2020
1 parent 1c25092 commit d359895
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 150 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License](https://img.shields.io/badge/License%20-Apache%202-337ab7.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Arsenal](https://img.shields.io/badge/Arsenal%20-%20SmartRefresh-4cae4c.svg)](https://android-arsenal.com/details/1/6001)
[![JCenter](https://img.shields.io/badge/%20JCenter%20-1.1.0-5bc0de.svg)](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
[![JCenter](https://img.shields.io/badge/%20JCenter%20-2.0.0-5bc0de.svg)](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
[![MinSdk](https://img.shields.io/badge/%20MinSdk%20-%2012%2B%20-f0ad4e.svg)](https://android-arsenal.com/api?level=12)
[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20121%20KB-d9534f.svg)](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.0.4)

Expand Down Expand Up @@ -129,6 +129,8 @@ V2.x 版本已经把依赖库拆分成8个包啦,用到的时候自行引用
## 简单用例
#### 1.在 build.gradle 中添加依赖

[【V1.1.0】](https://github.com/scwang90/SmartRefreshLayout/tree/1.x#%E7%AE%80%E5%8D%95%E7%94%A8%E4%BE%8B) 如果正在使用1.x 版本请调转,当前2.0 版本已经重定制,不支持升级,请在新项目中使用。

V2.x 相对于 V1.x 对包名做了修改如:com.scwang.smartrefresh 改为 com.scwang.smart.refresh。
建议在新项目中使用,如果项目升级,java,xml 中都需要做包名替换,比较麻烦。
但主要改动还是对 Smart 进行分包,减小不必要的依赖,比如不使用二级刷新就不依赖,避免代码冗余。
Expand All @@ -137,21 +139,21 @@ V2.x 相对于 V1.x 对包名做了修改如:com.scwang.smartrefresh 改为 co

```
// 注意:分包之后不会有默认的Header和Footer需要手动添加!还是原来的三种方法!
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //核心必须依赖
implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //经典刷新头
implementation 'com.scwang.smart:refresh-header-radar:2.0.0-alpha-1' //雷达刷新头
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0-alpha-1' //虚拟刷新头
implementation 'com.scwang.smart:refresh-header-material:2.0.0-alpha-1' //谷歌刷新头
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0-alpha-1' //二级刷新头
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0-alpha-1' //球脉冲加载
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1' //经典加载
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0' //核心必须依赖
implementation 'com.scwang.smart:refresh-header-classics:2.0.0' //经典刷新头
implementation 'com.scwang.smart:refresh-header-radar:2.0.0' //雷达刷新头
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0' //虚拟刷新头
implementation 'com.scwang.smart:refresh-header-material:2.0.0' //谷歌刷新头
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0' //二级刷新头
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0' //球脉冲加载
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0' //经典加载
```

<!-- // 保留了 com.scwang.smartrefresh 的包名,但不分包 -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0-alpha-1' //各种Header集合 -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0-alpha-1' //各种Footer集合 -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0-alpha-1' //核心、默认Header、默认Footer -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0' //各种Header集合 -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0' //各种Footer集合 -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0' //核心、默认Header、默认Footer -->

如果使用 AndroidX 在 gradle.properties 中添加

Expand Down
24 changes: 12 additions & 12 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License](https://img.shields.io/badge/License%20-Apache%202-337ab7.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Arsenal](https://img.shields.io/badge/Arsenal%20-%20SmartRefresh-4cae4c.svg)](https://android-arsenal.com/details/1/6001)
[![JCenter](https://img.shields.io/badge/%20Jcenter%20-1.1.0-5bc0de.svg)](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
[![JCenter](https://img.shields.io/badge/%20Jcenter%20-2.0.0-5bc0de.svg)](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
[![MinSdk](https://img.shields.io/badge/%20MinSdk%20-%2012%2B%20-f0ad4e.svg)](https://android-arsenal.com/api?level=12)
[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20122%20KB-d9534f.svg)](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.1.0)

Expand Down Expand Up @@ -114,20 +114,20 @@ It is recommended that you copy the source code into the project whenever you ne

```
// Note: There will be no default Header and Footer after subcontracting. It needs to be added manually!
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //core
implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //ClassicsHeader
implementation 'com.scwang.smart:refresh-header-radar:2.0.0-alpha-1' //BezierRadarHeader
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0-alpha-1' //FalsifyHeader
implementation 'com.scwang.smart:refresh-header-material:2.0.0-alpha-1' //MaterialHeader
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0-alpha-1' //TwoLevelHeader
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0-alpha-1' //BallPulseFooter
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1' //ClassicsFooter
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0' //core
implementation 'com.scwang.smart:refresh-header-classics:2.0.0' //ClassicsHeader
implementation 'com.scwang.smart:refresh-header-radar:2.0.0' //BezierRadarHeader
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0' //FalsifyHeader
implementation 'com.scwang.smart:refresh-header-material:2.0.0' //MaterialHeader
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0' //TwoLevelHeader
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0' //BallPulseFooter
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0' //ClassicsFooter
```
<!-- // The package name of `com.scwang.smartrefresh` is retained, but not subcontracted. -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0-alpha-1' //Headers -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0-alpha-1' //Footers -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0-alpha-1' //core、 default Header and Footer -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0' //Headers -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0' //Footers -->
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0' //core、 default Header and Footer -->

If you use AndroidX, add it to gradle.properties

Expand Down
11 changes: 10 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ dependencies {
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'

// implementation project(':refresh-footer')
implementation project(':refresh-footer')
implementation project(':refresh-header')
implementation project(':refresh-layout')
implementation project(':refresh-drawable-path')

implementation project(':refresh-layout-kernel')
implementation project(':refresh-header-classics')
implementation project(':refresh-header-radar')
implementation project(':refresh-header-falsify')
implementation project(':refresh-header-material')
implementation project(':refresh-header-two-level')
implementation project(':refresh-footer-ball')

// implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //核心必须依赖
// implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //经典刷新头
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ org.gradle.jvmargs=-Xmx1536m

SMART_USER=scwang90
SMART_GROUP=com.scwang.smart
SMART_VERSION=2.0.0-alpha-1
SMART_VERSION=2.0.0
SMART_PUBLISH=false
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,24 @@ public ClassicsFooter(Context context, AttributeSet attrs) {
//</editor-fold>

//<editor-fold desc="RefreshFooter">
@Override
public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
if (!mNoMoreData) {
super.onStartAnimator(refreshLayout, height, maxDragHeight);
}
}
// @Override
// public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
// if (!mNoMoreData) {
// super.onStartAnimator(refreshLayout, height, maxDragHeight);
// }
// }

@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
/*
* 2020-5-15 修复BUG
* https://github.com/scwang90/SmartRefreshLayout/issues/1003
* 修复 没有更多数据之后 loading 还在显示问题
*/
super.onFinish(layout, success);
if (!mNoMoreData) {
mTitleText.setText(success ? mTextFinish : mTextFailed);
return super.onFinish(layout, success);
return mFinishDuration;
}
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions refresh-footer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ dependencies {
})
testImplementation 'junit:junit:4.12'

api project(':refresh-footer-ball')
api project(':refresh-footer-classics')
compileOnly project(':refresh-footer-ball')
compileOnly project(':refresh-footer-classics')
compileOnly project(':refresh-layout')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.scwang.smart.refresh.layout.api.RefreshFooter;
import com.scwang.smart.refresh.layout.api.RefreshKernel;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.constant.RefreshState;

/**
* 虚假的 Footer
Expand Down Expand Up @@ -38,11 +37,18 @@ public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDrag
@Override
public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
if (mRefreshKernel != null) {
mRefreshKernel.setState(RefreshState.None);
//onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
//而是先执行一个回弹动画,LoadFinish 是介于 Refreshing 和 None 之间的状态
//LoadFinish 用于在回弹动画结束时候能顺利改变为 None
mRefreshKernel.setState(RefreshState.LoadFinish);
/*
* 2020-3-15 BUG修复
* https://github.com/scwang90/SmartRefreshLayout/issues/1018
* 强化了 closeHeaderOrFooter 的关闭逻辑,帮助 Footer 取消刷新
* FalsifyFooter 是不能触发加载的
*/
layout.closeHeaderOrFooter();
// mRefreshKernel.setState(RefreshState.None);
// //onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
// //而是先执行一个回弹动画,LoadFinish 是介于 Refreshing 和 None 之间的状态
// //LoadFinish 用于在回弹动画结束时候能顺利改变为 None
// mRefreshKernel.setState(RefreshState.LoadFinish);
}
}
//</editor-fold>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.scwang.smart.refresh.header.falsify.FalsifyAbstract;
import com.scwang.smart.refresh.layout.api.RefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.constant.RefreshState;

/**
* 虚假的 Header
Expand All @@ -32,11 +31,18 @@ public FalsifyHeader(Context context, AttributeSet attrs) {
@Override
public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
if (mRefreshKernel != null) {
mRefreshKernel.setState(RefreshState.None);
//onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
//而是先执行一个回弹动画,RefreshFinish 是介于 Refreshing 和 None 之间的状态
//RefreshFinish 用于在回弹动画结束时候能顺利改变为 None
mRefreshKernel.setState(RefreshState.RefreshFinish);
/*
* 2020-3-15 BUG修复
* https://github.com/scwang90/SmartRefreshLayout/issues/1018
* 强化了 closeHeaderOrFooter 的关闭逻辑,帮助 Header 取消刷新
* FalsifyHeader 是不能触发刷新的
*/
layout.closeHeaderOrFooter();
// mRefreshKernel.setState(RefreshState.None);
// //onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
// //而是先执行一个回弹动画,RefreshFinish 是介于 Refreshing 和 None 之间的状态
// //RefreshFinish 用于在回弹动画结束时候能顺利改变为 None
// mRefreshKernel.setState(RefreshState.RefreshFinish);
}
}
//</editor-fold>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TwoLevelHeader extends SimpleComponent implements RefreshHeader, Ne
protected float mMaxRate = 2.5f;
protected float mFloorRate = 1.9f;
protected float mRefreshRate = 1f;
protected boolean mEnableRefresh = true;
protected boolean mEnableTwoLevel = true;
protected boolean mEnablePullToCloseTwoLevel = true;
protected int mFloorDuration = 1000;
Expand All @@ -62,6 +63,7 @@ public TwoLevelHeader(Context context, @Nullable AttributeSet attrs) {
mFloorRate = ta.getFloat(R.styleable.TwoLevelHeader_srlFloorRate, mFloorRate);
mRefreshRate = ta.getFloat(R.styleable.TwoLevelHeader_srlRefreshRate, mRefreshRate);
mFloorDuration = ta.getInt(R.styleable.TwoLevelHeader_srlFloorDuration, mFloorDuration);
mEnableRefresh = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableRefresh, mEnableRefresh);
mEnableTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableTwoLevel, mEnableTwoLevel);
mEnablePullToCloseTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnablePullToCloseTwoLevel, mEnablePullToCloseTwoLevel);

Expand Down Expand Up @@ -162,6 +164,9 @@ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull Refres
final RefreshComponent refreshHeader = mRefreshHeader;
if (refreshHeader != null) {
final OnStateChangedListener listener = mRefreshHeader;
if (newState == RefreshState.ReleaseToRefresh && !mEnableRefresh) {
newState = RefreshState.PullDownToRefresh;
}
listener.onStateChanged(refreshLayout, oldState, newState);
switch (newState) {
case TwoLevelReleased:
Expand Down Expand Up @@ -203,8 +208,10 @@ public void onMoving(boolean isDragging, float percent, int offset, int height,
refreshKernel.setState(RefreshState.ReleaseToTwoLevel);
} else if (mPercent >= mFloorRate && percent < mRefreshRate) {
refreshKernel.setState(RefreshState.PullDownToRefresh);
} else if (mPercent >= mFloorRate && percent < mFloorRate) {
} else if (mPercent >= mFloorRate && percent < mFloorRate && mEnableRefresh) {
refreshKernel.setState(RefreshState.ReleaseToRefresh);
} else if (!mEnableRefresh && refreshKernel.getRefreshLayout().getState() != RefreshState.ReleaseToTwoLevel) {
refreshKernel.setState(RefreshState.PullDownToRefresh);
}
mPercent = percent;
}
Expand Down Expand Up @@ -275,7 +282,7 @@ public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int
* @return TwoLevelHeader
*/
public TwoLevelHeader setRefreshHeader(RefreshHeader header) {
return setRefreshHeader(header, MATCH_PARENT, WRAP_CONTENT);
return setRefreshHeader(header, 0, 0);
}

/**
Expand All @@ -288,15 +295,26 @@ public TwoLevelHeader setRefreshHeader(RefreshHeader header) {
public TwoLevelHeader setRefreshHeader(RefreshHeader header, int width, int height) {
final ViewGroup thisGroup = this;
if (header != null) {
/*
* 2020-3-16 修复 header 中自带 LayoutParams 丢失问题
*/
width = width == 0 ? MATCH_PARENT : width;
height = height == 0 ? WRAP_CONTENT : height;
LayoutParams lp = new LayoutParams(width, height);
Object olp = header.getView().getLayoutParams();
if (olp instanceof LayoutParams) {
lp = ((LayoutParams) olp);
}

RefreshComponent refreshHeader = mRefreshHeader;
if (refreshHeader != null) {
thisGroup.removeView(refreshHeader.getView());
}
refreshHeader = header;
if (refreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) {
thisGroup.addView(refreshHeader.getView(), 0, new LayoutParams(width, height));
thisGroup.addView(refreshHeader.getView(), 0, lp);
} else {
thisGroup.addView(refreshHeader.getView(), thisGroup.getChildCount(), new LayoutParams(width, height));
thisGroup.addView(refreshHeader.getView(), thisGroup.getChildCount(), lp);
}
this.mRefreshHeader = header;
this.mWrappedInternal = header;
Expand Down Expand Up @@ -335,6 +353,16 @@ public TwoLevelHeader setEnablePullToCloseTwoLevel(boolean enabled) {
return this;
}

/**
* 设置是否开启
* @param enabled 刷新功能
* @return TwoLevelHeader
*/
public TwoLevelHeader setEnableRefresh(boolean enabled) {
this.mEnableRefresh = enabled;
return this;
}

/**
* 设置触发二楼的白百分比
* @param rate 比率 要求大于 RefreshRate
Expand Down
1 change: 1 addition & 0 deletions refresh-header-two-level/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<attr name="srlFloorRate" format="float"/>
<attr name="srlRefreshRate" format="float"/>
<attr name="srlFloorDuration" format="integer"/>
<attr name="srlEnableRefresh" format="boolean"/>
<attr name="srlEnableTwoLevel" format="boolean"/>
<attr name="srlEnablePullToCloseTwoLevel" format="boolean"/>
</declare-styleable>
Expand Down
7 changes: 5 additions & 2 deletions refresh-header/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ dependencies {
compileOnly 'com.android.support:support-annotations:28.0.0'
compileOnly 'com.android.support:support-v4:28.0.0'
compileOnly project(':refresh-layout')
api project(':refresh-drawable-path')
api project(':refresh-header-material')
compileOnly project(':refresh-drawable-path')
compileOnly project(':refresh-header-material')

compileOnly project(':refresh-layout-kernel')
compileOnly project(':refresh-header-falsify')
}

//publish {
Expand Down
Loading

0 comments on commit d359895

Please sign in to comment.