mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Consolidate back callback to a single delegate.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user