diff options
Diffstat (limited to 'OpenKeychain/src/main/java')
3 files changed, 81 insertions, 38 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/KeyUpdateHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/KeyUpdateHelper.java index 2d7d452b7..bd565fccf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/KeyUpdateHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/KeyUpdateHelper.java @@ -44,7 +44,7 @@ public class KeyUpdateHelper { public ImportKeysListEntry getKeyByFingerprint(Context context, String fingerprint) { String[] servers = Preferences.getPreferences(context).getKeyServers(); - if (servers != null && servers.length != 0) { + if (servers != null && servers.length != 0 && servers[0] != null) { try { HkpKeyserver hkp = new HkpKeyserver(servers[0]); for (ImportKeysListEntry key : hkp.search("0x" + fingerprint)) { @@ -72,28 +72,31 @@ public class KeyUpdateHelper { protected Void doInBackground(Void... voids) { ProviderHelper providerHelper = new ProviderHelper(mContext); List<ImportKeysListEntry> keys = new ArrayList<ImportKeysListEntry>(); - - // Load all the fingerprints in the database and prepare to import them - for(String fprint : providerHelper.getAllFingerprints(KeychainContract.KeyRings.buildUnifiedKeyRingsUri())) { - ImportKeysListEntry key = getKeyByFingerprint(mContext, fprint); - if(key != null) { + String[] servers = Preferences.getPreferences(mContext).getKeyServers(); + + if (servers != null && servers.length > 0) { + // Load all the fingerprints in the database and prepare to import them + for (String fprint : providerHelper.getAllFingerprints(KeychainContract.KeyRings.buildUnifiedKeyRingsUri())) { + ImportKeysListEntry key = new ImportKeysListEntry(); + key.setFingerprintHex(fprint); + key.setBitStrength(1337); + key.setOrigin(servers[0]); 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); + // 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); + 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); + importIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, new Messenger(mHandler)); + mContext.startService(importIntent); + } return null; } } 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 065ed5841..4fda4cede 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -57,6 +57,7 @@ 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; @@ -137,6 +138,13 @@ public class KeyListFragment extends LoaderFragment 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 */ 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 3b6f7d7f3..58e8e81e9 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 @@ -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; 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; + /** - * A StickyListHeadersListView whose parent view is this SwipeRefreshLayout + * Constructors */ - private StickyListHeadersListView mStickyListHeadersListView; - 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) { - // 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 + if (mStickyListHeadersListView == null) return super.canChildScrollUp(); - } + + return ( + mIsLocked + || + ( + mStickyListHeadersListView.getWrappedList().getChildCount() > 0 + && + ( + mStickyListHeadersListView.getTop() > 0 + || + mStickyListHeadersListView.getFirstVisiblePosition() > 0 + ) + ) + ); } }
\ No newline at end of file |