From 0625a16cb5aaef9c31fdbdf7c91210f7bac34558 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 13 Sep 2014 23:32:56 +0200 Subject: [PATCH] Temporary fix for #848, fixed pull2refresh bugs --- .../service/KeychainIntentService.java | 50 +++++++++---------- .../keychain/ui/KeyListFragment.java | 2 +- .../widget/ListAwareSwipeRefreshLayout.java | 10 ++-- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 966c43597..f8ef9b0f6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -641,36 +641,39 @@ public class KeychainIntentService extends IntentService implements Progressable sendErrorToHandler(e); } } else if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action) || ACTION_IMPORT_KEYBASE_KEYS.equals(action)) { - try { - ArrayList entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST); + ArrayList entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST); // this downloads the keys and places them into the ImportKeysListEntry entries String keyServer = data.getString(DOWNLOAD_KEY_SERVER); ArrayList keyRings = new ArrayList(entries.size()); for (ImportKeysListEntry entry : entries) { - Keyserver server; - if (entry.getOrigin() == null) { - server = new HkpKeyserver(keyServer); - } else if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) { - server = new KeybaseKeyserver(); - } else { - server = new HkpKeyserver(entry.getOrigin()); - } + try { + Keyserver server; + if (entry.getOrigin() == null) { + server = new HkpKeyserver(keyServer); + } else if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) { + server = new KeybaseKeyserver(); + } else { + server = new HkpKeyserver(entry.getOrigin()); + } - // if available use complete fingerprint for get request - byte[] downloadedKeyBytes; - if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) { - downloadedKeyBytes = server.get(entry.getExtraData()).getBytes(); - } else if (entry.getFingerprintHex() != null) { - downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes(); - } else { - downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes(); - } + // if available use complete fingerprint for get request + byte[] downloadedKeyBytes; + if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) { + downloadedKeyBytes = server.get(entry.getExtraData()).getBytes(); + } else if (entry.getFingerprintHex() != null) { + downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes(); + } else { + downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes(); + } - // save key bytes in entry object for doing the - // actual import afterwards - keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex())); + // save key bytes in entry object for doing the + // actual import afterwards + keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex())); + } catch (Exception e) { + sendErrorToHandler(e); + } } Intent importIntent = new Intent(this, KeychainIntentService.class); @@ -686,9 +689,6 @@ public class KeychainIntentService extends IntentService implements Progressable onHandleIntent(importIntent); // result is handled in ACTION_IMPORT_KEYRING - } catch (Exception e) { - sendErrorToHandler(e); - } } else if (ACTION_CERTIFY_KEYRING.equals(action)) { try { 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 db5c48da7..84f12522d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -82,7 +82,7 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView; */ public class KeyListFragment extends LoaderFragment implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, - LoaderManager.LoaderCallbacks, NoScrollableSwipeRefreshLayout.OnRefreshListener { + LoaderManager.LoaderCallbacks, ListAwareSwipeRefreshLayout.OnRefreshListener { private KeyListAdapter mAdapter; private StickyListHeadersListView mStickyList; 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 17954f827..7490d69ee 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 @@ -70,9 +70,13 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout return (mIsLocked || ( mStickyListHeadersListView.getWrappedList().getChildCount() > 0 - && (mStickyListHeadersListView.getTop() > 0 - || mStickyListHeadersListView.getFirstVisiblePosition() > 0 - )) + && + ( + mStickyListHeadersListView.getWrappedList().getChildAt(0).getTop() < 0 + || + mStickyListHeadersListView.getFirstVisiblePosition() > 0 + ) + ) ); } } \ No newline at end of file