From 466cbb40198060f33e5809be64ac56bfe92b5ac5 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Sat, 5 Mar 2022 12:34:02 +0400 Subject: [PATCH] show keyboard bug --- .../com/github/libretube/PlayerFragment.kt | 8 +++++++ .../com/github/libretube/SearchFragment.kt | 22 ++++++++++++------- app/src/main/res/layout/fragment_search.xml | 2 ++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index f6d1bf863..4b5bbdfe3 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -19,6 +19,8 @@ import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.WindowManager +import android.view.inputmethod.InputMethodManager import android.widget.* import androidx.appcompat.app.AlertDialog import androidx.constraintlayout.motion.widget.MotionLayout @@ -81,6 +83,12 @@ class PlayerFragment : Fragment() { arguments?.let { videoId = it.getString("videoId") } + closeKeyboard() + } + private fun closeKeyboard() { + val inputMethodManager: InputMethodManager = + requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0) } override fun onCreateView( diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 53aabffed..9b55a22f5 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -1,31 +1,31 @@ package com.github.libretube +import android.content.Context import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.util.Log -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.WindowManager +import android.view.inputmethod.InputMethodManager import android.widget.ArrayAdapter import android.widget.AutoCompleteTextView +import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.adapters.SearchAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import retrofit2.HttpException -import com.github.libretube.adapters.SearchAdapter import java.io.IOException class SearchFragment : Fragment() { - private val TAG = "SearchFragment" - - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { @@ -61,7 +61,7 @@ class SearchFragment : Fragment() { if(s!! != ""){ GlobalScope.launch { fetchSuggestions(s.toString(), autoTextView) - delay(2000) + delay(3000) fetchSearch(s.toString(),recyclerView) } } @@ -96,7 +96,7 @@ class SearchFragment : Fragment() { RetrofitInstance.api.getSearchResults(query, "all") } catch (e: IOException) { println(e) - Log.e(TAG, "IOException, you might not have internet connection "+e.toString()) + Log.e(TAG, "IOException, you might not have internet connection $e") return@launchWhenCreated } catch (e: HttpException) { Log.e(TAG, "HttpException, unexpected response") @@ -117,4 +117,10 @@ class SearchFragment : Fragment() { if (!isAdded) return // Fragment not attached to an Activity activity?.runOnUiThread(action) } -} \ No newline at end of file + + override fun onResume() { + super.onResume() + requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) + } + +} diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index ff5368722..fac4020df 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -5,6 +5,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".SearchFragment" + android:focusable="true" + android:focusableInTouchMode="true" >