use QueueingCryptoOperationFragment in all other places

This commit is contained in:
Vincent Breitmoser
2015-07-07 23:57:12 +02:00
parent 310228f6ba
commit 587e7d088b
5 changed files with 38 additions and 22 deletions

View File

@@ -66,10 +66,10 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
// this import NEEDS to be above the ViewModel one, or it won't compile! (as of 06/06/15)
import org.sufficientlysecure.keychain.ui.base.QueueingCryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.StatusHolder;
import org.sufficientlysecure.keychain.ui.DecryptListFragment.DecryptFilesAdapter.ViewModel;
import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify;
@@ -80,7 +80,7 @@ import org.sufficientlysecure.keychain.util.ParcelableHashMap;
public class DecryptListFragment
extends CryptoOperationFragment<PgpDecryptVerifyInputParcel,DecryptVerifyResult>
extends QueueingCryptoOperationFragment<PgpDecryptVerifyInputParcel,DecryptVerifyResult>
implements OnMenuItemClickListener {
public static final String ARG_INPUT_URIS = "input_uris";
@@ -195,15 +195,6 @@ public class DecryptListFragment
cryptoOperation();
}
private String removeEncryptedAppend(String name) {
if (name.endsWith(Constants.FILE_EXTENSION_ASC)
|| name.endsWith(Constants.FILE_EXTENSION_PGP_MAIN)
|| name.endsWith(Constants.FILE_EXTENSION_PGP_ALTERNATE)) {
return name.substring(0, name.length() - 4);
}
return name;
}
private void askForOutputFilename(Uri inputUri, String originalFilename, String mimeType) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
File file = new File(inputUri.getPath());
@@ -257,7 +248,7 @@ public class DecryptListFragment
return true;
}
@Override
public void onCryptoOperationError(DecryptVerifyResult result) {
public void onQueuedOperationError(DecryptVerifyResult result) {
final Uri uri = mCurrentInputUri;
mCurrentInputUri = null;
@@ -267,7 +258,7 @@ public class DecryptListFragment
}
@Override
public void onCryptoOperationSuccess(DecryptVerifyResult result) {
public void onQueuedOperationSuccess(DecryptVerifyResult result) {
Uri uri = mCurrentInputUri;
mCurrentInputUri = null;

View File

@@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.base.QueueingCryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
@@ -68,7 +68,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
public class EditKeyFragment extends CryptoOperationFragment<SaveKeyringParcel, OperationResult>
public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyringParcel, OperationResult>
implements LoaderManager.LoaderCallbacks<Cursor> {
public static final String ARG_DATA_URI = "uri";
@@ -192,7 +192,7 @@ public class EditKeyFragment extends CryptoOperationFragment<SaveKeyringParcel,
private void loadData(Uri dataUri) {
mDataUri = dataUri;
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
Log.i(Constants.TAG, "mDataUri: " + mDataUri);
// load the secret key ring. we do verify here that the passphrase is correct, so cached won't do
try {
@@ -618,13 +618,16 @@ public class EditKeyFragment extends CryptoOperationFragment<SaveKeyringParcel,
}
@Override
public void onCryptoOperationSuccess(OperationResult result) {
public void onQueuedOperationSuccess(OperationResult result) {
// null-protected from Queueing*Fragment
Activity activity = getActivity();
// if good -> finish, return result to showkey and display there!
Intent intent = new Intent();
intent.putExtra(OperationResult.EXTRA_RESULT, result);
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
getActivity().finish();
activity.setResult(EditKeyActivity.RESULT_OK, intent);
activity.finish();
}

View File

@@ -40,11 +40,12 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.base.QueueingCryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
public class ViewKeyYubiKeyFragment
extends CryptoOperationFragment<PromoteKeyringParcel, PromoteKeyResult>
extends QueueingCryptoOperationFragment<PromoteKeyringParcel, PromoteKeyResult>
implements LoaderCallbacks<Cursor> {
public static final String ARG_MASTER_KEY_ID = "master_key_id";
@@ -214,7 +215,8 @@ public class ViewKeyYubiKeyFragment
}
@Override
public void onCryptoOperationSuccess(PromoteKeyResult result) {
public void onQueuedOperationSuccess(PromoteKeyResult result) {
result.createNotify(getActivity()).show();
}
}

View File

@@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
* @see KeychainService
*
*/
public abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
extends Fragment implements CryptoOperationHelper.Callback<T, S> {
final private CryptoOperationHelper<T, S> mOperationHelper;

View File

@@ -7,12 +7,32 @@ import android.os.Parcelable;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
/** CryptoOperationFragment which calls crypto operation results only while
* attached to Activity.
*
* This subclass of CryptoOperationFragment substitutes the onCryptoOperation*
* methods for onQueuedOperation* ones, which are ensured to be called while
* the fragment is attached to an Activity, possibly delaying the call until
* the Fragment is re-attached.
*
* TODO merge this functionality into CryptoOperationFragment?
*
* @see CryptoOperationFragment
*/
public abstract class QueueingCryptoOperationFragment<T extends Parcelable, S extends OperationResult>
extends CryptoOperationFragment<T,S> {
public static final String ARG_QUEUED_RESULT = "queued_result";
private S mQueuedResult;
public QueueingCryptoOperationFragment() {
super();
}
public QueueingCryptoOperationFragment(Integer initialProgressMsg) {
super(initialProgressMsg);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);