|
29 | 29 | import android.util.Log; |
30 | 30 | import android.view.View; |
31 | 31 |
|
| 32 | +import androidx.activity.OnBackPressedCallback; |
32 | 33 | import androidx.annotation.ColorInt; |
33 | 34 | import androidx.annotation.NonNull; |
34 | 35 | import androidx.annotation.Nullable; |
@@ -329,6 +330,20 @@ public void onError(@NonNull Throwable t) { |
329 | 330 | menuAdapter.updateAccount(this, nextAccount); |
330 | 331 | } |
331 | 332 | }); |
| 333 | + |
| 334 | + getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { |
| 335 | + @Override |
| 336 | + public void handleOnBackPressed() { |
| 337 | + if (activityBinding.searchToolbar.getVisibility() == VISIBLE) { |
| 338 | + updateToolbars(false); |
| 339 | + } else if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { |
| 340 | + binding.drawerLayout.closeDrawer(GravityCompat.START); |
| 341 | + } else { |
| 342 | + setEnabled(false); |
| 343 | + getOnBackPressedDispatcher().onBackPressed(); |
| 344 | + } |
| 345 | + } |
| 346 | + }); |
332 | 347 | } |
333 | 348 |
|
334 | 349 | private void showAppAccountNotFoundAlertDialog(NextcloudFilesAppAccountNotFoundException e) { |
@@ -802,17 +817,6 @@ public void onNoteFavoriteClick(int position, View view) { |
802 | 817 | }}); |
803 | 818 | } |
804 | 819 |
|
805 | | - @Override |
806 | | - public void onBackPressed() { |
807 | | - if (activityBinding.searchToolbar.getVisibility() == VISIBLE) { |
808 | | - updateToolbars(false); |
809 | | - } else if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { |
810 | | - binding.drawerLayout.closeDrawer(GravityCompat.START); |
811 | | - } else { |
812 | | - super.onBackPressed(); |
813 | | - } |
814 | | - } |
815 | | - |
816 | 820 | private void updateToolbars(boolean enableSearch) { |
817 | 821 | activityBinding.homeToolbar.setVisibility(enableSearch ? GONE : VISIBLE); |
818 | 822 | activityBinding.searchToolbar.setVisibility(enableSearch ? VISIBLE : GONE); |
|
0 commit comments