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
|
@Override
|
||||||
public boolean saveIdentity(
|
public boolean saveIdentity(
|
||||||
final SignalProtocolAddress signalProtocolAddress, IdentityKey identityKey) {
|
final SignalProtocolAddress signalProtocolAddress, final IdentityKey identityKey) {
|
||||||
final var address = AxolotlAddress.cast(signalProtocolAddress);
|
final var address = AxolotlAddress.cast(signalProtocolAddress);
|
||||||
final boolean isBTBVEnabled = true;
|
final boolean isBTBVEnabled = true;
|
||||||
return database.runInTransaction(
|
return database.runInTransaction(
|
||||||
|
|
|
@ -36,6 +36,14 @@ public class OverviewFragment extends Fragment {
|
||||||
|
|
||||||
private FragmentOverviewBinding binding;
|
private FragmentOverviewBinding binding;
|
||||||
|
|
||||||
|
final OnBackPressedCallback drawerLayoutOnBackPressedCallback =
|
||||||
|
new OnBackPressedCallback(false) {
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
binding.drawerLayout.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private OverviewViewModel overviewViewModel;
|
private OverviewViewModel overviewViewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,31 +85,32 @@ public class OverviewFragment extends Fragment {
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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() {
|
private void configureDrawerLayoutToCloseOnBackPress() {
|
||||||
final OnBackPressedCallback onBackPressedCallback =
|
|
||||||
new OnBackPressedCallback(false) {
|
|
||||||
@Override
|
|
||||||
public void handleOnBackPressed() {
|
|
||||||
binding.drawerLayout.close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.binding.drawerLayout.addDrawerListener(
|
this.binding.drawerLayout.addDrawerListener(
|
||||||
new DrawerLayout.SimpleDrawerListener() {
|
new DrawerLayout.SimpleDrawerListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerOpened(View drawerView) {
|
public void onDrawerOpened(final View drawerView) {
|
||||||
super.onDrawerOpened(drawerView);
|
super.onDrawerOpened(drawerView);
|
||||||
onBackPressedCallback.setEnabled(true);
|
drawerLayoutOnBackPressedCallback.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerClosed(View drawerView) {
|
public void onDrawerClosed(final View drawerView) {
|
||||||
super.onDrawerClosed(drawerView);
|
super.onDrawerClosed(drawerView);
|
||||||
onBackPressedCallback.setEnabled(false);
|
drawerLayoutOnBackPressedCallback.setEnabled(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requireActivity()
|
requireActivity()
|
||||||
.getOnBackPressedDispatcher()
|
.getOnBackPressedDispatcher()
|
||||||
.addCallback(getViewLifecycleOwner(), onBackPressedCallback);
|
.addCallback(getViewLifecycleOwner(), this.drawerLayoutOnBackPressedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onNavigationItemSelected(final MenuItem menuItem) {
|
private boolean onNavigationItemSelected(final MenuItem menuItem) {
|
||||||
|
|
Loading…
Reference in a new issue