made CryptoOperationFragment implement OperationHelper.Callback
This commit is contained in:
@@ -295,7 +295,7 @@ public class CertifyKeyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CertifyActionsParcel createOperationInput() {
|
public CertifyActionsParcel createOperationInput() {
|
||||||
|
|
||||||
// Bail out if there is not at least one user id selected
|
// Bail out if there is not at least one user id selected
|
||||||
ArrayList<CertifyAction> certifyActions = mUserIdsAdapter.getSelectedCertifyActions();
|
ArrayList<CertifyAction> certifyActions = mUserIdsAdapter.getSelectedCertifyActions();
|
||||||
@@ -318,7 +318,7 @@ public class CertifyKeyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(CertifyResult result) {
|
public void onCryptoOperationSuccess(CertifyResult result) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
|
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
|
||||||
getActivity().setResult(Activity.RESULT_OK, intent);
|
getActivity().setResult(Activity.RESULT_OK, intent);
|
||||||
@@ -326,7 +326,7 @@ public class CertifyKeyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationCancelled() {
|
public void onCryptoOperationCancelled() {
|
||||||
super.onCryptoOperationCancelled();
|
super.onCryptoOperationCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,12 +151,12 @@ public class CreateKeyFinalFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SaveKeyringParcel createOperationInput() {
|
public SaveKeyringParcel createOperationInput() {
|
||||||
return mSaveKeyringParcel;
|
return mSaveKeyringParcel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(EditKeyResult result) {
|
public void onCryptoOperationSuccess(EditKeyResult result) {
|
||||||
if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) {
|
if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) {
|
||||||
// result will be displayed after upload
|
// result will be displayed after upload
|
||||||
uploadKey(result);
|
uploadKey(result);
|
||||||
|
|||||||
@@ -211,12 +211,12 @@ public class CreateKeyYubiKeyImportFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ImportKeyringParcel createOperationInput() {
|
public ImportKeyringParcel createOperationInput() {
|
||||||
return new ImportKeyringParcel(mKeyList, mKeyserver);
|
return new ImportKeyringParcel(mKeyList, mKeyserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(ImportKeyResult result) {
|
public void onCryptoOperationSuccess(ImportKeyResult result) {
|
||||||
long[] masterKeyIds = result.getImportedMasterKeyIds();
|
long[] masterKeyIds = result.getImportedMasterKeyIds();
|
||||||
if (masterKeyIds.length == 0) {
|
if (masterKeyIds.length == 0) {
|
||||||
super.onCryptoOperationError(result);
|
super.onCryptoOperationError(result);
|
||||||
|
|||||||
@@ -254,12 +254,12 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCryptoSetProgress(String msg, int progress, int max) {
|
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||||
mAdapter.setProgress(mCurrentInputUri, progress, max, msg);
|
mAdapter.setProgress(mCurrentInputUri, progress, max, msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationError(DecryptVerifyResult result) {
|
public void onCryptoOperationError(DecryptVerifyResult result) {
|
||||||
final Uri uri = mCurrentInputUri;
|
final Uri uri = mCurrentInputUri;
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(DecryptVerifyResult result) {
|
public void onCryptoOperationSuccess(DecryptVerifyResult result) {
|
||||||
Uri uri = mCurrentInputUri;
|
Uri uri = mCurrentInputUri;
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PgpDecryptVerifyInputParcel createOperationInput() {
|
public PgpDecryptVerifyInputParcel createOperationInput() {
|
||||||
|
|
||||||
if (mCurrentInputUri == null) {
|
if (mCurrentInputUri == null) {
|
||||||
if (mPendingInputUris.isEmpty()) {
|
if (mPendingInputUris.isEmpty()) {
|
||||||
|
|||||||
@@ -607,12 +607,12 @@ public class EditKeyFragment extends CryptoOperationFragment<SaveKeyringParcel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SaveKeyringParcel createOperationInput() {
|
public SaveKeyringParcel createOperationInput() {
|
||||||
return mSaveKeyringParcel;
|
return mSaveKeyringParcel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(OperationResult result) {
|
public void onCryptoOperationSuccess(OperationResult result) {
|
||||||
|
|
||||||
// if good -> finish, return result to showkey and display there!
|
// if good -> finish, return result to showkey and display there!
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public class EncryptFilesFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(final SignEncryptResult result) {
|
public void onCryptoOperationSuccess(final SignEncryptResult result) {
|
||||||
|
|
||||||
if (mDeleteAfterEncrypt) {
|
if (mDeleteAfterEncrypt) {
|
||||||
// TODO make behavior coherent here
|
// TODO make behavior coherent here
|
||||||
@@ -485,7 +485,7 @@ public class EncryptFilesFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SignEncryptParcel createOperationInput() {
|
public SignEncryptParcel createOperationInput() {
|
||||||
|
|
||||||
SignEncryptParcel actionsParcel = getCachedActionsParcel();
|
SignEncryptParcel actionsParcel = getCachedActionsParcel();
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ public class EncryptTextFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SignEncryptParcel createOperationInput() {
|
public SignEncryptParcel createOperationInput() {
|
||||||
|
|
||||||
if (mMessage == null || mMessage.isEmpty()) {
|
if (mMessage == null || mMessage.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.error_empty_text, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.error_empty_text, Notify.Style.ERROR)
|
||||||
@@ -316,7 +316,7 @@ public class EncryptTextFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(SignEncryptResult result) {
|
public void onCryptoOperationSuccess(SignEncryptResult result) {
|
||||||
|
|
||||||
if (mShareAfterEncrypt) {
|
if (mShareAfterEncrypt) {
|
||||||
// Share encrypted message/file
|
// Share encrypted message/file
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ public class ViewKeyYubiKeyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PromoteKeyringParcel createOperationInput() {
|
public PromoteKeyringParcel createOperationInput() {
|
||||||
return new PromoteKeyringParcel(mMasterKeyId, mCardAid, mSubKeyIds);
|
return new PromoteKeyringParcel(mMasterKeyId, mCardAid, mSubKeyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected abstract T createOperationInput();
|
public abstract T createOperationInput();
|
||||||
|
|
||||||
protected T getCachedActionsParcel() {
|
protected T getCachedActionsParcel() {
|
||||||
return mCachedActionsParcel;
|
return mCachedActionsParcel;
|
||||||
@@ -47,7 +47,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
|
|||||||
mCachedActionsParcel = cachedActionsParcel;
|
mCachedActionsParcel = cachedActionsParcel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCryptoOperationCancelled() {
|
public void onCryptoOperationCancelled() {
|
||||||
mCachedActionsParcel = null;
|
mCachedActionsParcel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,43 +29,13 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
|||||||
* All fragments executing crypto operations need to extend this class.
|
* All fragments executing crypto operations need to extend this class.
|
||||||
*/
|
*/
|
||||||
public abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
|
public abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
|
||||||
extends Fragment {
|
extends Fragment implements CryptoOperationHelper.Callback<T, S> {
|
||||||
|
|
||||||
private CryptoOperationHelper<T, S> mOperationHelper;
|
private CryptoOperationHelper<T, S> mOperationHelper;
|
||||||
|
|
||||||
public CryptoOperationFragment() {
|
public CryptoOperationFragment() {
|
||||||
// this is implemented here instead of by the fragment so that the corresponding methods in
|
|
||||||
// CryptoOperationFragment may continue using the "protected" modifier.
|
|
||||||
CryptoOperationHelper.Callback callback = new CryptoOperationHelper.Callback<T, S>() {
|
|
||||||
|
|
||||||
@Override
|
mOperationHelper = new CryptoOperationHelper<>(this, this);
|
||||||
public T createOperationInput() {
|
|
||||||
return CryptoOperationFragment.this.createOperationInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCryptoOperationSuccess(S result) {
|
|
||||||
CryptoOperationFragment.this.onCryptoOperationSuccess(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCryptoOperationCancelled() {
|
|
||||||
CryptoOperationFragment.this.onCryptoOperationCancelled();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCryptoOperationError(S result) {
|
|
||||||
CryptoOperationFragment.this.onCryptoOperationError(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
|
||||||
return CryptoOperationFragment.this.onCryptoSetProgress(msg, progress, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
mOperationHelper = new CryptoOperationHelper<>(this, callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressMessageResource(int id) {
|
public void setProgressMessageResource(int id) {
|
||||||
@@ -78,7 +48,8 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
|
|||||||
mOperationHelper.handleActivityResult(requestCode, resultCode, data);
|
mOperationHelper.handleActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract T createOperationInput();
|
@Override
|
||||||
|
public abstract T createOperationInput();
|
||||||
|
|
||||||
protected void cryptoOperation() {
|
protected void cryptoOperation() {
|
||||||
cryptoOperation(new CryptoInputParcel());
|
cryptoOperation(new CryptoInputParcel());
|
||||||
@@ -92,19 +63,22 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
|
|||||||
mOperationHelper.cryptoOperation(cryptoInput, showProgress);
|
mOperationHelper.cryptoOperation(cryptoInput, showProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean onCryptoSetProgress(String msg, int progress, int max) {
|
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCryptoOperationError(S result) {
|
@Override
|
||||||
|
public void onCryptoOperationError(S result) {
|
||||||
onCryptoOperationResult(result);
|
onCryptoOperationResult(result);
|
||||||
result.createNotify(getActivity()).show();
|
result.createNotify(getActivity()).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCryptoOperationCancelled() {
|
@Override
|
||||||
|
public void onCryptoOperationCancelled() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCryptoOperationSuccess(S result) {
|
@Override
|
||||||
|
public void onCryptoOperationSuccess(S result) {
|
||||||
onCryptoOperationResult(result);
|
onCryptoOperationResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class CryptoOperationHelper<T extends Parcelable, S extends OperationResult> {
|
public class CryptoOperationHelper<T extends Parcelable, S extends OperationResult> {
|
||||||
|
|
||||||
public interface Callback <T extends Parcelable, S extends OperationResult> {
|
public interface Callback <T extends Parcelable, S extends OperationResult> {
|
||||||
T createOperationInput();
|
T createOperationInput();
|
||||||
void onCryptoOperationSuccess(S result);
|
void onCryptoOperationSuccess(S result);
|
||||||
void onCryptoOperationCancelled();
|
void onCryptoOperationCancelled();
|
||||||
|
|||||||
Reference in New Issue
Block a user