mirror of https://github.com/M66B/FairEmail.git
Fixed back pressed callback ordering
This commit is contained in:
parent
d494c31e3c
commit
025803894d
|
@ -490,7 +490,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
setBackPressedCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (Helper.isKeyboardVisible(view))
|
||||
|
|
|
@ -22,7 +22,6 @@ package eu.faircode.email;
|
|||
import static android.app.ActionBar.DISPLAY_SHOW_CUSTOM;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.RecoverableSecurityException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
@ -37,7 +36,6 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.ResultReceiver;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -48,6 +46,7 @@ import android.widget.ScrollView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
@ -59,6 +58,8 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentResultListener;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -420,6 +421,23 @@ public class FragmentBase extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
protected void setBackPressedCallback(OnBackPressedCallback backPressedCallback) {
|
||||
backPressedCallback.setEnabled(false);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null)
|
||||
return;
|
||||
activity.getOnBackPressedDispatcher().addCallback(backPressedCallback);
|
||||
getViewLifecycleOwner().getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
public void onAny() {
|
||||
Lifecycle.State state = getViewLifecycleOwner().getLifecycle().getCurrentState();
|
||||
backPressedCallback.setEnabled(state.isAtLeast(Lifecycle.State.STARTED));
|
||||
if (state.isAtLeast(Lifecycle.State.DESTROYED))
|
||||
backPressedCallback.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isPane() {
|
||||
Bundle args = getArguments();
|
||||
return (args != null && args.getBoolean("pane"));
|
||||
|
|
|
@ -1053,7 +1053,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
});
|
||||
|
||||
addKeyPressedListener(onKeyPressedListener);
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), backPressedCallback);
|
||||
setBackPressedCallback(backPressedCallback);
|
||||
|
||||
// Initialize
|
||||
setHasOptionsMenu(true);
|
||||
|
|
|
@ -238,7 +238,7 @@ public class FragmentFolder extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
setBackPressedCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (Helper.isKeyboardVisible(view))
|
||||
|
|
|
@ -491,7 +491,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
setBackPressedCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (Helper.isKeyboardVisible(view))
|
||||
|
|
|
@ -1629,7 +1629,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
});
|
||||
|
||||
addKeyPressedListener(keyPressedListener);
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), backPressedCallback);
|
||||
setBackPressedCallback(backPressedCallback);
|
||||
|
||||
// Initialize
|
||||
FragmentDialogTheme.setBackground(getContext(), view, false);
|
||||
|
|
|
@ -275,7 +275,7 @@ public class FragmentPop extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
getActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
setBackPressedCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (Helper.isKeyboardVisible(view))
|
||||
|
|
Loading…
Reference in New Issue