made CryptoOperationFragment implement OperationHelper.Callback

This commit is contained in:
Adithya Abraham Philip
2015-06-30 20:22:00 +05:30
parent 4b2e85794f
commit 51d3daeccd
11 changed files with 32 additions and 58 deletions

View File

@@ -295,7 +295,7 @@ public class CertifyKeyFragment
}
@Override
protected CertifyActionsParcel createOperationInput() {
public CertifyActionsParcel createOperationInput() {
// Bail out if there is not at least one user id selected
ArrayList<CertifyAction> certifyActions = mUserIdsAdapter.getSelectedCertifyActions();
@@ -318,7 +318,7 @@ public class CertifyKeyFragment
}
@Override
protected void onCryptoOperationSuccess(CertifyResult result) {
public void onCryptoOperationSuccess(CertifyResult result) {
Intent intent = new Intent();
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
getActivity().setResult(Activity.RESULT_OK, intent);
@@ -326,7 +326,7 @@ public class CertifyKeyFragment
}
@Override
protected void onCryptoOperationCancelled() {
public void onCryptoOperationCancelled() {
super.onCryptoOperationCancelled();
}

View File

@@ -151,12 +151,12 @@ public class CreateKeyFinalFragment
}
@Override
protected SaveKeyringParcel createOperationInput() {
public SaveKeyringParcel createOperationInput() {
return mSaveKeyringParcel;
}
@Override
protected void onCryptoOperationSuccess(EditKeyResult result) {
public void onCryptoOperationSuccess(EditKeyResult result) {
if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) {
// result will be displayed after upload
uploadKey(result);

View File

@@ -211,12 +211,12 @@ public class CreateKeyYubiKeyImportFragment
}
@Override
protected ImportKeyringParcel createOperationInput() {
public ImportKeyringParcel createOperationInput() {
return new ImportKeyringParcel(mKeyList, mKeyserver);
}
@Override
protected void onCryptoOperationSuccess(ImportKeyResult result) {
public void onCryptoOperationSuccess(ImportKeyResult result) {
long[] masterKeyIds = result.getImportedMasterKeyIds();
if (masterKeyIds.length == 0) {
super.onCryptoOperationError(result);

View File

@@ -254,12 +254,12 @@ public class DecryptListFragment
}
@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);
return true;
}
@Override
protected void onCryptoOperationError(DecryptVerifyResult result) {
public void onCryptoOperationError(DecryptVerifyResult result) {
final Uri uri = mCurrentInputUri;
mCurrentInputUri = null;
@@ -269,7 +269,7 @@ public class DecryptListFragment
}
@Override
protected void onCryptoOperationSuccess(DecryptVerifyResult result) {
public void onCryptoOperationSuccess(DecryptVerifyResult result) {
Uri uri = mCurrentInputUri;
mCurrentInputUri = null;
@@ -433,7 +433,7 @@ public class DecryptListFragment
}
@Override
protected PgpDecryptVerifyInputParcel createOperationInput() {
public PgpDecryptVerifyInputParcel createOperationInput() {
if (mCurrentInputUri == null) {
if (mPendingInputUris.isEmpty()) {

View File

@@ -607,12 +607,12 @@ public class EditKeyFragment extends CryptoOperationFragment<SaveKeyringParcel,
}
@Override
protected SaveKeyringParcel createOperationInput() {
public SaveKeyringParcel createOperationInput() {
return mSaveKeyringParcel;
}
@Override
protected void onCryptoOperationSuccess(OperationResult result) {
public void onCryptoOperationSuccess(OperationResult result) {
// if good -> finish, return result to showkey and display there!
Intent intent = new Intent();

View File

@@ -386,7 +386,7 @@ public class EncryptFilesFragment
}
@Override
protected void onCryptoOperationSuccess(final SignEncryptResult result) {
public void onCryptoOperationSuccess(final SignEncryptResult result) {
if (mDeleteAfterEncrypt) {
// TODO make behavior coherent here
@@ -485,7 +485,7 @@ public class EncryptFilesFragment
}
protected SignEncryptParcel createOperationInput() {
public SignEncryptParcel createOperationInput() {
SignEncryptParcel actionsParcel = getCachedActionsParcel();

View File

@@ -202,7 +202,7 @@ public class EncryptTextFragment
}
protected SignEncryptParcel createOperationInput() {
public SignEncryptParcel createOperationInput() {
if (mMessage == null || mMessage.isEmpty()) {
Notify.create(getActivity(), R.string.error_empty_text, Notify.Style.ERROR)
@@ -316,7 +316,7 @@ public class EncryptTextFragment
}
@Override
protected void onCryptoOperationSuccess(SignEncryptResult result) {
public void onCryptoOperationSuccess(SignEncryptResult result) {
if (mShareAfterEncrypt) {
// Share encrypted message/file

View File

@@ -205,7 +205,7 @@ public class ViewKeyYubiKeyFragment
}
@Override
protected PromoteKeyringParcel createOperationInput() {
public PromoteKeyringParcel createOperationInput() {
return new PromoteKeyringParcel(mMasterKeyId, mCardAid, mSubKeyIds);
}

View File

@@ -37,7 +37,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
}
@Override
protected abstract T createOperationInput();
public abstract T createOperationInput();
protected T getCachedActionsParcel() {
return mCachedActionsParcel;
@@ -47,7 +47,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
mCachedActionsParcel = cachedActionsParcel;
}
protected void onCryptoOperationCancelled() {
public void onCryptoOperationCancelled() {
mCachedActionsParcel = null;
}

View File

@@ -29,43 +29,13 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
* All fragments executing crypto operations need to extend this class.
*/
public abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
extends Fragment {
extends Fragment implements CryptoOperationHelper.Callback<T, S> {
private CryptoOperationHelper<T, S> mOperationHelper;
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
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);
mOperationHelper = new CryptoOperationHelper<>(this, this);
}
public void setProgressMessageResource(int id) {
@@ -78,7 +48,8 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
mOperationHelper.handleActivityResult(requestCode, resultCode, data);
}
protected abstract T createOperationInput();
@Override
public abstract T createOperationInput();
protected void cryptoOperation() {
cryptoOperation(new CryptoInputParcel());
@@ -92,19 +63,22 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
mOperationHelper.cryptoOperation(cryptoInput, showProgress);
}
protected boolean onCryptoSetProgress(String msg, int progress, int max) {
public boolean onCryptoSetProgress(String msg, int progress, int max) {
return false;
}
protected void onCryptoOperationError(S result) {
@Override
public void onCryptoOperationError(S result) {
onCryptoOperationResult(result);
result.createNotify(getActivity()).show();
}
protected void onCryptoOperationCancelled() {
@Override
public void onCryptoOperationCancelled() {
}
protected void onCryptoOperationSuccess(S result) {
@Override
public void onCryptoOperationSuccess(S result) {
onCryptoOperationResult(result);
}

View File

@@ -52,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
*/
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();
void onCryptoOperationSuccess(S result);
void onCryptoOperationCancelled();