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

View file

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