mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Close search/filter bar with back gesture/button
This commit is contained in:
parent
196a010f36
commit
4978c9a16d
2 changed files with 53 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ import android.view.ViewGroup
|
|||
import android.view.ViewTreeObserver
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.PopupWindow
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.UiThread
|
||||
|
|
@ -310,6 +311,23 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
|
||||
private var bottomSheetReactionsModel: MessageReactionsModel? = null
|
||||
|
||||
private val backPressedCallback = object : OnBackPressedCallback(false) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (viewModel.searchBarVisible.value == true) {
|
||||
viewModel.closeSearchBar()
|
||||
return
|
||||
}
|
||||
|
||||
Log.i("$TAG Search bar is closed, going back")
|
||||
isEnabled = false
|
||||
try {
|
||||
requireActivity().onBackPressedDispatcher.onBackPressed()
|
||||
} catch (ise: IllegalStateException) {
|
||||
Log.w("$TAG Can't go back: $ise")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -826,6 +844,11 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
requireActivity().onBackPressedDispatcher.addCallback(
|
||||
viewLifecycleOwner,
|
||||
backPressedCallback
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
@ -1011,6 +1034,8 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
popupView.setSearchClickListener {
|
||||
Log.i("$TAG Opening search bar")
|
||||
viewModel.openSearchBar()
|
||||
backPressedCallback.isEnabled = true
|
||||
|
||||
popupWindow.dismiss()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.core.view.doOnPreDraw
|
||||
|
|
@ -57,10 +58,33 @@ abstract class AbstractMainFragment : GenericMainFragment() {
|
|||
|
||||
private lateinit var viewModel: AbstractMainViewModel
|
||||
|
||||
private val backPressedCallback = object : OnBackPressedCallback(false) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (viewModel.searchBarVisible.value == true) {
|
||||
viewModel.closeSearchBar()
|
||||
return
|
||||
}
|
||||
|
||||
Log.i("$TAG Search bar is closed, going back")
|
||||
isEnabled = false
|
||||
try {
|
||||
requireActivity().onBackPressedDispatcher.onBackPressed()
|
||||
} catch (ise: IllegalStateException) {
|
||||
Log.w("$TAG Can't go back: $ise")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun onDefaultAccountChanged()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
postponeEnterTransition()
|
||||
|
||||
requireActivity().onBackPressedDispatcher.addCallback(
|
||||
viewLifecycleOwner,
|
||||
backPressedCallback
|
||||
)
|
||||
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
}
|
||||
|
||||
|
|
@ -206,6 +230,10 @@ abstract class AbstractMainFragment : GenericMainFragment() {
|
|||
false
|
||||
}
|
||||
|
||||
viewModel.searchBarVisible.observe(viewLifecycleOwner) { visible ->
|
||||
backPressedCallback.isEnabled = visible
|
||||
}
|
||||
|
||||
viewModel.focusSearchBarEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { show ->
|
||||
if (show) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue