johannilsson / android-pulltorefresh

DEPRECATED This project aims to provide a reusable pull to refresh widget for Android.
2.47k stars 1.03k forks source link

The refresh view remains #2

Closed tomoyuki28jp closed 13 years ago

tomoyuki28jp commented 13 years ago

If we scroll fast once from the bottom and it stops on the top, the refresh view remain and nothing will happen.

tomoyuki28jp commented 13 years ago

I found another issue. If there is only one row in ListView, the refresh view never disappear. Is this expected behavior?

johannilsson commented 13 years ago

When reaching the top it should bounce back. That's a bug.

Second issue I'm not sure, I do think that's expected at least that is how the Twitter implementation works which is our current reference.

mattg1981 commented 13 years ago

Add the following code to onScroll(AbsListView, int, int, int) within PullToRefreshListView.java to fix the issue of the refresh view remaining visibly at the top after a fling scroll:

if ( mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING )     {
..
}

// add this code

    else if ( mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 ) {
        scrollListTo( mRefreshViewHeight , 1250 );
    }

EDIT: refined the code a little to take out unneeded statements

MantaMay commented 13 years ago

You can use the SCROLL_STATE_FLING to detect when a fling has occurred, and set a flag that you reset once SCROLL_STATE_FLING has ended. Place this in the onScroll as a conditional, and you will fix this issue. Also you will probably want to impement the same logic in a onTrackBallEvent and setOnKeyListener to make sure the user only fires this with a scroll rather d-pad or track ball.

To make this Android 2.1 compatible use setSelection(int) instead of smoothScrollBy. If you still want a smooth scrolling you can take the time to dispatch a TouchEvent, but this can get ugly. Sorry I haven't provided any code, if you have troubles implementing this yourself let me know and I'll finish it and upload the code.

EDIT: whoops, someone beat me to the SCROLL_STATE_FLING, must've missed this, should've refreshed comments before posting.

johannilsson commented 13 years ago

@mattg1981, @MantaMay Thank you, seems like SCROLL_STATE_FLING solves the problem with the view being visible. Will wrap it up during the weekend.

@MantaMay I've done some test with TouchEvent to simulate a smooth scroll, but never got it to behave as good as I wanted so I gave up and just used scrollBy if smoothScrollBy does not exist. Think it works fairly good but smooth scroll would be preferred though.

mattg1981 commented 13 years ago

Instead of editing my previous post, I thought this was worthy of a new one. To make it feel even more like the Twitter Pull-To-Refresh (ie, on a fling, it is not visible at all when hitting the top, it is only visible when pulling the list down), make these adjustments:

if ( mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING )     {
    mRefreshView.setVisibility( View.VISIBLE );
    ...
}
else if ( mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 ) {
        mRefreshView.setVisibility( View.GONE );
        scrollListTo( mRefreshViewHeight , 1250 );
}
johannilsson commented 13 years ago

Hide the pull to fresh label in a fling, its now only visible when pulling the list down. Thank you mattg1981 and MantaMay for this. Closed by f69140d6ae9b69678c63b32735e85e8730e97992.