Consolidate back callback to a single delegate.

This commit is contained in:
Alex Hart
2025-11-03 15:47:43 -04:00
committed by Michelle Tang
parent 04d8f7d9aa
commit 8c99843b2d
2 changed files with 13 additions and 14 deletions

View File

@@ -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() {

View File

@@ -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
}
}