fix drawer layout reacting to back press after rotation
This commit is contained in:
parent
9c95554782
commit
3c207c28b4
|
@ -38,7 +38,7 @@ public class AxolotlDatabaseStore extends AbstractAccountService implements Sign
|
|||
|
||||
@Override
|
||||
public boolean saveIdentity(
|
||||
final SignalProtocolAddress signalProtocolAddress, IdentityKey identityKey) {
|
||||
final SignalProtocolAddress signalProtocolAddress, final IdentityKey identityKey) {
|
||||
final var address = AxolotlAddress.cast(signalProtocolAddress);
|
||||
final boolean isBTBVEnabled = true;
|
||||
return database.runInTransaction(
|
||||
|
|
|
@ -36,6 +36,14 @@ public class OverviewFragment extends Fragment {
|
|||
|
||||
private FragmentOverviewBinding binding;
|
||||
|
||||
final OnBackPressedCallback drawerLayoutOnBackPressedCallback =
|
||||
new OnBackPressedCallback(false) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
binding.drawerLayout.close();
|
||||
}
|
||||
};
|
||||
|
||||
private OverviewViewModel overviewViewModel;
|
||||
|
||||
@Override
|
||||
|
@ -77,31 +85,32 @@ public class OverviewFragment extends Fragment {
|
|||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void configureDrawerLayoutToCloseOnBackPress() {
|
||||
final OnBackPressedCallback onBackPressedCallback =
|
||||
new OnBackPressedCallback(false) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
binding.drawerLayout.close();
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// after rotation (or similar) the drawer layout might get opened in restoreInstanceState
|
||||
// therefor we need to check again if we need to enable the callback
|
||||
this.drawerLayoutOnBackPressedCallback.setEnabled(this.binding.drawerLayout.isOpen());
|
||||
}
|
||||
};
|
||||
|
||||
private void configureDrawerLayoutToCloseOnBackPress() {
|
||||
this.binding.drawerLayout.addDrawerListener(
|
||||
new DrawerLayout.SimpleDrawerListener() {
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
public void onDrawerOpened(final View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
onBackPressedCallback.setEnabled(true);
|
||||
drawerLayoutOnBackPressedCallback.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
public void onDrawerClosed(final View drawerView) {
|
||||
super.onDrawerClosed(drawerView);
|
||||
onBackPressedCallback.setEnabled(false);
|
||||
drawerLayoutOnBackPressedCallback.setEnabled(false);
|
||||
}
|
||||
});
|
||||
requireActivity()
|
||||
.getOnBackPressedDispatcher()
|
||||
.addCallback(getViewLifecycleOwner(), onBackPressedCallback);
|
||||
.addCallback(getViewLifecycleOwner(), this.drawerLayoutOnBackPressedCallback);
|
||||
}
|
||||
|
||||
private boolean onNavigationItemSelected(final MenuItem menuItem) {
|
||||
|
|
Loading…
Reference in a new issue