Skip to content

Commit

Permalink
完成新版 autoRefresh 代码框架开发和测试
Browse files Browse the repository at this point in the history
  • Loading branch information
scwang90 committed Nov 4, 2022
1 parent 26327d6 commit c35291d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public boolean isSupportHorizontalDrag() {
}

@Override
public boolean autoRefresh(int delayed, int duration, float dragRate, boolean animationOnly) {
public boolean autoOpen(int duration, float dragRate, boolean animationOnly) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion refresh-footer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 12
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion refresh-header/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {

minSdkVersion 14
minSdkVersion 12
targetSdkVersion 28

versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public MaterialHeader setScrollableWhenRefreshing(boolean scrollable) {


@Override
public boolean autoRefresh(int delayed, int duration, float dragRate, final boolean animationOnly) {
public boolean autoOpen(int duration, float dragRate, final boolean animationOnly) {
if (mShowBezierWave) {
//如果显示背景,使用旧版的 autoRefresh 动画
return false;
Expand All @@ -375,10 +375,10 @@ public boolean autoRefresh(int delayed, int duration, float dragRate, final bool
circleView.setScaleX(0);
circleView.setScaleY(0);
circleView.setTranslationY(mInitHeight / 2f + mCircleDiameter / 2f);
circleView.animate().scaleX(1).scaleY(1).setStartDelay(delayed).setDuration(duration).setListener(new AnimatorListenerAdapter() {
circleView.animate().scaleX(1).scaleY(1).setDuration(duration).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// mProgress.showArrow(false);
circleView.animate().setListener(null);
mProgress.start();
mKernel.onAutoRefreshAnimationEnd(animation, animationOnly);
}
Expand Down
2 changes: 1 addition & 1 deletion refresh-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 12
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3269,13 +3269,6 @@ public boolean autoRefreshAnimationOnly() {
@Override
public boolean autoRefresh(int delayed, final int duration, final float dragRate,final boolean animationOnly) {
if (mState == RefreshState.None && isEnableRefreshOrLoadMore(mEnableRefresh)) {
setViceState(RefreshState.Refreshing);
if (mRefreshHeader.autoRefresh(delayed, duration, dragRate, animationOnly)) {
/*
* 2022-11-03 添加Header可以自己实现 autoRefresh ,返回true表示支持,返回False表示不支持,使用老版本的 autoRefresh
*/
return true;
}
Runnable runnable = new Runnable() {
@Override
public void run() {
Expand All @@ -3290,6 +3283,13 @@ public void run() {
mLastTouchX = thisView.getMeasuredWidth() / 2f;
mKernel.setState(RefreshState.PullDownToRefresh);

if (mRefreshHeader != null && mRefreshHeader.autoOpen(duration, dragRate, animationOnly)) {
/*
* 2022-11-03 添加Header可以自己实现 autoOpen ,返回true表示支持,返回False表示不支持,使用老版本的 autoOpen
*/
return;
}

reboundAnimator = ValueAnimator.ofInt(mSpinner, (int) (mHeaderHeight * dragRate));
reboundAnimator.setDuration(duration);
reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID));
Expand All @@ -3310,6 +3310,7 @@ public void onAnimationEnd(Animator animation) {
reboundAnimator.start();
}
};
setViceState(RefreshState.Refreshing);
if (delayed > 0) {
mHandler.postDelayed(runnable, delayed);
} else {
Expand Down Expand Up @@ -3382,6 +3383,13 @@ public void run() {
mLastTouchX = thisView.getMeasuredWidth() / 2f;
mKernel.setState(RefreshState.PullUpToLoad);

if (mRefreshFooter != null && mRefreshFooter.autoOpen(duration, dragRate, animationOnly)) {
/*
* 2022-11-03 添加Header可以自己实现 autoOpen ,返回true表示支持,返回False表示不支持,使用老版本的 autoOpen
*/
return;
}

reboundAnimator = ValueAnimator.ofInt(mSpinner, -(int) (mFooterHeight * dragRate));
reboundAnimator.setDuration(duration);
reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID));
Expand All @@ -3396,21 +3404,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
reboundAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation != null && animation.getDuration() == 0) {
return;//0 表示被取消
}
reboundAnimator = null;
if (mRefreshFooter != null) {
if (mState != RefreshState.ReleaseToLoad) {
mKernel.setState(RefreshState.ReleaseToLoad);
}
setStateLoading(!animationOnly);
} else {
/*
* 2019-12-24 修复 mRefreshFooter=null 时状态错乱问题
*/
mKernel.setState(RefreshState.None);
}
mKernel.onAutoLoadMoreAnimationEnd(animation, animationOnly);
}
});
reboundAnimator.start();
Expand Down Expand Up @@ -3913,6 +3907,26 @@ public RefreshKernel onAutoRefreshAnimationEnd(Animator animation, boolean anima
return this;
}

@Override
public RefreshKernel onAutoLoadMoreAnimationEnd(Animator animation, boolean animationOnly) {
if (animation != null && animation.getDuration() == 0) {
return this;//0 表示被取消
}
reboundAnimator = null;
if (mRefreshFooter != null) {
if (mState != RefreshState.ReleaseToLoad) {
this.setState(RefreshState.ReleaseToLoad);
}
SmartRefreshLayout.this.setStateLoading(!animationOnly);
} else {
/*
* 2019-12-24 修复 mRefreshFooter=null 时状态错乱问题
*/
this.setState(RefreshState.None);
}
return this;
}

//</editor-fold>
}
//</editor-fold>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ public interface RefreshInternal extends OnStateChangedListener {
/**
* Display refresh animation, Multifunction.
* 显示刷新动画并且触发刷新事件
* @param delayed 开始延时
* @param duration 拖拽动画持续时间
* @param dragRate 拉拽的高度比率
* @param animationOnly animation only 只有动画
* @return If False is returned, this header does not support automatic refresh
* 返回 False 代表本Header不支持自动刷新
*/
boolean autoRefresh(int delayed, int duration, float dragRate, boolean animationOnly);
boolean autoOpen(int duration, float dragRate, boolean animationOnly);

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ public interface RefreshKernel {
* @return RefreshKernel
*/
RefreshKernel onAutoRefreshAnimationEnd(Animator animation, boolean animationOnly);
/**
* 当 autoLoadMore 动画结束时,处理刷新状态的事件
* @param animation 动画对象
* @param animationOnly 是否只播放动画,不通知事件
* @return RefreshKernel
*/
RefreshKernel onAutoLoadMoreAnimationEnd(Animator animation, boolean animationOnly);
//</editor-fold>
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public boolean setNoMoreData(boolean noMoreData) {
}

@Override
public boolean autoRefresh(int delayed, int duration, float dragRate, boolean animationOnly) {
public boolean autoOpen(int duration, float dragRate, boolean animationOnly) {
return false;
}
}

0 comments on commit c35291d

Please sign in to comment.