fix keyboard remains on search

This commit is contained in:
rimthekid 2022-03-15 04:51:31 -04:00
parent ab1576bb2b
commit 4b9f772b62
4 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package com.github.libretube
import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.content.res.Resources
@ -10,6 +12,7 @@ import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.*
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.appcompat.widget.Toolbar
@ -264,4 +267,17 @@ class MainActivity : AppCompatActivity() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
}
}
}
fun Fragment.hideKeyboard() {
view?.let { activity?.hideKeyboard(it) }
}
fun Activity.hideKeyboard() {
hideKeyboard(currentFocus ?: View(this))
}
fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

View File

@ -95,6 +95,7 @@ class PlayerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
hideKeyboard()
videoId = videoId!!.replace("/watch?v=","")
relDownloadVideo = view.findViewById(R.id.relPlayer_download)
val mainActivity = activity as MainActivity

View File

@ -47,6 +47,9 @@ class SearchFragment : Fragment() {
val recyclerView = view.findViewById<RecyclerView>(R.id.search_recycler)
recyclerView.layoutManager = GridLayoutManager(view.context, 1)
val autoTextView = view.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView)
autoTextView.requestFocus()
val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm!!.showSoftInput(autoTextView, InputMethodManager.SHOW_IMPLICIT)
autoTextView.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(
s: CharSequence?,
@ -111,7 +114,6 @@ class SearchFragment : Fragment() {
}
}
private fun Fragment?.runOnUiThread(action: () -> Unit) {
this ?: return
if (!isAdded) return // Fragment not attached to an Activity

View File

@ -77,7 +77,7 @@ class Settings : PreferenceFragmentCompat() {
instance?.summaryProvider = Preference.SummaryProvider<ListPreference> { preference ->
val text = preference.entry
if (TextUtils.isEmpty(text)) {
"Not set"
"kavin.rocks (Official)"
} else {
text
}