From 9cda44ee99192d52cb950310b0a2a0cd6a632d82 Mon Sep 17 00:00:00 2001 From: JinJieGu <1015121748@qq.com> Date: Fri, 9 Dec 2016 11:20:23 +0800 Subject: [PATCH] Update SwipeToLoadLayout.java add a switcher whither hiding headerView/footView when refreshing/loadingmore. I think keep the headerView/footView while refreshing/loadingmore is not good for user, so I add this switcher to give more choices. I give the switcher a false default, so it won't change it if u don't set it true. please merge it , thank u~ --- .../swipetoloadlayout/SwipeToLoadLayout.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java b/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java index 9233ab0..d6b1e79 100644 --- a/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java +++ b/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java @@ -140,6 +140,18 @@ public class SwipeToLoadLayout extends ViewGroup { */ private boolean mLoadMoreEnabled = true; + /** + * a switcher whither hiding headerView when refreshing + */ + + private boolean isHideHeaderWhenRefreshing = false; + + /** + * a switcher whither hiding footerView when loadingmore + */ + + private boolean isHideFooterWhenLoadingMore = false; + /** * ATTRIBUTE: * the style default classic @@ -496,6 +508,19 @@ public boolean onInterceptTouchEvent(MotionEvent event) { if (mActivePointerId == INVALID_POINTER) { return false; } + + //hide headerView when refreshing , it will improve the user experience + if (mHasHeaderView && isRefreshing() && isHideHeaderWhenRefreshing){ + mRefreshCallback.onReset(); + scrollRefreshingToDefault(); + } + + //hide footerView when loadingmore , it will improve the user experience + if (mHasFooterView && isLoadingMore() && isHideFooterWhenLoadingMore){ + mLoadMoreCallback.onReset(); + scrollLoadingMoreToDefault(); + } + float y = getMotionEventY(event, mActivePointerId); float x = getMotionEventX(event, mActivePointerId); final float yInitDiff = y - mInitDownY; @@ -513,6 +538,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) { // intercept the move action event and pass it to SwipeToLoadLayout#onTouchEvent() return true; } + break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(event); @@ -538,6 +564,7 @@ public boolean onTouchEvent(MotionEvent event) { return true; case MotionEvent.ACTION_MOVE: + // take over the ACTION_MOVE event from SwipeToLoadLayout#onInterceptTouchEvent() // if condition is true final float y = getMotionEventY(event, mActivePointerId); @@ -687,6 +714,24 @@ public boolean isLoadingMore() { return STATUS.isLoadingMore(mStatus); } + /** + * a switcher whither hiding headerView when refreshing + * + * @param hideable + */ + public void setHideHeaderWhenRefreshing(boolean hideable) { + this.isHideHeaderWhenRefreshing = hideable; + } + + /** + * a switcher whither hiding footerView when loadingmore + * + * @param hideable + */ + public void setHideFooterWhenLoadingMore(boolean hideable) { + this.isHideFooterWhenLoadingMore = hideable; + } + /** * set refresh header view, the view must at lease be an implement of {@code SwipeRefreshTrigger}. * the view can also implement {@code SwipeTrigger} for more extension functions