From b0a1ac3ee4b8fe55be116d6d020f94ab4d9f77da Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 8 Sep 2023 09:46:24 +0200 Subject: [PATCH] Fixed caret direction when in-call bottom sheet is opened by dragging the handle --- .../ui/voip/fragment/ActiveCallFragment.kt | 31 +++++++++++++++---- .../ui/voip/viewmodel/CurrentCallViewModel.kt | 6 +++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/voip/fragment/ActiveCallFragment.kt b/app/src/main/java/org/linphone/ui/voip/fragment/ActiveCallFragment.kt index 024e6033d..982ea5525 100644 --- a/app/src/main/java/org/linphone/ui/voip/fragment/ActiveCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/voip/fragment/ActiveCallFragment.kt @@ -143,14 +143,33 @@ class ActiveCallFragment : GenericCallFragment() { binding.chronometer.start() } - callViewModel.isActionsMenuExpanded.observe(viewLifecycleOwner) { expanded -> - val standardBottomSheetBehavior = BottomSheetBehavior.from(binding.bottomBar.root) - if (expanded) { - standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED - } else { - standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + val standardBottomSheetBehavior = BottomSheetBehavior.from(binding.bottomBar.root) + callViewModel.toggleExtraActionsBottomSheetEvent.observe(viewLifecycleOwner) { + it.consume { + val state = standardBottomSheetBehavior.state + if (state == BottomSheetBehavior.STATE_COLLAPSED) { + standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + } else if (state == BottomSheetBehavior.STATE_EXPANDED) { + standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + } } } + + standardBottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onStateChanged(bottomSheet: View, newState: Int) { + when (newState) { + BottomSheetBehavior.STATE_COLLAPSED -> { + callViewModel.isActionsMenuExpanded.value = false + } + BottomSheetBehavior.STATE_EXPANDED -> { + callViewModel.isActionsMenuExpanded.value = true + } + else -> {} + } + } + + override fun onSlide(bottomSheet: View, slideOffset: Float) {} + }) } override fun onResume() { diff --git a/app/src/main/java/org/linphone/ui/voip/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/voip/viewmodel/CurrentCallViewModel.kt index 47b7d7134..c1a756ecc 100644 --- a/app/src/main/java/org/linphone/ui/voip/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/voip/viewmodel/CurrentCallViewModel.kt @@ -86,6 +86,10 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { val isActionsMenuExpanded = MutableLiveData() + val toggleExtraActionsBottomSheetEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + private lateinit var call: Call private val callListener = object : CallListenerStub() { @@ -302,7 +306,7 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { @UiThread fun toggleExpandActionsMenu() { - isActionsMenuExpanded.value = isActionsMenuExpanded.value == false + toggleExtraActionsBottomSheetEvent.value = Event(true) } @WorkerThread