Close keyboard when opening emoji picker + improved EmojiCompat init

This commit is contained in:
Sylvain Berfini 2023-04-06 14:31:40 +02:00
parent 22d4a8baf1
commit e395cff106
3 changed files with 18 additions and 3 deletions

View file

@ -330,6 +330,14 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
}
}
chatSendingViewModel.requestKeyboardHidingEvent.observe(
viewLifecycleOwner
) {
it.consume {
(requireActivity() as MainActivity).hideKeyboard()
}
}
listViewModel.events.observe(
viewLifecycleOwner
) { events ->

View file

@ -107,6 +107,10 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
val isEmojiPickerVisible = MutableLiveData<Boolean>()
val requestKeyboardHidingEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
private lateinit var recorder: Recorder
private var voiceRecordAudioFocusRequest: AudioFocusRequestCompat? = null
@ -216,6 +220,9 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
fun toggleEmojiPicker() {
isEmojiPickerOpen.value = isEmojiPickerOpen.value == false
if (isEmojiPickerOpen.value == true) {
requestKeyboardHidingEvent.value = Event(true)
}
}
fun sendMessage() {

View file

@ -45,15 +45,15 @@ import org.linphone.core.tools.Log
*/
class AppUtils {
companion object {
var emojiCompat: EmojiCompat? = null
private val emojiCompat: EmojiCompat?
get() = initEmojiCompat()
private fun initEmojiCompat(): EmojiCompat? {
return try {
EmojiCompat.get()
} catch (ise: IllegalStateException) {
Log.e("[App Utils] Can't get EmojiCompat: $ise")
null
Log.w("[App Utils] EmojiCompat.get() triggered IllegalStateException [$ise], trying manual init")
EmojiCompat.init(coreContext.context)
}
}