From a3c3f9b249a9950ab184cd4c8de086a2798f44f0 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Tue, 24 Sep 2024 12:48:47 +0300 Subject: [PATCH] App menu now scrolls to the top when opening the app menu with automatic keyboard opening enabled. --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 27b14a7..32be30c 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -16,7 +16,6 @@ import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper -import android.os.ResultReceiver import android.os.UserHandle import android.provider.AlarmClock import android.provider.ContactsContract @@ -121,6 +120,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh var returnAllowed = true + private var isInitialOpen = false + private val handler = Handler(Looper.getMainLooper()) override fun onCreate(savedInstanceState: Bundle?) { @@ -279,17 +280,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh animations.showApps(binding.homeView, binding.appView) animations.backgroundIn(this@MainActivity) if (sharedPreferenceManager.isAutoKeyboardEnabled()) { - val keyboardReceiver = object : ResultReceiver(null) { - override fun onReceiveResult(resultCode: Int, resultData: Bundle?) { - super.onReceiveResult(resultCode, resultData) - appRecycler.scrollToPosition(0) - } - - } + isInitialOpen = true val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager searchView.requestFocus() - imm.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT, keyboardReceiver) + imm.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT) } } @@ -836,6 +831,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh if (bottom - top > oldBottom - oldTop) { // If keyboard is closed, remove cursor from the search bar searchView.clearFocus() + } else if (bottom - top < oldBottom - oldTop && isInitialOpen) { + isInitialOpen = false + appRecycler.scrollToPosition(0) } }