From 47bcc6149e72d4bc354e5065feefcedca6c7db26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 20 Aug 2014 20:08:51 +0200 Subject: [PATCH] return some more results --- .../keychain/ui/CertifyKeyActivity.java | 4 +- .../keychain/ui/CreateKeyFinalFragment.java | 43 ++++++++----------- .../keychain/ui/FirstTimeActivity.java | 12 +++--- .../keychain/ui/KeyListActivity.java | 13 +++++- .../keychain/ui/LogDisplayFragment.java | 1 - .../keychain/ui/ViewKeyActivity.java | 1 + 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java index 323c6a00d..728e6e1e1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java @@ -317,7 +317,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements LoaderManag OperationResultParcel result = new OperationResultParcel(OperationResultParcel.RESULT_OK, null); Intent intent = new Intent(); - intent.putExtra(OperationResults.ImportKeyResult.EXTRA_RESULT, result); + intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); CertifyKeyActivity.this.setResult(RESULT_OK, intent); CertifyKeyActivity.this.finish(); @@ -376,7 +376,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements LoaderManag OperationResultParcel result = new OperationResultParcel(OperationResultParcel.RESULT_OK, null); Intent intent = new Intent(); - intent.putExtra(OperationResults.ImportKeyResult.EXTRA_RESULT, result); + intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); CertifyKeyActivity.this.setResult(RESULT_OK, intent); CertifyKeyActivity.this.finish(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 22c0f7767..076f52a10 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -33,6 +33,7 @@ import android.widget.TextView; import org.spongycastle.bcpg.PublicKeyAlgorithmTags; import org.spongycastle.bcpg.sig.KeyFlags; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.pgp.KeyRing; @@ -42,6 +43,7 @@ import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; +import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; public class CreateKeyFinalFragment extends Fragment { @@ -142,23 +144,18 @@ public class CreateKeyFinalFragment extends Fragment { final OperationResults.SaveKeyringResult result = returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); if (result == null) { + Log.e(Constants.TAG, "result == null"); return; } - if (result.getResult() == OperationResultParcel.RESULT_OK) { - if (mUploadCheckbox.isChecked()) { - // result will be displayed after upload - uploadKey(result); - } else { - // TODO: return result - result.createNotify(getActivity()); - - getActivity().setResult(Activity.RESULT_OK); - getActivity().finish(); - } + if (mUploadCheckbox.isChecked()) { + // result will be displayed after upload + uploadKey(result); } else { - // display result on error without finishing activity - result.createNotify(getActivity()); + Intent data = new Intent(); + data.putExtra(OperationResultParcel.EXTRA_RESULT, result); + getActivity().setResult(Activity.RESULT_OK, data); + getActivity().finish(); } } } @@ -217,20 +214,16 @@ public class CreateKeyFinalFragment extends Fragment { super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - // TODO: not supported by upload? -// if (result.getResult() == OperationResultParcel.RESULT_OK) { - // TODO: return result - editKeyResult.createNotify(getActivity()); + // TODO: upload operation needs a result! + // TODO: then combine these results + //if (result.getResult() == OperationResultParcel.RESULT_OK) { + //Notify.showNotify(getActivity(), R.string.key_send_success, + //Notify.Style.INFO); - Notify.showNotify(getActivity(), R.string.key_send_success, - Notify.Style.INFO); - - getActivity().setResult(Activity.RESULT_OK); + Intent data = new Intent(); + data.putExtra(OperationResultParcel.EXTRA_RESULT, editKeyResult); + getActivity().setResult(Activity.RESULT_OK, data); getActivity().finish(); -// } else { -// // display result on error without finishing activity -// editKeyResult.createNotify(getActivity()); -// } } } }; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java index 5f3f170a1..9811500a2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java @@ -51,7 +51,7 @@ public class FirstTimeActivity extends ActionBarActivity { mSkipSetup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - finishSetup(); + finishSetup(null); } }); @@ -80,18 +80,20 @@ public class FirstTimeActivity extends ActionBarActivity { if (requestCode == REQUEST_CODE_CREATE_OR_IMPORT_KEY) { if (resultCode == RESULT_OK) { - finishSetup(); + finishSetup(data); } } else { Log.e(Constants.TAG, "No valid request code!"); } } - private void finishSetup() { + private void finishSetup(Intent srcData) { Preferences prefs = Preferences.getPreferences(this); prefs.setFirstTime(false); - Intent intent = new Intent(FirstTimeActivity.this, KeyListActivity.class); - startActivity(intent); + Intent intent = new Intent(this, KeyListActivity.class); + // give intent through to display notify + intent.putExtras(srcData); + startActivityForResult(intent, 0); finish(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 0bc98d545..7663b7366 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -145,7 +145,7 @@ public class KeyListActivity extends DrawerActivity { private void createKey() { Intent intent = new Intent(this, CreateKeyActivity.class); - startActivity(intent); + startActivityForResult(intent, 0); } private void consolidate() { @@ -197,4 +197,15 @@ public class KeyListActivity extends DrawerActivity { } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // if a result has been returned, display a notify + if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { + OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + result.createNotify(this).show(); + } else { + super.onActivityResult(requestCode, resultCode, data); + } + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 7b0f3ecff..0e948bf7f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -179,7 +179,6 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener (Integer) entry.mParameters[0], entry.mParameters)); } else { - Log.d(Constants.TAG, "entry.mType.getMsgId() "+entry.mType.name()); ih.mText.setText(getResources().getString(entry.mType.getMsgId(), entry.mParameters)); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 28f7b8bf5..c9db79740 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -313,6 +313,7 @@ public class ViewKeyActivity extends ActionBarActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // if a result has been returned, display a notify if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); result.createNotify(this).show();