@@ -34,8 +34,7 @@ import android.widget.RelativeLayout
3434import androidx.annotation.StringRes
3535import androidx.constraintlayout.widget.ConstraintLayout
3636import androidx.core.content.res.ResourcesCompat
37- import androidx.core.view.WindowInsetsCompat
38- import androidx.core.view.updateLayoutParams
37+ import androidx.core.view.*
3938import com.google.gson.Gson
4039import com.google.gson.reflect.TypeToken
4140import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@@ -488,10 +487,11 @@ class ThreadActivity : SimpleActivity() {
488487 thread_add_attachment.setOnClickListener {
489488 if (attachment_picker_holder.isVisible()) {
490489 isAttachmentPickerVisible = false
491- showKeyboard( thread_type_message)
490+ WindowCompat .getInsetsController(window, thread_type_message).show( WindowInsetsCompat . Type .ime() )
492491 } else {
493492 isAttachmentPickerVisible = true
494- hideKeyboard()
493+ showOrHideAttachmentPicker()
494+ WindowCompat .getInsetsController(window, thread_type_message).hide(WindowInsetsCompat .Type .ime())
495495 }
496496 window.decorView.requestApplyInsets()
497497 }
@@ -1445,19 +1445,40 @@ class ThreadActivity : SimpleActivity() {
14451445 }
14461446
14471447 private fun setupKeyboardListener () {
1448- val imeTypeMask = WindowInsetsCompat .Type .ime()
1449- val navigationBarMask = WindowInsetsCompat .Type .navigationBars()
1450-
1451- window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
1452- val insets = WindowInsetsCompat .toWindowInsetsCompat(windowInsets)
1453- if (insets.isVisible(imeTypeMask)) {
1454- config.keyboardHeight = insets.getInsets(imeTypeMask).bottom - insets.getInsets(navigationBarMask).bottom
1455- hideAttachmentPicker()
1456- } else if (isAttachmentPickerVisible) {
1457- showAttachmentPicker()
1448+ window.decorView.setOnApplyWindowInsetsListener { _, insets ->
1449+ showOrHideAttachmentPicker()
1450+ insets
1451+ }
1452+
1453+ val callback = object : WindowInsetsAnimationCompat .Callback (DISPATCH_MODE_CONTINUE_ON_SUBTREE ) {
1454+ override fun onPrepare (animation : WindowInsetsAnimationCompat ) {
1455+ super .onPrepare(animation)
1456+ showOrHideAttachmentPicker()
14581457 }
14591458
1460- view.onApplyWindowInsets(windowInsets)
1459+ override fun onProgress (insets : WindowInsetsCompat , runningAnimations : MutableList <WindowInsetsAnimationCompat >) = insets
1460+ }
1461+ ViewCompat .setWindowInsetsAnimationCallback(window.decorView, callback)
1462+ }
1463+
1464+ private fun showOrHideAttachmentPicker () {
1465+ val type = WindowInsetsCompat .Type .ime()
1466+ val insets = ViewCompat .getRootWindowInsets(window.decorView) ? : return
1467+ val isKeyboardVisible = insets.isVisible(type)
1468+
1469+ if (isKeyboardVisible) {
1470+ val keyboardHeight = insets.getInsets(type).bottom
1471+ val bottomBarHeight = insets.getInsets(WindowInsetsCompat .Type .navigationBars()).bottom
1472+
1473+ // check keyboard height just to be sure, 150 seems like a good middle ground between ime and navigation bar
1474+ config.keyboardHeight = if (keyboardHeight > 150 ) {
1475+ keyboardHeight - bottomBarHeight
1476+ } else {
1477+ getDefaultKeyboardHeight()
1478+ }
1479+ hideAttachmentPicker()
1480+ } else if (isAttachmentPickerVisible) {
1481+ showAttachmentPicker()
14611482 }
14621483 }
14631484}
0 commit comments