Bladeren bron

Fix more keyboard issues with search box (#41)

* Fix the keyboard staying open after swiping down from the app drawer
* Fix the keyboard staying open after adding an app to the home screen
* Fix all cases of the edit box staying in focus after opening another app in any way (by moving the clearFocus call to onStop)
levant47 5 jaren geleden
bovenliggende
commit
bb2bbb7622

+ 33 - 2
app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt

@@ -1,5 +1,6 @@
 package com.sduduzog.slimlauncher.ui.main
 
+import android.app.Activity
 import android.content.*
 import android.content.pm.LauncherApps
 import android.os.Bundle
@@ -13,6 +14,9 @@ import android.text.TextWatcher
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.view.inputmethod.InputMethodManager
+import androidx.constraintlayout.motion.widget.MotionLayout
+import androidx.constraintlayout.motion.widget.MotionLayout.TransitionListener
 import androidx.lifecycle.Observer
 import androidx.navigation.Navigation
 import com.sduduzog.slimlauncher.BuildConfig
@@ -77,6 +81,28 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
                 openAppAdapter.setItems(apps)
             }
         })
+        home_fragment.setTransitionListener(object : TransitionListener {
+            override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
+                // hide the keyboard and remove focus from the EditText when swiping back up
+                if (currentId == motionLayout?.startState) {
+                    resetAppDrawerEditText()
+                    val inputMethodManager = requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
+                    inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
+                }
+            }
+
+            override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) {
+                // do nothing
+            }
+
+            override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) {
+                // do nothing
+            }
+
+            override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float) {
+                // do nothing
+            }
+        })
     }
 
     override fun onStart() {
@@ -99,6 +125,7 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
     override fun onStop() {
         super.onStop()
         activity?.unregisterReceiver(receiver)
+        resetAppDrawerEditText()
     }
 
     private fun setEventListeners() {
@@ -188,8 +215,6 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
 
     override fun onAppClicked(app: App) {
         launchApp(app.packageName, app.activityName, app.userSerial)
-        app_drawer_edit_text.clearFocus() // dismiss the on-screen keyboard
-        app_drawer_edit_text.clearComposingText()
         home_fragment.transitionToStart()
     }
 
@@ -207,6 +232,12 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
         }
     }
 
+    private fun resetAppDrawerEditText() {
+        app_drawer_edit_text.clearComposingText()
+        app_drawer_edit_text.setText("")
+        app_drawer_edit_text.clearFocus()
+    }
+
     private val onTextChangeListener: TextWatcher = object : TextWatcher {
 
         override fun afterTextChanged(s: Editable?) {

+ 5 - 0
app/src/main/java/com/sduduzog/slimlauncher/ui/options/AddAppFragment.kt

@@ -1,5 +1,6 @@
 package com.sduduzog.slimlauncher.ui.options
 
+import android.app.Activity
 import android.content.Context
 import android.content.pm.LauncherApps
 import android.os.Bundle
@@ -10,6 +11,7 @@ import android.text.TextWatcher
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.view.inputmethod.InputMethodManager
 import androidx.fragment.app.viewModels
 import androidx.lifecycle.Observer
 import androidx.navigation.Navigation
@@ -60,6 +62,9 @@ class AddAppFragment : BaseFragment(), OnAppClickedListener {
     override fun onPause() {
         super.onPause()
         add_app_fragment_edit_text?.removeTextChangedListener(onTextChangeListener)
+
+        val inputMethodManager = requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
+        inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
     }
 
     private val onTextChangeListener: TextWatcher = object : TextWatcher {