This commit is contained in:
LagradOst 2023-08-01 04:03:43 +02:00
parent d5316bff9b
commit 7c60ccdef2
3 changed files with 43 additions and 31 deletions

View file

@ -372,7 +372,11 @@ object CommonActivity {
}
// if cant focus but visible then break and let android decide
if (!next.isFocusable && next.isShown) return null
// the exception if is the view is a parent and has children that wants focus
val hasChildrenThatWantsFocus = (next as? ViewGroup)?.let { parent ->
parent.descendantFocusability == ViewGroup.FOCUS_AFTER_DESCENDANTS && parent.childCount > 0
} ?: false
if (!next.isFocusable && next.isShown && !hasChildrenThatWantsFocus) return null
// if not shown then continue because we will "skip" over views to get to a replacement
if (!next.isShown) return getNextFocus(act, next, direction, depth + 1)

View file

@ -37,10 +37,10 @@ import androidx.navigation.NavOptions
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.google.android.gms.cast.framework.CastButtonFactory
import com.google.android.gms.cast.framework.CastContext
import com.google.android.gms.cast.framework.Session
import com.google.android.gms.cast.framework.SessionManager
@ -63,10 +63,10 @@ import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent
import com.lagradost.cloudstream3.CommonActivity.onUserLeaveHint
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.CommonActivity.updateLocale
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.databinding.ActivityMainBinding
import com.lagradost.cloudstream3.databinding.ActivityMainTvBinding
import com.lagradost.cloudstream3.databinding.BottomResultviewPreviewBinding
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.debugAssert
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
@ -780,7 +780,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
return ret
}
private var binding: ActivityMainBinding? = null
var binding: ActivityMainBinding? = null
object TvFocus {
data class FocusTarget(
@ -808,10 +808,18 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
var focusOutline: WeakReference<View> = WeakReference(null)
var lastFocus: WeakReference<View> = WeakReference(null)
private val layoutListener: View.OnLayoutChangeListener =
View.OnLayoutChangeListener { v, _, _, _, _, _, _, _, _ ->
View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
// shitty fix for layouts
lastFocus.get()?.apply {
updateFocusView(
v, same = true
this, same = true
)
postDelayed({
updateFocusView(
lastFocus.get(), same = false
)
}, 300)
}
}
private val attachListener: View.OnAttachStateChangeListener =
object : View.OnAttachStateChangeListener {
@ -843,9 +851,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
@MainThread
fun updateFocusView(newFocus: View?, same: Boolean = false) {
val focusOutline = focusOutline.get() ?: return
lastFocus.get()?.apply {
removeOnLayoutChangeListener(layoutListener)
removeOnAttachStateChangeListener(attachListener)
val lastView = lastFocus.get()
val exactlyTheSame = lastView == newFocus && newFocus != null
if (!exactlyTheSame) {
lastView?.removeOnLayoutChangeListener(layoutListener)
lastView?.removeOnAttachStateChangeListener(attachListener)
(lastView?.parent as? RecyclerView)?.removeOnLayoutChangeListener(layoutListener)
}
val wasGone = focusOutline.isGone
@ -857,6 +868,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
if (newFocus != null) {
lastFocus = WeakReference(newFocus)
val out = IntArray(2)
newFocus.getLocationInWindow(out)
val (screenX, screenY) = out
@ -871,10 +883,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
if (screenX == 0 && screenY == 0) {
focusOutline.isVisible = false
}
if (!exactlyTheSame) {
(newFocus.parent as? RecyclerView)?.addOnLayoutChangeListener(layoutListener)
newFocus.addOnLayoutChangeListener(layoutListener)
newFocus.addOnAttachStateChangeListener(attachListener)
}
val start = FocusTarget(
x = currentX,
y = currentY,

View file

@ -14,11 +14,12 @@ import androidx.viewbinding.ViewBinding
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipDrawable
import com.google.android.material.navigationrail.NavigationRailView
import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.CommonActivity.activity
import com.lagradost.cloudstream3.HomePageList
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.databinding.FragmentHomeHeadBinding
@ -467,27 +468,21 @@ class HomeParentItemAdapterPreview(
}
homePreviewHiddenNextFocus.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
if (!hasFocus) return@setOnFocusChangeListener
previewViewpager.setCurrentItem(previewViewpager.currentItem + 1, true)
homePreviewInfoBtt.requestFocus()
}
}
homePreviewHiddenPrevFocus.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
previewViewpager.apply {
if (currentItem <= 0) {
findViewById<NavigationRailView?>(R.id.nav_rail_view)?.menu?.getItem(
0
)?.actionView?.requestFocus()
if (!hasFocus) return@setOnFocusChangeListener
if (previewViewpager.currentItem <= 0) {
(activity as? MainActivity)?.binding?.navRailView?.requestFocus()
} else {
setCurrentItem(currentItem - 1, true)
previewViewpager.setCurrentItem(previewViewpager.currentItem - 1, true)
binding.homePreviewPlayBtt.requestFocus()
}
}
}
}
}
(binding as? FragmentHomeHeadBinding)?.apply {
fixPaddingStatusbar(binding.homeSearch)