Skip to content

Commit

Permalink
fix load more data function bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklygaj committed Mar 27, 2017
1 parent f9152b9 commit 496b474
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions library/src/main/java/com/ajguan/library/EasyRefreshLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.os.Build;
import android.os.Handler;

import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.GridLayoutManager;
Expand Down Expand Up @@ -39,7 +41,7 @@ public class EasyRefreshLayout extends ViewGroup {
private static long SHOW_COMPLETED_TIME = 500;
private static long SCROLL_TO_LOADING_DURATION = 500;
private static long SHOW_SCROLL_DOWN_DURATION = 300;
private double pull_resistance = 2.0f;
private double pull_resistance = 2.0f;

private State state = State.RESET;

Expand Down Expand Up @@ -77,6 +79,8 @@ public class EasyRefreshLayout extends ViewGroup {
private View mLoadMoreView;
private boolean isLoadingFail = false;
private boolean isEnableLoadMore = true;
private float offsetY;
private float yDiff;

public EasyRefreshLayout(Context context) {
this(context, null);
Expand Down Expand Up @@ -146,7 +150,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// int expandParentHeight = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
// super.onMeasure(widthMeasureSpec, expandParentHeight);

super.onMeasure(widthMeasureSpec,heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (contentView == null) {
initContentView();
}
Expand Down Expand Up @@ -300,8 +304,8 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
float x = ev.getX(MotionEventCompat.findPointerIndex(ev, activePointerId));
float y = ev.getY(MotionEventCompat.findPointerIndex(ev, activePointerId));
float xDiff = x - lastMotionX;
float yDiff = y - lastMotionY;
float offsetY = yDiff * DRAG_RATE;
yDiff = y - lastMotionY;
offsetY = yDiff * DRAG_RATE;
lastMotionX = x;
lastMotionY = y;
if (Math.abs(xDiff) > touchSlop /*&& isInterceptMoveEvent*/) {
Expand Down Expand Up @@ -684,6 +688,12 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
Log.i(TAG,"yDiff:"+yDiff);
if (yDiff > 0 || Math.abs(yDiff) < touchSlop) {
return;
}


if (newState == RecyclerView.SCROLL_STATE_IDLE && !isLoading && isEnableLoadMore && !isRefreshing && !isLoadingFail && !isNotMoreLoading) {
final int lastVisibleItem = getLastVisiBleItem();
int totalItemCount = mRecyclerView.getLayoutManager().getItemCount();
Expand Down Expand Up @@ -726,21 +736,21 @@ public void onAnimationUpdate(ValueAnimator animation) {
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (easyEvent != null) {
easyEvent.onLoadMore();
}
}
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (easyEvent != null) {
easyEvent.onLoadMore();
}
}
}

);
animator.setDuration(SCROLL_TO_LOADING_DURATION);
animator.start();
);
animator.setDuration(SCROLL_TO_LOADING_DURATION);
animator.start();


}
}

private void hideLoadView() {
// setTargetOffsetTopAndBottom( mLoadMoreView.getMeasuredHeight());
Expand Down Expand Up @@ -951,17 +961,17 @@ public boolean isLoading() {
return isLoading;
}

public interface LoadMoreEvent {
/***
* 加载更多
*/
void onLoadMore();
}
public interface LoadMoreEvent {
/***
* 加载更多
*/
void onLoadMore();
}

public interface Event {
void complete();
public interface Event {
void complete();

}
}

public long getShowLoadViewAnimatorDuration() {
return SCROLL_TO_LOADING_DURATION;
Expand Down Expand Up @@ -996,15 +1006,16 @@ public void setHideLoadViewAnimatorDuration(long showCompletedTime) {
}


public double getPullResistance() {
public double getPullResistance() {
return this.pull_resistance;
}

/**
* Set the pull-down refresh resistance factor
*
* @param PullResistance resistance factor
*/
public void setPullResistance(double PullResistance) {
public void setPullResistance(double PullResistance) {
this.pull_resistance = PullResistance;
}
}

0 comments on commit 496b474

Please sign in to comment.