Split remote methods from activities for better seperation

This commit is contained in:
Dominik Schürmann
2016-02-15 16:29:23 +01:00
parent eef27a544f
commit 15488c5445
8 changed files with 134 additions and 57 deletions

View File

@@ -57,8 +57,6 @@ public class ImportKeysActivity extends BaseActivity
= Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_FACEBOOK";
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_TO_SERVICE = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN";
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_FILE_AND_RETURN";
@@ -77,10 +75,6 @@ public class ImportKeysActivity extends BaseActivity
public static final String EXTRA_KEY_ID = Constants.EXTRA_PREFIX + "EXTRA_KEY_ID";
public static final String EXTRA_FINGERPRINT = OpenKeychainIntents.IMPORT_KEY_FROM_KEYSERVER_EXTRA_FINGERPRINT;
// only used by ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_TO_SERVICE when used from OpenPgpService
public static final String EXTRA_PENDING_INTENT_DATA = "data";
private Intent mPendingIntentData;
public static final String TAG_FRAG_LIST = "frag_list";
public static final String TAG_FRAG_TOP = "frag_top";
@@ -106,11 +100,6 @@ public class ImportKeysActivity extends BaseActivity
importSelectedKeys();
}
});
// only used for OpenPgpService
if (getIntent().hasExtra(EXTRA_PENDING_INTENT_DATA)) {
mPendingIntentData = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_DATA);
}
}
@Override
@@ -172,7 +161,6 @@ public class ImportKeysActivity extends BaseActivity
break;
}
case ACTION_IMPORT_KEY_FROM_KEYSERVER:
case ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_TO_SERVICE:
case ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT: {
if (extras.containsKey(EXTRA_QUERY) || extras.containsKey(EXTRA_KEY_ID)) {
@@ -412,7 +400,7 @@ public class ImportKeysActivity extends BaseActivity
super.onActivityResult(requestCode, resultCode, data);
}
public void handleResult(ImportKeyResult result) {
protected void handleResult(ImportKeyResult result) {
String intentAction = getIntent().getAction();
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(intentAction)
@@ -424,15 +412,10 @@ public class ImportKeysActivity extends BaseActivity
return;
}
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_TO_SERVICE.equals(intentAction)) {
setResult(RESULT_OK, mPendingIntentData);
finish();
return;
}
result.createNotify(ImportKeysActivity.this)
.show((ViewGroup) findViewById(R.id.import_snackbar));
}
// methods from CryptoOperationHelper.Callback
@Override

View File

@@ -85,9 +85,6 @@ public class PassphraseDialogActivity extends FragmentActivity {
public static final String EXTRA_REQUIRED_INPUT = "required_input";
public static final String EXTRA_CRYPTO_INPUT = "crypto_input";
// special extra for OpenPgpService
public static final String EXTRA_SERVICE_INTENT = "data";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -393,10 +390,10 @@ public class PassphraseDialogActivity extends FragmentActivity {
boolean unlockSucceeded = secretKeyToUnlock.unlock(passphrase);
// if it didn't take that long, give the user time to appreciate the progress bar
long operationTime = System.currentTimeMillis() -timeBeforeOperation;
long operationTime = System.currentTimeMillis() - timeBeforeOperation;
if (operationTime < 100) {
try {
Thread.sleep(100 -operationTime);
Thread.sleep(100 - operationTime);
} catch (InterruptedException e) {
// ignore
}
@@ -467,16 +464,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
// noinspection ConstantConditions, we handle the non-null case in PassphraseDialogActivity.onCreate()
inputParcel.mPassphrase = passphrase;
Intent serviceIntent = getArguments().getParcelable(EXTRA_SERVICE_INTENT);
if (serviceIntent != null) {
CryptoInputParcelCacheService.addCryptoInputParcel(getActivity(), serviceIntent, inputParcel);
getActivity().setResult(RESULT_OK, serviceIntent);
} else {
// also return passphrase back to activity
Intent returnIntent = new Intent();
returnIntent.putExtra(RESULT_CRYPTO_INPUT, inputParcel);
getActivity().setResult(RESULT_OK, returnIntent);
}
((PassphraseDialogActivity) getActivity()).handleResult(inputParcel);
dismiss();
getActivity().finish();
@@ -526,5 +514,11 @@ public class PassphraseDialogActivity extends FragmentActivity {
}
protected void handleResult(CryptoInputParcel inputParcel) {
// also return passphrase back to activity
Intent returnIntent = new Intent();
returnIntent.putExtra(RESULT_CRYPTO_INPUT, inputParcel);
setResult(RESULT_OK, returnIntent);
}
}

View File

@@ -71,7 +71,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
private static final byte[] BLANK_FINGERPRINT = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
protected CryptoInputParcel mInputParcel;
private CryptoInputParcel mInputParcel;
@Override
protected void initTheme() {
@@ -268,7 +268,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
@Override
protected void onNfcPostExecute() {
returnResult();
handleResult(mInputParcel);
// show finish
vAnimator.setDisplayedChild(2);
@@ -299,10 +299,10 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
}.execute();
}
protected void returnResult() {
protected void handleResult(CryptoInputParcel inputParcel) {
Intent result = new Intent();
// send back the CryptoInputParcel we received
result.putExtra(RESULT_CRYPTO_INPUT, mInputParcel);
result.putExtra(RESULT_CRYPTO_INPUT, inputParcel);
setResult(RESULT_OK, result);
}