mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Open/close keyboard when search bar is made visible/gone
This commit is contained in:
parent
09bbe650e3
commit
254cf3d9cf
4 changed files with 48 additions and 10 deletions
|
|
@ -33,6 +33,8 @@ import androidx.transition.AutoTransition
|
|||
import org.linphone.R
|
||||
import org.linphone.databinding.ContactsFragmentBinding
|
||||
import org.linphone.ui.contacts.viewmodel.ContactsListViewModel
|
||||
import org.linphone.utils.hideKeyboard
|
||||
import org.linphone.utils.showKeyboard
|
||||
|
||||
class ContactsFragment : Fragment() {
|
||||
private lateinit var binding: ContactsFragmentBinding
|
||||
|
|
@ -84,6 +86,17 @@ class ContactsFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
listViewModel.focusSearchBarEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { take ->
|
||||
if (take) {
|
||||
// To automatically open keyboard
|
||||
binding.search.showKeyboard(requireActivity().window)
|
||||
} else {
|
||||
binding.search.hideKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||
startPostponedEnterTransition()
|
||||
}*/
|
||||
|
|
|
|||
|
|
@ -21,22 +21,29 @@ package org.linphone.ui.contacts.viewmodel
|
|||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class ContactsListViewModel : ViewModel() {
|
||||
val searchBarVisible = MutableLiveData<Boolean>()
|
||||
|
||||
val searchFilter = MutableLiveData<String>()
|
||||
|
||||
val focusSearchBarEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
init {
|
||||
searchBarVisible.value = false
|
||||
}
|
||||
|
||||
fun openSearchBar() {
|
||||
searchBarVisible.value = true
|
||||
focusSearchBarEvent.value = Event(true)
|
||||
}
|
||||
|
||||
fun closeSearchBar() {
|
||||
searchBarVisible.value = false
|
||||
focusSearchBarEvent.value = Event(false)
|
||||
}
|
||||
|
||||
fun clearFilter() {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,14 @@
|
|||
*/
|
||||
package org.linphone.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Window
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.databinding.BindingAdapter
|
||||
import coil.load
|
||||
import coil.transform.CircleCropTransformation
|
||||
|
|
@ -31,6 +37,18 @@ import org.linphone.contacts.ContactData
|
|||
* This file contains all the data binding necessary for the app
|
||||
*/
|
||||
|
||||
fun AppCompatEditText.showKeyboard(window: Window) {
|
||||
this.requestFocus()
|
||||
/*val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)*/
|
||||
WindowCompat.getInsetsController(window, this).show(WindowInsetsCompat.Type.ime())
|
||||
}
|
||||
|
||||
fun AppCompatEditText.hideKeyboard() {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(this.windowToken, 0)
|
||||
}
|
||||
|
||||
@BindingAdapter("android:src")
|
||||
fun ImageView.setSourceImageResource(resource: Int) {
|
||||
this.setImageResource(resource)
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="avatar, title, search_toggle"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.INVISIBLE : View.VISIBLE}" />
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.GONE : View.VISIBLE, default=gone}" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="cancel_search, search, clear_field"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.VISIBLE : View.INVISIBLE, default=gone}" />
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.VISIBLE : View.GONE}" />
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/background_barrier"
|
||||
|
|
@ -92,23 +92,23 @@
|
|||
app:layout_constraintTop_toTopOf="@id/search"
|
||||
app:tint="@color/white" />
|
||||
|
||||
<EditText
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/search"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:hint="Search contact"
|
||||
android:focusedByDefault="true"
|
||||
android:text="@={viewModel.searchFilter}"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="@color/gray_6"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp"
|
||||
android:textCursorDrawable="@null"
|
||||
android:textColor="@color/gray_6"
|
||||
android:textColorHint="@color/gray_6"
|
||||
android:text="@={viewModel.searchFilter}"
|
||||
android:hint="Search contact"
|
||||
android:background="@android:color/transparent"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.VISIBLE : View.GONE, default=visible}"
|
||||
app:hintTextColor="@color/gray_6"
|
||||
app:boxStrokeWidth="0dp"
|
||||
app:boxStrokeWidthFocused="0dp"
|
||||
app:layout_constraintEnd_toStartOf="@id/clear_field"
|
||||
app:layout_constraintStart_toEndOf="@id/cancel_search"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
@ -130,7 +130,7 @@
|
|||
android:id="@+id/background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:src="@drawable/shape_white_background"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue