diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-11-04 00:11:16 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-11-04 00:11:16 +0300 |
commit | d525953eb5163d372c09bd59ca8320bc07258634 (patch) | |
tree | 01fc625cf917de3e425340d7c7c514e5cab3b8ef | |
parent | 6bc01a5d2d348ce10b6fad2bbf82ebc2b27c7cce (diff) |
Make backPressedCallback lifecycle aware
Signed-off-by: Stefan Niedermann <info@niedermann.it>
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java index f46442c9e..e3395ea35 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java @@ -169,7 +169,7 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == STATE_HIDDEN) { - backPressedCallback.remove(); + backPressedCallback.setEnabled(false); hidePicker(); } } @@ -232,6 +232,7 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme } mBottomSheetBehaviour.setState(STATE_HALF_EXPANDED); showPicker(); + backPressedCallback.setEnabled(true); requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), backPressedCallback); }); binding.fab.show(); @@ -264,6 +265,18 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme return binding.getRoot(); } + @Override + public void onPause() { + super.onPause(); + backPressedCallback.setEnabled(false); + } + + @Override + public void onResume() { + super.onResume(); + backPressedCallback.setEnabled(binding.pickerControlsWrapper.getVisibility() == VISIBLE); + } + @RequiresApi(LOLLIPOP) public void pickCamera() { if (isPermissionRequestNeeded(CAMERA)) { |