From ac66f6cc1043cf79896cf063be2358a0b08e2ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 18 Sep 2014 13:55:23 +0200 Subject: [PATCH] Swipe-to-refresh fixes --- .../keychain/ui/KeyListFragment.java | 36 ++++++++++--------- .../widget/ListAwareSwipeRefreshLayout.java | 14 ++------ .../src/main/res/layout/key_list_fragment.xml | 13 +++++-- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index e32677c7a..8603b5e8c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -35,6 +35,7 @@ import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.CursorAdapter; +import android.support.v4.widget.NoScrollableSwipeRefreshLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; @@ -81,7 +82,7 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView; */ public class KeyListFragment extends LoaderFragment implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, - LoaderManager.LoaderCallbacks, ListAwareSwipeRefreshLayout.OnRefreshListener { + LoaderManager.LoaderCallbacks { private KeyListAdapter mAdapter; private StickyListHeadersListView mStickyList; @@ -131,7 +132,19 @@ public class KeyListFragment extends LoaderFragment }); mSwipeRefreshLayout = (ListAwareSwipeRefreshLayout) view.findViewById(R.id.key_list_swipe_container); - mSwipeRefreshLayout.setOnRefreshListener(this); + mSwipeRefreshLayout.setOnRefreshListener(new NoScrollableSwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + KeyUpdateHelper updateHelper = new KeyUpdateHelper(); + KeychainIntentServiceHandler finishedHandler = new KeychainIntentServiceHandler(getActivity()) { + public void handleMessage(Message message) { + mSwipeRefreshLayout.setRefreshing(false); + } + }; + updateHelper.updateAllKeys(getActivity(), finishedHandler); + updateActionbarForSwipe(false); + } + }); mSwipeRefreshLayout.setColorScheme( R.color.android_purple_dark, R.color.android_purple_light, @@ -141,7 +154,7 @@ public class KeyListFragment extends LoaderFragment mSwipeRefreshLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { updateActionbarForSwipe(true); } else { updateActionbarForSwipe(false); @@ -454,6 +467,8 @@ public class KeyListFragment extends LoaderFragment MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { + // disable swipe-to-refresh + mSwipeRefreshLayout.setIsLocked(true); return true; } @@ -461,6 +476,8 @@ public class KeyListFragment extends LoaderFragment public boolean onMenuItemActionCollapse(MenuItem item) { mQuery = null; getLoaderManager().restartLoader(0, null, KeyListFragment.this); + // enable swipe-to-refresh + mSwipeRefreshLayout.setIsLocked(false); return true; } }); @@ -753,17 +770,4 @@ public class KeyListFragment extends LoaderFragment } - /** - * Implements OnRefreshListener for drag-to-refresh - */ - public void onRefresh() { - KeyUpdateHelper updateHelper = new KeyUpdateHelper(); - KeychainIntentServiceHandler finishedHandler = new KeychainIntentServiceHandler(getActivity()) { - public void handleMessage(Message message) { - mSwipeRefreshLayout.setRefreshing(false); - } - }; - updateHelper.updateAllKeys(getActivity(), finishedHandler); - updateActionbarForSwipe(false); - } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java index 7490d69ee..f7d44d2cf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java @@ -19,11 +19,8 @@ package org.sufficientlysecure.keychain.ui.widget; import android.content.Context; import android.support.v4.widget.NoScrollableSwipeRefreshLayout; -import android.support.v4.widget.SwipeRefreshLayout; import android.util.AttributeSet; -import org.sufficientlysecure.keychain.util.Log; - import se.emilsjolander.stickylistheaders.StickyListHeadersListView; public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout { @@ -55,7 +52,6 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout public void setIsLocked(boolean locked) { mIsLocked = locked; - Log.d("ListAwareSwipeRefreshLayout", (mIsLocked ? "is locked" : "not locked")); } public boolean getIsLocked() { @@ -70,13 +66,9 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout return (mIsLocked || ( mStickyListHeadersListView.getWrappedList().getChildCount() > 0 - && - ( - mStickyListHeadersListView.getWrappedList().getChildAt(0).getTop() < 0 - || - mStickyListHeadersListView.getFirstVisiblePosition() > 0 - ) - ) + && (mStickyListHeadersListView.getWrappedList().getChildAt(0).getTop() < 0 + || mStickyListHeadersListView.getFirstVisiblePosition() > 0) + ) ); } } \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/key_list_fragment.xml b/OpenKeychain/src/main/res/layout/key_list_fragment.xml index 6af40106d..69096f03e 100644 --- a/OpenKeychain/src/main/res/layout/key_list_fragment.xml +++ b/OpenKeychain/src/main/res/layout/key_list_fragment.xml @@ -1,6 +1,5 @@ - + + + + + +