Merge pull request #7790 from vector-im/feature/ons/fix_rename_session_keyboard_visibility

Automatically show keyboard after learn more bottom sheet is dismissed (PSG-1105)
This commit is contained in:
Onuray Sahin 2022-12-19 16:21:37 +03:00 committed by GitHub
commit 9fd6fe321d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

1
changelog.d/7790.bugfix Normal file
View file

@ -0,0 +1 @@
Automatically show keyboard after learn more bottom sheet is dismissed

View file

@ -16,6 +16,7 @@
package im.vector.app.features.settings.devices.v2.more
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -42,6 +43,8 @@ class SessionLearnMoreBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
override val showExpanded = true
var onDismiss: (() -> Unit)? = null
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetSessionLearnMoreBinding {
return BottomSheetSessionLearnMoreBinding.inflate(inflater, container, false)
}
@ -57,6 +60,11 @@ class SessionLearnMoreBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
}
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
onDismiss?.invoke()
}
override fun invalidate() = withState(viewModel) { viewState ->
super.invalidate()
views.bottomSheetSessionLearnMoreTitle.text = viewState.title
@ -65,11 +73,12 @@ class SessionLearnMoreBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
companion object {
fun show(fragmentManager: FragmentManager, args: Args) {
fun show(fragmentManager: FragmentManager, args: Args): SessionLearnMoreBottomSheet {
val bottomSheet = SessionLearnMoreBottomSheet()
bottomSheet.isCancelable = true
bottomSheet.setArguments(args)
bottomSheet.show(fragmentManager, "SessionLearnMoreBottomSheet")
return bottomSheet
}
}
}

View file

@ -20,6 +20,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.core.widget.doOnTextChanged
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -62,12 +63,24 @@ class RenameSessionFragment :
}
private fun initEditText() {
views.renameSessionEditText.showKeyboard(andRequestFocus = true)
showKeyboard()
views.renameSessionEditText.doOnTextChanged { text, _, _, _ ->
viewModel.handle(RenameSessionAction.EditLocally(text.toString()))
}
}
private fun showKeyboard() {
val focusChangeListener = object : ViewTreeObserver.OnWindowFocusChangeListener {
override fun onWindowFocusChanged(hasFocus: Boolean) {
if (hasFocus) {
views.renameSessionEditText.showKeyboard(andRequestFocus = true)
}
views.renameSessionEditText.viewTreeObserver.removeOnWindowFocusChangeListener(this)
}
}
views.renameSessionEditText.viewTreeObserver.addOnWindowFocusChangeListener(focusChangeListener)
}
private fun initSaveButton() {
views.renameSessionSave.debouncedClicks {
viewModel.handle(RenameSessionAction.SaveModifications)
@ -89,7 +102,9 @@ class RenameSessionFragment :
title = getString(R.string.device_manager_learn_more_session_rename_title),
description = getString(R.string.device_manager_learn_more_session_rename),
)
SessionLearnMoreBottomSheet.show(childFragmentManager, args)
SessionLearnMoreBottomSheet
.show(childFragmentManager, args)
.onDismiss = { showKeyboard() }
}
private fun observeViewEvents() {