Swipe-to-refresh fixes

This commit is contained in:
Dominik Schürmann 2014-09-18 13:55:23 +02:00
parent 91e97d03a1
commit ac66f6cc10
3 changed files with 33 additions and 30 deletions

View File

@ -35,6 +35,7 @@ import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.NoScrollableSwipeRefreshLayout;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
@ -81,7 +82,7 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
*/ */
public class KeyListFragment extends LoaderFragment public class KeyListFragment extends LoaderFragment
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
LoaderManager.LoaderCallbacks<Cursor>, ListAwareSwipeRefreshLayout.OnRefreshListener { LoaderManager.LoaderCallbacks<Cursor> {
private KeyListAdapter mAdapter; private KeyListAdapter mAdapter;
private StickyListHeadersListView mStickyList; private StickyListHeadersListView mStickyList;
@ -131,7 +132,19 @@ public class KeyListFragment extends LoaderFragment
}); });
mSwipeRefreshLayout = (ListAwareSwipeRefreshLayout) view.findViewById(R.id.key_list_swipe_container); 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( mSwipeRefreshLayout.setColorScheme(
R.color.android_purple_dark, R.color.android_purple_dark,
R.color.android_purple_light, R.color.android_purple_light,
@ -141,7 +154,7 @@ public class KeyListFragment extends LoaderFragment
mSwipeRefreshLayout.setOnTouchListener(new View.OnTouchListener() { mSwipeRefreshLayout.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
updateActionbarForSwipe(true); updateActionbarForSwipe(true);
} else { } else {
updateActionbarForSwipe(false); updateActionbarForSwipe(false);
@ -454,6 +467,8 @@ public class KeyListFragment extends LoaderFragment
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() { MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
@Override @Override
public boolean onMenuItemActionExpand(MenuItem item) { public boolean onMenuItemActionExpand(MenuItem item) {
// disable swipe-to-refresh
mSwipeRefreshLayout.setIsLocked(true);
return true; return true;
} }
@ -461,6 +476,8 @@ public class KeyListFragment extends LoaderFragment
public boolean onMenuItemActionCollapse(MenuItem item) { public boolean onMenuItemActionCollapse(MenuItem item) {
mQuery = null; mQuery = null;
getLoaderManager().restartLoader(0, null, KeyListFragment.this); getLoaderManager().restartLoader(0, null, KeyListFragment.this);
// enable swipe-to-refresh
mSwipeRefreshLayout.setIsLocked(false);
return true; 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);
}
} }

View File

@ -19,11 +19,8 @@ package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context; import android.content.Context;
import android.support.v4.widget.NoScrollableSwipeRefreshLayout; import android.support.v4.widget.NoScrollableSwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet; import android.util.AttributeSet;
import org.sufficientlysecure.keychain.util.Log;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView; import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout { public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout {
@ -55,7 +52,6 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout
public void setIsLocked(boolean locked) { public void setIsLocked(boolean locked) {
mIsLocked = locked; mIsLocked = locked;
Log.d("ListAwareSwipeRefreshLayout", (mIsLocked ? "is locked" : "not locked"));
} }
public boolean getIsLocked() { public boolean getIsLocked() {
@ -70,13 +66,9 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout
return (mIsLocked || ( return (mIsLocked || (
mStickyListHeadersListView.getWrappedList().getChildCount() > 0 mStickyListHeadersListView.getWrappedList().getChildCount() > 0
&& && (mStickyListHeadersListView.getWrappedList().getChildAt(0).getTop() < 0
( || mStickyListHeadersListView.getFirstVisiblePosition() > 0)
mStickyListHeadersListView.getWrappedList().getChildAt(0).getTop() < 0 )
||
mStickyListHeadersListView.getFirstVisiblePosition() > 0
)
)
); );
} }
} }

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<org.sufficientlysecure.keychain.ui.widget.ListAwareSwipeRefreshLayout <org.sufficientlysecure.keychain.ui.widget.ListAwareSwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/key_list_swipe_container" android:id="@+id/key_list_swipe_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -9,6 +8,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<se.emilsjolander.stickylistheaders.StickyListHeadersListView <se.emilsjolander.stickylistheaders.StickyListHeadersListView
android:id="@+id/key_list_list" android:id="@+id/key_list_list"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -20,6 +20,7 @@
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="32dp" android:paddingRight="32dp"
android:scrollbarStyle="outsideOverlay" /> android:scrollbarStyle="outsideOverlay" />
<LinearLayout <LinearLayout
android:id="@+id/key_list_empty" android:id="@+id/key_list_empty"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -27,18 +28,21 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical" android:orientation="vertical"
android:visibility="visible"> android:visibility="visible">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:text="@string/key_list_empty_text1" android:text="@string/key_list_empty_text1"
android:textAppearance="?android:attr/textAppearanceLarge" /> android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:text="" android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" /> android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -46,6 +50,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/key_list_empty_text2" android:text="@string/key_list_empty_text2"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<Button <Button
android:id="@+id/key_list_empty_button_create" android:id="@+id/key_list_empty_button_create"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -55,7 +60,8 @@
android:text="@string/key_list_empty_button_create" android:text="@string/key_list_empty_button_create"
android:drawableLeft="@drawable/ic_action_new_account" android:drawableLeft="@drawable/ic_action_new_account"
android:drawablePadding="8dp" android:drawablePadding="8dp"
android:background="@drawable/button_edgy"/> android:background="@drawable/button_edgy" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -63,6 +69,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/key_list_empty_text3" android:text="@string/key_list_empty_text3"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<Button <Button
android:id="@+id/key_list_empty_button_import" android:id="@+id/key_list_empty_button_import"
android:layout_width="wrap_content" android:layout_width="wrap_content"