@@ -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.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.view.ActionMode;
|
||||
@@ -55,9 +56,13 @@ import android.widget.TextView;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.ExportHelper;
|
||||
import org.sufficientlysecure.keychain.helper.KeyUpdateHelper;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.widget.ListAwareSwipeRefreshLayout;
|
||||
import org.sufficientlysecure.keychain.util.Highlighter;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Notify;
|
||||
@@ -74,10 +79,11 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||
*/
|
||||
public class KeyListFragment extends LoaderFragment
|
||||
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
LoaderManager.LoaderCallbacks<Cursor>, SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private KeyListAdapter mAdapter;
|
||||
private StickyListHeadersListView mStickyList;
|
||||
private ListAwareSwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
||||
// saves the mode object for multiselect, needed for reset at some point
|
||||
private ActionMode mActionMode = null;
|
||||
@@ -120,9 +126,25 @@ public class KeyListFragment extends LoaderFragment
|
||||
}
|
||||
});
|
||||
|
||||
mSwipeRefreshLayout = (ListAwareSwipeRefreshLayout) view.findViewById(R.id.key_list_swipe_container);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
mSwipeRefreshLayout.setColorScheme(
|
||||
R.color.android_purple_dark,
|
||||
R.color.android_purple_light,
|
||||
R.color.android_purple_dark,
|
||||
R.color.android_purple_light);
|
||||
mSwipeRefreshLayout.setStickyListHeadersListView(mStickyList);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
String[] servers = Preferences.getPreferences(getActivity()).getKeyServers();
|
||||
mSwipeRefreshLayout.setIsLocked(servers == null || servers.length == 0 || servers[0] == null);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Adapter and Loader on create of Activity
|
||||
*/
|
||||
@@ -690,4 +712,16 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Daniel Albert
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
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 SwipeRefreshLayout {
|
||||
|
||||
|
||||
private StickyListHeadersListView mStickyListHeadersListView = null;
|
||||
private boolean mIsLocked = false;
|
||||
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
public ListAwareSwipeRefreshLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public ListAwareSwipeRefreshLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getters / Setters
|
||||
*/
|
||||
public void setStickyListHeadersListView(StickyListHeadersListView stickyListHeadersListView) {
|
||||
mStickyListHeadersListView = stickyListHeadersListView;
|
||||
}
|
||||
public StickyListHeadersListView getStickyListHeadersListView() {
|
||||
return mStickyListHeadersListView;
|
||||
}
|
||||
|
||||
public void setIsLocked(boolean locked) {
|
||||
mIsLocked = locked;
|
||||
Log.d("ListAwareSwipeRefreshLayout", (mIsLocked ? "is locked" : "not locked"));
|
||||
}
|
||||
public boolean getIsLocked() {
|
||||
return mIsLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canChildScrollUp() {
|
||||
if (mStickyListHeadersListView == null)
|
||||
return super.canChildScrollUp();
|
||||
|
||||
return (
|
||||
mIsLocked
|
||||
||
|
||||
(
|
||||
mStickyListHeadersListView.getWrappedList().getChildCount() > 0
|
||||
&&
|
||||
(
|
||||
mStickyListHeadersListView.getTop() > 0
|
||||
||
|
||||
mStickyListHeadersListView.getFirstVisiblePosition() > 0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user