From adb08894ee05a9345b1b7c3345d7c78780ec23d0 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Mon, 23 Feb 2015 15:53:30 +0100 Subject: [PATCH] delay the refreshing anim by 50ms to workaround https://code.google.com/p/android/issues/detail?id=77712 --- .../android/util/ptr/SwipeToRefreshHelper.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java index 7488c2c85c78..48e29e18d4f2 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java @@ -12,6 +12,7 @@ public class SwipeToRefreshHelper implements OnRefreshListener { private SwipeRefreshLayout mSwipeRefreshLayout; private RefreshListener mRefreshListener; + private boolean mRefreshing; public interface RefreshListener { public void onRefreshStarted(); @@ -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() {