Skip to content

Commit

Permalink
delay the refreshing anim by 50ms to workaround https://code.google.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Feb 23, 2015
1 parent 153aa40 commit adb0889
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class SwipeToRefreshHelper implements OnRefreshListener {
private SwipeRefreshLayout mSwipeRefreshLayout;
private RefreshListener mRefreshListener;
private boolean mRefreshing;

public interface RefreshListener {
public void onRefreshStarted();
Expand All @@ -33,7 +34,20 @@ public void init(Activity activity, SwipeRefreshLayout swipeRefreshLayout, Refre
}

public void setRefreshing(boolean refreshing) {
mSwipeRefreshLayout.setRefreshing(refreshing);
mRefreshing = refreshing;
// Delayed refresh, if fixes https://code.google.com/p/android/issues/detail?id=77712
// 50ms seems a good compromise (always worked during tests) and fast enough so user can't notice the delay
if (refreshing) {
mSwipeRefreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
// use mRefreshing so if the refresh takes less than 50ms, loading indicator won't show up.
mSwipeRefreshLayout.setRefreshing(mRefreshing);
}
}, 50);
} else {
mSwipeRefreshLayout.setRefreshing(false);
}
}

public boolean isRefreshing() {
Expand Down

0 comments on commit adb0889

Please sign in to comment.