diff options
author | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-06-23 23:03:59 +0530 |
---|---|---|
committer | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-06-27 01:20:23 +0530 |
commit | 5a5d66009f22eb93874acd369443acb25700456c (patch) | |
tree | 61075ed2235a9c651b8cfb84160ded39028cc679 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | 6008353df8f8d17795fadb5a34fc86ad5a8f2de9 (diff) | |
download | open-keychain-5a5d66009f22eb93874acd369443acb25700456c.tar.gz open-keychain-5a5d66009f22eb93874acd369443acb25700456c.tar.bz2 open-keychain-5a5d66009f22eb93874acd369443acb25700456c.zip |
added export and upload to KeychainNewService
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java | 86 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java | 88 |
2 files changed, 90 insertions, 84 deletions
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 ebbd01afe..7a580c541 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -35,15 +35,18 @@ import org.spongycastle.bcpg.sig.KeyFlags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.EditKeyResult; +import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; @@ -63,6 +66,8 @@ public class CreateKeyFinalFragment extends Fragment { SaveKeyringParcel mSaveKeyringParcel; + private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mOperationHelper; + public static CreateKeyFinalFragment newInstance() { CreateKeyFinalFragment frag = new CreateKeyFinalFragment(); @@ -134,6 +139,9 @@ public class CreateKeyFinalFragment extends Fragment { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (mOperationHelper != null) { + mOperationHelper.handleActivityResult(requestCode, resultCode, data); + } switch (requestCode) { case REQUEST_EDIT_KEY: { if (resultCode == Activity.RESULT_OK) { @@ -249,58 +257,58 @@ public class CreateKeyFinalFragment extends Fragment { // TODO move into EditKeyOperation private void uploadKey(final EditKeyResult saveKeyResult) { - // Send all information needed to service to upload key in other thread - final Intent intent = new Intent(getActivity(), KeychainService.class); - - intent.setAction(KeychainService.ACTION_UPLOAD_KEYRING); // set data uri as path to keyring - Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri( + final Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri( saveKeyResult.mMasterKeyId); - intent.setData(blobUri); - - // fill values for this action - Bundle data = new Bundle(); - // upload to favorite keyserver - String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); - data.putString(KeychainService.UPLOAD_KEY_SERVER, keyserver); + final String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); - intent.putExtra(KeychainService.EXTRA_DATA, data); + CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> callback + = new CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult>() { - ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) { @Override - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); + public ExportKeyringParcel createOperationInput() { + return new ExportKeyringParcel(keyserver, blobUri); + } - if (message.arg1 == MessageStatus.OKAY.ordinal()) { - // TODO: upload operation needs a result! - // TODO: then combine these results - //if (result.getResult() == OperationResultParcel.RESULT_OK) { - //Notify.create(getActivity(), R.string.key_send_success, - //Notify.Style.OK).show(); - - Intent data = new Intent(); - data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); - getActivity().setResult(Activity.RESULT_OK, data); - getActivity().finish(); - } + @Override + public void onCryptoOperationSuccess(ExportResult result) { + // TODO: upload operation needs a result! + // TODO: then combine these results (saveKeyResult and update op result) + //if (result.getResult() == OperationResultParcel.RESULT_OK) { + //Notify.create(getActivity(), R.string.key_send_success, + //Notify.Style.OK).show(); + + Intent data = new Intent(); + data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); + getActivity().setResult(Activity.RESULT_OK, data); + getActivity().finish(); } - }; - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger); + @Override + public void onCryptoOperationCancelled() { - // show progress dialog - saveHandler.showProgressDialog( - getString(R.string.progress_uploading), - ProgressDialog.STYLE_HORIZONTAL, false); + } - // start service with intent - getActivity().startService(intent); + @Override + public void onCryptoOperationError(ExportResult result) { + + // TODO: upload operation needs a result! + // TODO: then combine these results (saveKeyResult and update op result) + //if (result.getResult() == OperationResultParcel.RESULT_OK) { + //Notify.create(getActivity(), R.string.key_send_success, + //Notify.Style.OK).show(); + + Intent data = new Intent(); + data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); + getActivity().setResult(Activity.RESULT_OK, data); + getActivity().finish(); + } + }; + mOperationHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_uploading); + mOperationHelper.cryptoOperation(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index e4dff6083..554aa43a8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -17,12 +17,9 @@ package org.sufficientlysecure.keychain.ui; -import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; import android.support.v4.app.NavUtils; import android.view.MenuItem; import android.view.View; @@ -33,23 +30,31 @@ import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.ui.base.BaseActivity; -import org.sufficientlysecure.keychain.service.ServiceProgressHandler; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; /** * Sends the selected public key to a keyserver */ -public class UploadKeyActivity extends BaseActivity { +public class UploadKeyActivity extends BaseActivity + implements CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> { private View mUploadButton; private Spinner mKeyServerSpinner; private Uri mDataUri; + // CryptoOperationHelper.Callback vars + private String mKeyserver; + private Uri mUnifiedKeyringUri; + private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mUploadOpHelper; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -89,51 +94,23 @@ public class UploadKeyActivity extends BaseActivity { setContentView(R.layout.upload_key_activity); } - private void uploadKey() { - // Send all information needed to service to upload key in other thread - Intent intent = new Intent(this, KeychainService.class); - - intent.setAction(KeychainService.ACTION_UPLOAD_KEYRING); + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (mUploadOpHelper != null) { + mUploadOpHelper.handleActivityResult(requestCode, resultCode, data); + } + super.onActivityResult(requestCode, resultCode, data); + } - // set data uri as path to keyring + private void uploadKey() { Uri blobUri = KeyRings.buildUnifiedKeyRingUri(mDataUri); - intent.setData(blobUri); - - // fill values for this action - Bundle data = new Bundle(); + mUnifiedKeyringUri = blobUri; String server = (String) mKeyServerSpinner.getSelectedItem(); - data.putString(KeychainService.UPLOAD_KEY_SERVER, server); - - intent.putExtra(KeychainService.EXTRA_DATA, data); - - // Message is received after uploading is done in KeychainService - ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) { - @Override - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - if (message.arg1 == MessageStatus.OKAY.ordinal()) { - - Toast.makeText(UploadKeyActivity.this, R.string.msg_crt_upload_success, - Toast.LENGTH_SHORT).show(); - finish(); - } - } - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger); + mKeyserver = server; - // show progress dialog - saveHandler.showProgressDialog( - getString(R.string.progress_uploading), - ProgressDialog.STYLE_HORIZONTAL, false); - - // start service with intent - startService(intent); + mUploadOpHelper = new CryptoOperationHelper(this, this, R.string.progress_uploading); + mUploadOpHelper.cryptoOperation(); } @Override @@ -148,4 +125,25 @@ public class UploadKeyActivity extends BaseActivity { } return super.onOptionsItemSelected(item); } + + @Override + public ExportKeyringParcel createOperationInput() { + return new ExportKeyringParcel(mKeyserver, mUnifiedKeyringUri); + } + + @Override + public void onCryptoOperationSuccess(ExportResult result) { + Toast.makeText(UploadKeyActivity.this, R.string.msg_crt_upload_success, + Toast.LENGTH_SHORT).show(); + } + + @Override + public void onCryptoOperationCancelled() { + + } + + @Override + public void onCryptoOperationError(ExportResult result) { + // TODO: Implement proper log for key upload then show error + } } |