diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-01 19:49:44 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-01 19:49:44 +0100 |
commit | 0e53d901e6121eec420db5be16ea77e9869503fb (patch) | |
tree | 1090d6fac18e4c7c1d36b97a4c8b61be6cb271ec /OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter | |
parent | 7e634a9930a61bed0f41713ec876c6d31b6d2264 (diff) | |
download | open-keychain-0e53d901e6121eec420db5be16ea77e9869503fb.tar.gz open-keychain-0e53d901e6121eec420db5be16ea77e9869503fb.tar.bz2 open-keychain-0e53d901e6121eec420db5be16ea77e9869503fb.zip |
search works
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter')
2 files changed, 102 insertions, 1 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java index 3ad82ea0b..2ad9cc593 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.adapter; import java.io.Serializable; import java.util.ArrayList; +import java.util.Date; import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPPublicKey; @@ -33,7 +34,7 @@ public class ImportKeysListEntry implements Serializable { public long keyId; public boolean revoked; - // public Date date; + public Date date; // TODO: not displayed public String fingerPrint; public String hexKeyId; public int bitStrength; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java new file mode 100644 index 000000000..22d92c10b --- /dev/null +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de> + * + * 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.adapter; + +import android.content.Context; +import android.support.v4.content.AsyncTaskLoader; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.util.HkpKeyServer; +import org.sufficientlysecure.keychain.util.KeyServer; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; +import java.util.List; + +public class ImportKeysListServerLoader extends AsyncTaskLoader<List<ImportKeysListEntry>> { + Context mContext; + + String mServerQuery; + String mKeyServer; + + ArrayList<ImportKeysListEntry> data = new ArrayList<ImportKeysListEntry>(); + + public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) { + super(context); + mContext = context; + mServerQuery = serverQuery; + mKeyServer = keyServer; + } + + @Override + public List<ImportKeysListEntry> loadInBackground() { + if (mServerQuery == null) { + Log.e(Constants.TAG, "mServerQuery is null!"); + return data; + } + + queryServer(mServerQuery, mKeyServer); + + return data; + } + + @Override + protected void onReset() { + super.onReset(); + + // Ensure the loader is stopped + onStopLoading(); + } + + @Override + protected void onStartLoading() { + forceLoad(); + } + + @Override + protected void onStopLoading() { + cancelLoad(); + } + + @Override + public void deliverResult(List<ImportKeysListEntry> data) { + super.deliverResult(data); + } + + /** + * Query key server + */ + private void queryServer(String query, String keyServer) { + HkpKeyServer server = new HkpKeyServer(keyServer); + try { + ArrayList<ImportKeysListEntry> searchResult = server.search(query); + + // add result to data + data.addAll(searchResult); + } catch (KeyServer.InsufficientQuery e) { + Log.e(Constants.TAG, "InsufficientQuery", e); + } catch (KeyServer.QueryException e) { + Log.e(Constants.TAG, "QueryException", e); + } catch (KeyServer.TooManyResponses e) { + Log.e(Constants.TAG, "TooManyResponses", e); + } + } + +} |