From 8c99843b2d676adbf728a86b1943d4e165f45443 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Mon, 3 Nov 2025 15:47:43 -0400 Subject: [PATCH] Consolidate back callback to a single delegate. --- .../conversation/v2/ConversationFragment.kt | 16 ++++------------ .../conversation/v2/ConversationViewModel.kt | 11 +++++++++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt index 68ff3f67d6..2fc4f8ed59 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt @@ -1120,12 +1120,6 @@ class ConversationFragment : val keyboardEvents = KeyboardEvents() container.addInputListener(keyboardEvents) container.addKeyboardStateListener(keyboardEvents) - requireActivity() - .onBackPressedDispatcher - .addCallback( - viewLifecycleOwner, - keyboardEvents - ) childFragmentManager.setFragmentResultListener(AttachmentKeyboardFragment.RESULT_KEY, viewLifecycleOwner, AttachmentKeyboardFragmentListener()) motionEventRelay.setDrain(MotionEventRelayDrain(this)) @@ -2505,6 +2499,8 @@ class ConversationFragment : searchMenuItem?.collapseActionView() } else if (state.isInActionMode) { finishActionMode() + } else if (state.isMediaKeyboardShowing) { + container.hideInput() } } } @@ -4509,21 +4505,17 @@ class ConversationFragment : } private inner class KeyboardEvents : - OnBackPressedCallback(false), InputAwareConstraintLayout.Listener, InsetAwareConstraintLayout.KeyboardStateListener { - override fun handleOnBackPressed() { - container.hideInput() - } override fun onInputShown() { binding.navBar.setBackgroundColor(ThemeUtil.getThemedColor(requireContext(), R.attr.mediaKeyboardBottomBarBackgroundColor)) - isEnabled = true + viewModel.setIsMediaKeyboardShowing(true) } override fun onInputHidden() { setNavBarBackgroundColor(viewModel.wallpaperSnapshot) - isEnabled = false + viewModel.setIsMediaKeyboardShowing(false) } override fun onKeyboardShown() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index b2e956d57e..73c1999100 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -660,6 +660,12 @@ class ConversationViewModel( } } + fun setIsMediaKeyboardShowing(isMediaKeyboardShowing: Boolean) { + internalBackPressedState.update { + it.copy(isMediaKeyboardShowing = isMediaKeyboardShowing) + } + } + fun toggleVote(poll: PollRecord, pollOption: PollOption, isChecked: Boolean) { viewModelScope.launch(Dispatchers.IO) { val voteCount = if (isChecked) { @@ -685,8 +691,9 @@ class ConversationViewModel( data class BackPressedState( val isReactionDelegateShowing: Boolean = false, val isSearchRequested: Boolean = false, - val isInActionMode: Boolean = false + val isInActionMode: Boolean = false, + val isMediaKeyboardShowing: Boolean = false ) { - fun shouldHandleBackPressed() = isSearchRequested || isReactionDelegateShowing || isInActionMode + fun shouldHandleBackPressed() = isSearchRequested || isReactionDelegateShowing || isInActionMode || isMediaKeyboardShowing } }