small fix for android tv and dark theme

This commit is contained in:
LagradOst 2021-11-27 00:19:17 +01:00
parent 37d402d7b3
commit 696f38e746
9 changed files with 52 additions and 21 deletions

View file

@ -12,10 +12,12 @@ import android.content.res.Resources
import android.os.Build
import android.os.Bundle
import android.view.*
import android.view.KeyEvent.ACTION_DOWN
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
@ -50,6 +52,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_result.*
@ -142,6 +145,33 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
}
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
event?.keyCode?.let { keyCode ->
when (event.action) {
ACTION_DOWN -> {
when (keyCode) {
KeyEvent.KEYCODE_DPAD_CENTER -> {
println("DPAD PRESSED $currentFocus")
if (currentFocus is SearchView || currentFocus is SearchView.SearchAutoComplete) {
println("current PRESSED")
showInputMethod(currentFocus?.findFocus())
}
}
}
//println("Keycode: $keyCode")
//showToast(
// this,
// "Got Keycode $keyCode | ${KeyEvent.keyCodeToString(keyCode)} \n ${event?.action}",
// Toast.LENGTH_LONG
//)
}
}
}
return super.dispatchKeyEvent(event)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
//println("Keycode: $keyCode")
//showToast(
@ -206,7 +236,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
//when (keyCode) {
// KeyEvent.KEYCODE_DPAD_CENTER -> {
// println("DPAD PRESSED ${this.isKeyboardOpen()}")
// println("DPAD PRESSED")
// }
//}
@ -385,6 +415,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
"Black" -> R.style.AppTheme
"Light" -> R.style.LightMode
"Amoled" -> R.style.AmoledMode
"AmoledLight" -> R.style.AmoledModeLight
else -> R.style.AppTheme
}

View file

@ -159,12 +159,12 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() {
quick_search_master_recycler.adapter = masterAdapter
quick_search_master_recycler.layoutManager = GridLayoutManager(context, 1)
quick_search.setOnQueryTextFocusChangeListener { _, b ->
if (b) {
// https://stackoverflow.com/questions/12022715/unable-to-show-keyboard-automatically-in-the-searchview
UIHelper.showInputMethod(view.findFocus())
}
}
//quick_search.setOnQueryTextFocusChangeListener { _, b ->
// if (b) {
// // https://stackoverflow.com/questions/12022715/unable-to-show-keyboard-automatically-in-the-searchview
// UIHelper.showInputMethod(view.findFocus())
// }
//}
quick_search_back.setOnClickListener {
activity?.popCurrentPage()

View file

@ -36,7 +36,6 @@ import com.lagradost.cloudstream3.utils.SEARCH_PROVIDER_TOGGLE
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
import kotlinx.android.synthetic.main.fragment_search.*
import java.util.concurrent.locks.ReentrantLock
@ -373,12 +372,12 @@ class SearchFragment : Fragment() {
typesActive = it.getApiTypeSettings()
}
main_search.setOnQueryTextFocusChangeListener { _, b ->
/*main_search.setOnQueryTextFocusChangeListener { _, b ->
if (b) {
// https://stackoverflow.com/questions/12022715/unable-to-show-keyboard-automatically-in-the-searchview
showInputMethod(view.findFocus())
}
}
}*/
//main_search.onActionViewExpanded()*/
val masterAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf(), { callback ->

View file

@ -300,7 +300,8 @@ object UIHelper {
inputMethodManager?.hideSoftInputFromWindow(view.windowToken, 0)
}
fun showInputMethod(view: View) {
fun showInputMethod(view: View?) {
if(view == null) return
val inputMethodManager = view.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager?
inputMethodManager?.showSoftInput(view, 0)
}

View file

@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.navigationrail.NavigationRailView
android:layout_width="wrap_content"
android:layout_width="62dp"
android:layout_height="match_parent"
android:id="@+id/nav_rail_view"
android:background="?attr/primaryGrayBackground"

View file

@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.navigationrail.NavigationRailView
android:layout_width="wrap_content"
android:layout_width="62dp"
android:layout_height="match_parent"
android:id="@+id/nav_rail_view"
android:background="?attr/primaryGrayBackground"

View file

@ -115,11 +115,13 @@
<string-array name="themes_names">
<item>Normal</item>
<item>Dark</item>
<item>Amoled</item>
<item>Flashbang</item>
</string-array>
<string-array name="themes_names_values">
<item>Black</item>
<item>AmoledLight</item>
<item>Amoled</item>
<item>Light</item>
</string-array>

View file

@ -22,6 +22,8 @@
<color name="black">#000</color>
<color name="dubColor">#3d50fa</color> <!--3b65f5 f18c82 8294F1-->
<color name="amoledModeLight">#121213</color>
<color name="dubColorBg">#803B65F5</color>
<color name="subColor">#F54A3B</color> <!--F53B66 FA3D79-->
<color name="subColorBg">#80F53B66</color>

View file

@ -57,13 +57,9 @@
<item name="white">#FFF</item>
</style>
<!-- <style name="PreferencesTheme" parent="@style/Base.Theme.AppCompat">
<item name="android:textColorPrimary">?attr/textColor</item>
<item name="android:textColorSecondary">?attr/grayTextColor</item>
<item name="android:colorAccent">?attr/colorAccent</item>
<item name="android:colorControlHighlight">@color/colorPrimary</item>
<item name="android:tint">?attr/textColor</item>
</style>-->
<style name="AmoledModeLight" parent="AmoledMode">
<item name="primaryGrayBackground">@color/amoledModeLight</item>
</style>
<style name="AmoledMode">
<item name="primaryGrayBackground">@color/black</item>