Properly handle attachment picker visibility
This commit is contained in:
parent
e87c8eeff7
commit
b4c5648ddc
|
@ -34,8 +34,7 @@ import android.widget.RelativeLayout
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.*
|
||||||
import androidx.core.view.updateLayoutParams
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
|
@ -488,10 +487,11 @@ class ThreadActivity : SimpleActivity() {
|
||||||
thread_add_attachment.setOnClickListener {
|
thread_add_attachment.setOnClickListener {
|
||||||
if (attachment_picker_holder.isVisible()) {
|
if (attachment_picker_holder.isVisible()) {
|
||||||
isAttachmentPickerVisible = false
|
isAttachmentPickerVisible = false
|
||||||
showKeyboard(thread_type_message)
|
WindowCompat.getInsetsController(window, thread_type_message).show(WindowInsetsCompat.Type.ime())
|
||||||
} else {
|
} else {
|
||||||
isAttachmentPickerVisible = true
|
isAttachmentPickerVisible = true
|
||||||
hideKeyboard()
|
showOrHideAttachmentPicker()
|
||||||
|
WindowCompat.getInsetsController(window, thread_type_message).hide(WindowInsetsCompat.Type.ime())
|
||||||
}
|
}
|
||||||
window.decorView.requestApplyInsets()
|
window.decorView.requestApplyInsets()
|
||||||
}
|
}
|
||||||
|
@ -1445,19 +1445,40 @@ class ThreadActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupKeyboardListener() {
|
private fun setupKeyboardListener() {
|
||||||
val imeTypeMask = WindowInsetsCompat.Type.ime()
|
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
|
||||||
val navigationBarMask = WindowInsetsCompat.Type.navigationBars()
|
showOrHideAttachmentPicker()
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
|
||||||
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
|
val callback = object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) {
|
||||||
val insets = WindowInsetsCompat.toWindowInsetsCompat(windowInsets)
|
override fun onPrepare(animation: WindowInsetsAnimationCompat) {
|
||||||
if (insets.isVisible(imeTypeMask)) {
|
super.onPrepare(animation)
|
||||||
config.keyboardHeight = insets.getInsets(imeTypeMask).bottom - insets.getInsets(navigationBarMask).bottom
|
showOrHideAttachmentPicker()
|
||||||
hideAttachmentPicker()
|
|
||||||
} else if (isAttachmentPickerVisible) {
|
|
||||||
showAttachmentPicker()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view.onApplyWindowInsets(windowInsets)
|
override fun onProgress(insets: WindowInsetsCompat, runningAnimations: MutableList<WindowInsetsAnimationCompat>) = insets
|
||||||
|
}
|
||||||
|
ViewCompat.setWindowInsetsAnimationCallback(window.decorView, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showOrHideAttachmentPicker() {
|
||||||
|
val type = WindowInsetsCompat.Type.ime()
|
||||||
|
val insets = ViewCompat.getRootWindowInsets(window.decorView) ?: return
|
||||||
|
val isKeyboardVisible = insets.isVisible(type)
|
||||||
|
|
||||||
|
if (isKeyboardVisible) {
|
||||||
|
val keyboardHeight = insets.getInsets(type).bottom
|
||||||
|
val bottomBarHeight = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||||
|
|
||||||
|
// check keyboard height just to be sure, 150 seems like a good middle ground between ime and navigation bar
|
||||||
|
config.keyboardHeight = if (keyboardHeight > 150) {
|
||||||
|
keyboardHeight - bottomBarHeight
|
||||||
|
} else {
|
||||||
|
getDefaultKeyboardHeight()
|
||||||
|
}
|
||||||
|
hideAttachmentPicker()
|
||||||
|
} else if (isAttachmentPickerVisible) {
|
||||||
|
showAttachmentPicker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1065,3 +1065,5 @@ fun Context.clearExpiredScheduledMessages(threadId: Long, messagesToDelete: List
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getDefaultKeyboardHeight() = resources.getDimensionPixelSize(R.dimen.default_keyboard_height)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
|
import com.simplemobiletools.smsmessenger.extensions.getDefaultKeyboardHeight
|
||||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
|
@ -88,6 +89,6 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
set(wasDbCleared) = prefs.edit().putBoolean(WAS_DB_CLEARED, wasDbCleared).apply()
|
set(wasDbCleared) = prefs.edit().putBoolean(WAS_DB_CLEARED, wasDbCleared).apply()
|
||||||
|
|
||||||
var keyboardHeight: Int
|
var keyboardHeight: Int
|
||||||
get() = prefs.getInt(SOFT_KEYBOARD_HEIGHT, 600)
|
get() = prefs.getInt(SOFT_KEYBOARD_HEIGHT, context.getDefaultKeyboardHeight())
|
||||||
set(keyboardHeight) = prefs.edit().putInt(SOFT_KEYBOARD_HEIGHT, keyboardHeight).apply()
|
set(keyboardHeight) = prefs.edit().putInt(SOFT_KEYBOARD_HEIGHT, keyboardHeight).apply()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,5 @@
|
||||||
<dimen name="medium_icon_size">36dp</dimen>
|
<dimen name="medium_icon_size">36dp</dimen>
|
||||||
<dimen name="attachment_button_height">96dp</dimen>
|
<dimen name="attachment_button_height">96dp</dimen>
|
||||||
<dimen name="attachment_button_width">90dp</dimen>
|
<dimen name="attachment_button_width">90dp</dimen>
|
||||||
|
<dimen name="default_keyboard_height">250dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue