Removed unnecessary querying of keyservers, reimplemented the ListAwareSwipeRefreshLayout and implemented a pull-lock in case there are no keyservers
This commit is contained in:
@@ -44,7 +44,7 @@ public class KeyUpdateHelper {
|
|||||||
|
|
||||||
public ImportKeysListEntry getKeyByFingerprint(Context context, String fingerprint) {
|
public ImportKeysListEntry getKeyByFingerprint(Context context, String fingerprint) {
|
||||||
String[] servers = Preferences.getPreferences(context).getKeyServers();
|
String[] servers = Preferences.getPreferences(context).getKeyServers();
|
||||||
if (servers != null && servers.length != 0) {
|
if (servers != null && servers.length != 0 && servers[0] != null) {
|
||||||
try {
|
try {
|
||||||
HkpKeyserver hkp = new HkpKeyserver(servers[0]);
|
HkpKeyserver hkp = new HkpKeyserver(servers[0]);
|
||||||
for (ImportKeysListEntry key : hkp.search("0x" + fingerprint)) {
|
for (ImportKeysListEntry key : hkp.search("0x" + fingerprint)) {
|
||||||
@@ -72,28 +72,31 @@ public class KeyUpdateHelper {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
ProviderHelper providerHelper = new ProviderHelper(mContext);
|
ProviderHelper providerHelper = new ProviderHelper(mContext);
|
||||||
List<ImportKeysListEntry> keys = new ArrayList<ImportKeysListEntry>();
|
List<ImportKeysListEntry> keys = new ArrayList<ImportKeysListEntry>();
|
||||||
|
String[] servers = Preferences.getPreferences(mContext).getKeyServers();
|
||||||
|
|
||||||
// Load all the fingerprints in the database and prepare to import them
|
if (servers != null && servers.length > 0) {
|
||||||
for(String fprint : providerHelper.getAllFingerprints(KeychainContract.KeyRings.buildUnifiedKeyRingsUri())) {
|
// Load all the fingerprints in the database and prepare to import them
|
||||||
ImportKeysListEntry key = getKeyByFingerprint(mContext, fprint);
|
for (String fprint : providerHelper.getAllFingerprints(KeychainContract.KeyRings.buildUnifiedKeyRingsUri())) {
|
||||||
if(key != null) {
|
ImportKeysListEntry key = new ImportKeysListEntry();
|
||||||
|
key.setFingerprintHex(fprint);
|
||||||
|
key.setBitStrength(1337);
|
||||||
|
key.setOrigin(servers[0]);
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the service and update the keys
|
||||||
|
Intent importIntent = new Intent(mContext, KeychainIntentService.class);
|
||||||
|
importIntent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
|
||||||
|
|
||||||
|
Bundle importData = new Bundle();
|
||||||
|
importData.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST,
|
||||||
|
new ArrayList<ImportKeysListEntry>(keys));
|
||||||
|
importIntent.putExtra(KeychainIntentService.EXTRA_DATA, importData);
|
||||||
|
|
||||||
|
importIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, new Messenger(mHandler));
|
||||||
|
|
||||||
|
mContext.startService(importIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the service and update the keys
|
|
||||||
Intent importIntent = new Intent(mContext, KeychainIntentService.class);
|
|
||||||
importIntent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
|
|
||||||
|
|
||||||
Bundle importData = new Bundle();
|
|
||||||
importData.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST,
|
|
||||||
new ArrayList<ImportKeysListEntry>(keys));
|
|
||||||
importIntent.putExtra(KeychainIntentService.EXTRA_DATA, importData);
|
|
||||||
|
|
||||||
importIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, new Messenger(mHandler));
|
|
||||||
|
|
||||||
mContext.startService(importIntent);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.ExportHelper;
|
import org.sufficientlysecure.keychain.helper.ExportHelper;
|
||||||
import org.sufficientlysecure.keychain.helper.KeyUpdateHelper;
|
import org.sufficientlysecure.keychain.helper.KeyUpdateHelper;
|
||||||
|
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
@@ -137,6 +138,13 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
return root;
|
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
|
* Define Adapter and Loader on create of Activity
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,49 +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;
|
package org.sufficientlysecure.keychain.ui.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
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 SwipeRefreshLayout {
|
public class ListAwareSwipeRefreshLayout extends SwipeRefreshLayout {
|
||||||
|
|
||||||
/**
|
|
||||||
* A StickyListHeadersListView whose parent view is this SwipeRefreshLayout
|
|
||||||
*/
|
|
||||||
private StickyListHeadersListView mStickyListHeadersListView;
|
|
||||||
|
|
||||||
|
private StickyListHeadersListView mStickyListHeadersListView = null;
|
||||||
|
private boolean mIsLocked = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructors
|
||||||
|
*/
|
||||||
public ListAwareSwipeRefreshLayout(Context context) {
|
public ListAwareSwipeRefreshLayout(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListAwareSwipeRefreshLayout(Context context, AttributeSet attrs) {
|
public ListAwareSwipeRefreshLayout(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getters / Setters
|
||||||
|
*/
|
||||||
public void setStickyListHeadersListView(StickyListHeadersListView stickyListHeadersListView) {
|
public void setStickyListHeadersListView(StickyListHeadersListView stickyListHeadersListView) {
|
||||||
mStickyListHeadersListView = 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
|
@Override
|
||||||
public boolean canChildScrollUp() {
|
public boolean canChildScrollUp() {
|
||||||
if (mStickyListHeadersListView != null) {
|
if (mStickyListHeadersListView == null)
|
||||||
// In order to scroll a StickyListHeadersListView up:
|
|
||||||
// Firstly, the wrapped ListView must have at least one item
|
|
||||||
return (mStickyListHeadersListView.getListChildCount() > 0) &&
|
|
||||||
// And then, the first visible item must not be the first item
|
|
||||||
((mStickyListHeadersListView.getFirstVisiblePosition() > 0) ||
|
|
||||||
// If the first visible item is the first item,
|
|
||||||
// (we've reached the first item)
|
|
||||||
// make sure that its top must not cross over the padding top of the wrapped ListView
|
|
||||||
(mStickyListHeadersListView.getListChildAt(0).getTop() < 0));
|
|
||||||
|
|
||||||
// If the wrapped ListView is empty or,
|
|
||||||
// the first item is located below the padding top of the wrapped ListView,
|
|
||||||
// we can allow performing refreshing now
|
|
||||||
} else {
|
|
||||||
// Fall back to default implementation
|
|
||||||
return super.canChildScrollUp();
|
return super.canChildScrollUp();
|
||||||
}
|
|
||||||
|
return (
|
||||||
|
mIsLocked
|
||||||
|
||
|
||||||
|
(
|
||||||
|
mStickyListHeadersListView.getWrappedList().getChildCount() > 0
|
||||||
|
&&
|
||||||
|
(
|
||||||
|
mStickyListHeadersListView.getTop() > 0
|
||||||
|
||
|
||||||
|
mStickyListHeadersListView.getFirstVisiblePosition() > 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user