diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/livedata/KeyInfoInteractor.java
similarity index 74%
rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyLoader.java
rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/livedata/KeyInfoInteractor.java
index ac30275a7..173e58ac5 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyLoader.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/livedata/KeyInfoInteractor.java
@@ -15,7 +15,7 @@
* along with this program. If not, see .
*/
-package org.sufficientlysecure.keychain.remote.ui.dialog;
+package org.sufficientlysecure.keychain.livedata;
import java.util.ArrayList;
@@ -23,19 +23,17 @@ import java.util.Collections;
import java.util.List;
import android.content.ContentResolver;
-import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.Nullable;
-import android.support.v4.content.AsyncTaskLoader;
import com.google.auto.value.AutoValue;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeyInfo;
+import org.sufficientlysecure.keychain.util.DatabaseUtil;
-public class KeyLoader extends AsyncTaskLoader> {
+public class KeyInfoInteractor {
// These are the rows that we will retrieve.
private String[] QUERY_PROJECTION = new String[]{
KeyRings._ID,
@@ -61,29 +59,27 @@ public class KeyLoader extends AsyncTaskLoader> {
private static final int INDEX_EMAIL = 8;
private static final int INDEX_COMMENT = 9;
- private static final String QUERY_WHERE = Tables.KEYS + "." + KeyRings.IS_REVOKED +
+ private static final String QUERY_WHERE_ALL = Tables.KEYS + "." + KeyRings.IS_REVOKED +
" = 0 AND " + KeyRings.IS_EXPIRED + " = 0";
+ private static final String QUERY_WHERE_SECRET = Tables.KEYS + "." + KeyRings.IS_REVOKED +
+ " = 0 AND " + KeyRings.IS_EXPIRED + " = 0" + " AND " + KeyRings.HAS_ANY_SECRET + " != 0";
private static final String QUERY_ORDER = Tables.KEYS + "." + KeyRings.CREATION + " DESC";
private final ContentResolver contentResolver;
- private final KeySelector keySelector;
- private List cachedResult;
-
- KeyLoader(Context context, ContentResolver contentResolver, KeySelector keySelector) {
- super(context);
+ public KeyInfoInteractor(ContentResolver contentResolver) {
this.contentResolver = contentResolver;
- this.keySelector = keySelector;
}
- @Override
- public List loadInBackground() {
+ public List loadKeyInfo(KeySelector keySelector) {
ArrayList keyInfos = new ArrayList<>();
Cursor cursor;
+ String selection = keySelector.isOnlySecret() ? QUERY_WHERE_SECRET : QUERY_WHERE_ALL;
String additionalSelection = keySelector.getSelection();
- String selection = QUERY_WHERE + (additionalSelection != null ? " AND " + additionalSelection : "");
+
+ selection = DatabaseUtil.concatenateWhere(selection, additionalSelection);
cursor = contentResolver.query(keySelector.getKeyRingUri(), QUERY_PROJECTION, selection, null, QUERY_ORDER);
if (cursor == null) {
@@ -98,33 +94,6 @@ public class KeyLoader extends AsyncTaskLoader> {
return Collections.unmodifiableList(keyInfos);
}
- @Override
- public void deliverResult(List keySubkeyStatus) {
- cachedResult = keySubkeyStatus;
-
- if (isStarted()) {
- super.deliverResult(keySubkeyStatus);
- }
- }
-
- @Override
- protected void onStartLoading() {
- if (cachedResult != null) {
- deliverResult(cachedResult);
- }
-
- if (takeContentChanged() || cachedResult == null) {
- forceLoad();
- }
- }
-
- @Override
- protected void onStopLoading() {
- super.onStopLoading();
-
- cachedResult = null;
- }
-
@AutoValue
public abstract static class KeyInfo {
public abstract long getMasterKeyId();
@@ -153,7 +122,7 @@ public class KeyLoader extends AsyncTaskLoader> {
String email = cursor.getString(INDEX_EMAIL);
String comment = cursor.getString(INDEX_COMMENT);
- return new AutoValue_KeyLoader_KeyInfo(
+ return new AutoValue_KeyInfoInteractor_KeyInfo(
masterKeyId, creationDate, hasEncrypt, hasAuthenticate, hasAnySecret, isVerified, name, email, comment);
}
}
@@ -163,9 +132,14 @@ public class KeyLoader extends AsyncTaskLoader> {
public abstract Uri getKeyRingUri();
@Nullable
public abstract String getSelection();
+ public abstract boolean isOnlySecret();
- static KeySelector create(Uri keyRingUri, String selection) {
- return new AutoValue_KeyLoader_KeySelector(keyRingUri, selection);
+ public static KeySelector create(Uri keyRingUri, String selection) {
+ return new AutoValue_KeyInfoInteractor_KeySelector(keyRingUri, selection, false);
+ }
+
+ public static KeySelector createOnlySecret(Uri keyRingUri, String selection) {
+ return new AutoValue_KeyInfoInteractor_KeySelector(keyRingUri, selection, true);
}
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyInfoLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyInfoLoader.java
new file mode 100644
index 000000000..31c87ac58
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/KeyInfoLoader.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 Schürmann & Breitmoser GbR
+ *
+ * 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 .
+ */
+
+package org.sufficientlysecure.keychain.remote.ui.dialog;
+
+
+import java.util.List;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.support.v4.content.AsyncTaskLoader;
+
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeyInfo;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeySelector;
+
+
+public class KeyInfoLoader extends AsyncTaskLoader> {
+ private final KeySelector keySelector;
+
+ private List cachedResult;
+ private KeyInfoInteractor keyInfoInteractor;
+
+ KeyInfoLoader(Context context, ContentResolver contentResolver, KeySelector keySelector) {
+ super(context);
+
+ this.keySelector = keySelector;
+ this.keyInfoInteractor = new KeyInfoInteractor(contentResolver);
+ }
+
+ @Override
+ public List loadInBackground() {
+ return keyInfoInteractor.loadKeyInfo(keySelector);
+ }
+
+ @Override
+ public void deliverResult(List keySubkeyStatus) {
+ cachedResult = keySubkeyStatus;
+
+ if (isStarted()) {
+ super.deliverResult(keySubkeyStatus);
+ }
+ }
+
+ @Override
+ protected void onStartLoading() {
+ if (cachedResult != null) {
+ deliverResult(cachedResult);
+ }
+
+ if (takeContentChanged() || cachedResult == null) {
+ forceLoad();
+ }
+ }
+
+ @Override
+ protected void onStopLoading() {
+ super.onStopLoading();
+
+ cachedResult = null;
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicateActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicateActivity.java
index e1fd3edd4..adb079821 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicateActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicateActivity.java
@@ -51,7 +51,7 @@ import android.widget.TextView;
import com.mikepenz.materialdrawer.util.KeyboardUtil;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.remote.ui.RemoteSecurityTokenOperationActivity;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeyInfo;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeyInfo;
import org.sufficientlysecure.keychain.remote.ui.dialog.RemoteDeduplicatePresenter.RemoteDeduplicateView;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicatePresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicatePresenter.java
index 4717f7da5..ffda9a81d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicatePresenter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteDeduplicatePresenter.java
@@ -33,8 +33,8 @@ import android.support.v4.content.Loader;
import org.sufficientlysecure.keychain.provider.AutocryptPeerDataAccessObject;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeyInfo;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeySelector;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeyInfo;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeySelector;
import timber.log.Timber;
@@ -95,7 +95,7 @@ class RemoteDeduplicatePresenter implements LoaderCallbacks> {
KeySelector keySelector = KeySelector.create(
KeyRings.buildUnifiedKeyRingsFindByEmailUri(duplicateAddress), null);
- return new KeyLoader(context, context.getContentResolver(), keySelector);
+ return new KeyInfoLoader(context, context.getContentResolver(), keySelector);
}
@Override
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyActivity.java
index 73ef66dee..367fc496b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyActivity.java
@@ -54,7 +54,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.remote.ui.RemoteSecurityTokenOperationActivity;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeyInfo;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeyInfo;
import org.sufficientlysecure.keychain.remote.ui.dialog.RemoteSelectAuthenticationKeyPresenter.RemoteSelectAuthenticationKeyView;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyPresenter.java
index 2bbe57e92..c9e0f70b0 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyPresenter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/dialog/RemoteSelectAuthenticationKeyPresenter.java
@@ -18,6 +18,8 @@
package org.sufficientlysecure.keychain.remote.ui.dialog;
+import java.util.List;
+
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -29,12 +31,10 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeyInfo;
-import org.sufficientlysecure.keychain.remote.ui.dialog.KeyLoader.KeySelector;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeyInfo;
+import org.sufficientlysecure.keychain.livedata.KeyInfoInteractor.KeySelector;
import timber.log.Timber;
-import java.util.List;
-
class RemoteSelectAuthenticationKeyPresenter implements LoaderCallbacks> {
private final PackageManager packageManager;
@@ -84,7 +84,7 @@ class RemoteSelectAuthenticationKeyPresenter implements LoaderCallbacks