mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-17 04:00:35 +01:00
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.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.*
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
@ -488,10 +487,11 @@ class ThreadActivity : SimpleActivity() {
|
||||
thread_add_attachment.setOnClickListener {
|
||||
if (attachment_picker_holder.isVisible()) {
|
||||
isAttachmentPickerVisible = false
|
||||
showKeyboard(thread_type_message)
|
||||
WindowCompat.getInsetsController(window, thread_type_message).show(WindowInsetsCompat.Type.ime())
|
||||
} else {
|
||||
isAttachmentPickerVisible = true
|
||||
hideKeyboard()
|
||||
showOrHideAttachmentPicker()
|
||||
WindowCompat.getInsetsController(window, thread_type_message).hide(WindowInsetsCompat.Type.ime())
|
||||
}
|
||||
window.decorView.requestApplyInsets()
|
||||
}
|
||||
@ -1445,19 +1445,40 @@ class ThreadActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun setupKeyboardListener() {
|
||||
val imeTypeMask = WindowInsetsCompat.Type.ime()
|
||||
val navigationBarMask = WindowInsetsCompat.Type.navigationBars()
|
||||
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
|
||||
showOrHideAttachmentPicker()
|
||||
insets
|
||||
}
|
||||
|
||||
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
|
||||
val insets = WindowInsetsCompat.toWindowInsetsCompat(windowInsets)
|
||||
if (insets.isVisible(imeTypeMask)) {
|
||||
config.keyboardHeight = insets.getInsets(imeTypeMask).bottom - insets.getInsets(navigationBarMask).bottom
|
||||
hideAttachmentPicker()
|
||||
} else if (isAttachmentPickerVisible) {
|
||||
showAttachmentPicker()
|
||||
val callback = object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) {
|
||||
override fun onPrepare(animation: WindowInsetsAnimationCompat) {
|
||||
super.onPrepare(animation)
|
||||
showOrHideAttachmentPicker()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getDefaultKeyboardHeight() = resources.getDimensionPixelSize(R.dimen.default_keyboard_height)
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
import com.simplemobiletools.smsmessenger.extensions.getDefaultKeyboardHeight
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
}
|
||||
|
@ -13,4 +13,5 @@
|
||||
<dimen name="medium_icon_size">36dp</dimen>
|
||||
<dimen name="attachment_button_height">96dp</dimen>
|
||||
<dimen name="attachment_button_width">90dp</dimen>
|
||||
<dimen name="default_keyboard_height">250dp</dimen>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user