Merge pull request #2206 from k9mail/fix-cancel-crypto
Fix consecutive retrying of crypto operations
This commit is contained in:
commit
fc6d5188f7
2 changed files with 16 additions and 5 deletions
|
@ -258,7 +258,7 @@ public class MessageLoaderHelper {
|
|||
// process with crypto helper
|
||||
|
||||
private void startOrResumeCryptoOperation() {
|
||||
RetainFragment<MessageCryptoHelper> retainCryptoHelperFragment = getMessageCryptoHelperRetainFragment();
|
||||
RetainFragment<MessageCryptoHelper> retainCryptoHelperFragment = getMessageCryptoHelperRetainFragment(true);
|
||||
if (retainCryptoHelperFragment.hasData()) {
|
||||
messageCryptoHelper = retainCryptoHelperFragment.getData();
|
||||
} else {
|
||||
|
@ -270,7 +270,7 @@ public class MessageLoaderHelper {
|
|||
}
|
||||
|
||||
private void cancelAndClearCryptoOperation() {
|
||||
RetainFragment<MessageCryptoHelper> retainCryptoHelperFragment = getMessageCryptoHelperRetainFragment();
|
||||
RetainFragment<MessageCryptoHelper> retainCryptoHelperFragment = getMessageCryptoHelperRetainFragment(false);
|
||||
if (retainCryptoHelperFragment != null) {
|
||||
if (retainCryptoHelperFragment.hasData()) {
|
||||
messageCryptoHelper = retainCryptoHelperFragment.getData();
|
||||
|
@ -281,8 +281,12 @@ public class MessageLoaderHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private RetainFragment<MessageCryptoHelper> getMessageCryptoHelperRetainFragment() {
|
||||
private RetainFragment<MessageCryptoHelper> getMessageCryptoHelperRetainFragment(boolean createIfNotExists) {
|
||||
if (createIfNotExists) {
|
||||
return RetainFragment.findOrCreate(fragmentManager, "crypto_helper_" + messageReference.hashCode());
|
||||
} else {
|
||||
return RetainFragment.findOrNull(fragmentManager, "crypto_helper_" + messageReference.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
private MessageCryptoCallback messageCryptoCallback = new MessageCryptoCallback() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.os.Bundle;
|
|||
|
||||
public class RetainFragment<T> extends Fragment {
|
||||
private T data;
|
||||
private boolean cleared;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -30,11 +31,16 @@ public class RetainFragment<T> extends Fragment {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public static <T> RetainFragment<T> findOrNull(FragmentManager fm, String tag) {
|
||||
// noinspection unchecked, we know this is the the right type
|
||||
return (RetainFragment<T>) fm.findFragmentByTag(tag);
|
||||
}
|
||||
|
||||
public static <T> RetainFragment<T> findOrCreate(FragmentManager fm, String tag) {
|
||||
// noinspection unchecked, we know this is the the right type
|
||||
RetainFragment<T> retainFragment = (RetainFragment<T>) fm.findFragmentByTag(tag);
|
||||
|
||||
if (retainFragment == null) {
|
||||
if (retainFragment == null || retainFragment.cleared) {
|
||||
retainFragment = new RetainFragment<>();
|
||||
fm.beginTransaction()
|
||||
.add(retainFragment, tag)
|
||||
|
@ -46,6 +52,7 @@ public class RetainFragment<T> extends Fragment {
|
|||
|
||||
public void clearAndRemove(FragmentManager fm) {
|
||||
data = null;
|
||||
cleared = true;
|
||||
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1 && fm.isDestroyed()) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue