feat: Improve keyboard handling in selection mode for better user experience

This commit is contained in:
2026-01-15 20:54:04 +05:00
parent 2b1b6eecef
commit 22a17e5fec
3 changed files with 278 additions and 249 deletions

View File

@@ -22,6 +22,7 @@ import androidx.compose.ui.unit.dp
* ```
*/
object KeyboardHeightProvider {
private const val TAG = "KeyboardHeight"
private const val PREFS_NAME = "emoji_keyboard_prefs"
private const val KEY_KEYBOARD_HEIGHT = "kbd_height"
private const val DEFAULT_HEIGHT_DP = 280 // Telegram uses 200, we use 280
@@ -35,7 +36,11 @@ object KeyboardHeightProvider {
val savedPx = prefs.getInt(KEY_KEYBOARD_HEIGHT, defaultPx)
val isDefault = savedPx == defaultPx
android.util.Log.d("KeyboardHeight", "📖 getSavedKeyboardHeight: ${savedPx}px (${pxToDp(context, savedPx)}dp) ${if (isDefault) "[DEFAULT]" else "[SAVED]"}")
android.util.Log.d(TAG, "═══════════════════════════════════════")
android.util.Log.d(TAG, "📖 getSavedKeyboardHeight()")
android.util.Log.d(TAG, " 📏 Height: ${savedPx}px (${pxToDp(context, savedPx)}dp)")
android.util.Log.d(TAG, " 📦 Source: ${if (isDefault) "DEFAULT" else "SAVED"}")
android.util.Log.d(TAG, "═══════════════════════════════════════")
return savedPx
}
@@ -43,6 +48,9 @@ object KeyboardHeightProvider {
* Сохранить высоту клавиатуры
*/
fun saveKeyboardHeight(context: Context, heightPx: Int) {
android.util.Log.d(TAG, "═══════════════════════════════════════")
android.util.Log.d(TAG, "💾 saveKeyboardHeight($heightPx px)")
if (heightPx > 0) {
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
val oldHeight = prefs.getInt(KEY_KEYBOARD_HEIGHT, -1)
@@ -50,21 +58,29 @@ object KeyboardHeightProvider {
prefs.edit().putInt(KEY_KEYBOARD_HEIGHT, heightPx).apply()
android.util.Log.d(TAG, " 📏 New: ${heightPx}px (${pxToDp(context, heightPx)}dp)")
android.util.Log.d(TAG, " 📏 Old: ${oldHeight}px (${pxToDp(context, oldHeight)}dp)")
android.util.Log.d(TAG, " 🔄 Changed: $changed")
if (changed) {
android.util.Log.d("KeyboardHeight", "💾 SAVED keyboard height: ${heightPx}px (${pxToDp(context, heightPx)}dp) [WAS: ${oldHeight}px]")
android.util.Log.d(TAG, " SAVED successfully!")
} else {
android.util.Log.v("KeyboardHeight", "💾 Same keyboard height: ${heightPx}px (no change)")
android.util.Log.d(TAG, " ⏭️ Same height, no change")
}
} else {
android.util.Log.w("KeyboardHeight", "⚠️ Attempted to save invalid height: ${heightPx}px")
android.util.Log.w(TAG, " ⚠️ INVALID height: ${heightPx}px - NOT saved!")
}
android.util.Log.d(TAG, "═══════════════════════════════════════")
}
/**
* Получить длительность анимации клавиатуры
* Telegram использует: AdjustPanLayoutHelper.keyboardDuration (250ms обычно)
*/
fun getKeyboardAnimationDuration(): Long = 250L
fun getKeyboardAnimationDuration(): Long {
android.util.Log.d(TAG, "⏱️ getKeyboardAnimationDuration() = 250ms")
return 250L
}
// Helper functions
private fun dpToPx(context: Context, dp: Int): Int {
@@ -91,7 +107,9 @@ fun rememberSavedKeyboardHeight(): Dp {
val density = context.resources.displayMetrics.density
val heightDp = (heightPx / density).dp
android.util.Log.d("KeyboardHeight", "🎯 rememberSavedKeyboardHeight: ${heightDp} (${heightPx}px, density=${density})")
android.util.Log.d("KeyboardHeight", "🎯 rememberSavedKeyboardHeight()")
android.util.Log.d("KeyboardHeight", " 📏 Result: $heightDp (${heightPx}px)")
android.util.Log.d("KeyboardHeight", " 📱 Density: $density")
return heightDp
}