Many fixes

This commit is contained in:
CranberrySoup 2023-09-15 16:39:00 +02:00
parent 45ecc903a2
commit 6e89ed9d81
6 changed files with 184 additions and 120 deletions

View file

@ -539,6 +539,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
val isTrueTv = isTrueTvSettings() val isTrueTv = isTrueTvSettings()
navView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv navView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv
navRailView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv navRailView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv
// Hide downloads on TV
navView.menu.findItem(R.id.navigation_downloads)?.isVisible = !isTrueTv
navRailView.menu.findItem(R.id.navigation_downloads)?.isVisible = !isTrueTv
} }
} }
@ -1112,16 +1116,17 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
newLocalBinding.root.viewTreeObserver.addOnGlobalFocusChangeListener { _, newFocus -> newLocalBinding.root.viewTreeObserver.addOnGlobalFocusChangeListener { _, newFocus ->
// println("refocus $oldFocus -> $newFocus") // println("refocus $oldFocus -> $newFocus")
try { try {
val r = Rect(0,0,0,0) val r = Rect(0, 0, 0, 0)
newFocus.getDrawingRect(r) newFocus.getDrawingRect(r)
val x = r.centerX() val x = r.centerX()
val y = r.centerY() val y = r.centerY()
val dx = 0 //screenWidth / 2 val dx = 0 //screenWidth / 2
val dy = screenHeight / 2 val dy = screenHeight / 2
val r2 = Rect(x-dx,y-dy,x+dx,y+dy) val r2 = Rect(x - dx, y - dy, x + dx, y + dy)
newFocus.requestRectangleOnScreen(r2, false) newFocus.requestRectangleOnScreen(r2, false)
// TvFocus.current =TvFocus.current.copy(y=y.toFloat()) // TvFocus.current =TvFocus.current.copy(y=y.toFloat())
} catch (_ : Throwable) { } } catch (_: Throwable) {
}
TvFocus.updateFocusView(newFocus) TvFocus.updateFocusView(newFocus)
/*var focus = newFocus /*var focus = newFocus

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.core.view.children
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs import kotlin.math.abs
@ -70,8 +71,8 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
val orientation = this.orientation val orientation = this.orientation
// fixes arabic by inverting left and right layout focus // fixes arabic by inverting left and right layout focus
val correctDirection = if(this.isLayoutRTL) { val correctDirection = if (this.isLayoutRTL) {
when(direction) { when (direction) {
View.FOCUS_RIGHT -> View.FOCUS_LEFT View.FOCUS_RIGHT -> View.FOCUS_LEFT
View.FOCUS_LEFT -> View.FOCUS_RIGHT View.FOCUS_LEFT -> View.FOCUS_RIGHT
else -> direction else -> direction
@ -83,12 +84,15 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
View.FOCUS_DOWN -> { View.FOCUS_DOWN -> {
return spanCount return spanCount
} }
View.FOCUS_UP -> { View.FOCUS_UP -> {
return -spanCount return -spanCount
} }
View.FOCUS_RIGHT -> { View.FOCUS_RIGHT -> {
return 1 return 1
} }
View.FOCUS_LEFT -> { View.FOCUS_LEFT -> {
return -1 return -1
} }
@ -98,12 +102,15 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
View.FOCUS_DOWN -> { View.FOCUS_DOWN -> {
return 1 return 1
} }
View.FOCUS_UP -> { View.FOCUS_UP -> {
return -1 return -1
} }
View.FOCUS_RIGHT -> { View.FOCUS_RIGHT -> {
return spanCount return spanCount
} }
View.FOCUS_LEFT -> { View.FOCUS_LEFT -> {
return -spanCount return -spanCount
} }
@ -155,4 +162,32 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
layoutManager = manager layoutManager = manager
} }
}
/**
* Recyclerview wherein the max item width or height is set by the biggest view to prevent inconsistent view sizes.
*/
class MaxRecyclerView(ctx: Context, attrs: AttributeSet) : RecyclerView(ctx, attrs) {
private var biggestObserved: Int = 0
private val orientation = LayoutManager.getProperties(context, attrs, 0, 0).orientation
private val isHorizontal = orientation == HORIZONTAL
private fun View.updateMaxSize() {
if (isHorizontal) {
this.minimumHeight = biggestObserved
} else {
this.minimumWidth = biggestObserved
}
}
override fun onChildAttachedToWindow(child: View) {
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
val observed = if (isHorizontal) child.measuredHeight else child.measuredWidth
if (observed > biggestObserved) {
biggestObserved = observed
children.forEach { it.updateMaxSize() }
} else {
child.updateMaxSize()
}
super.onChildAttachedToWindow(child)
}
} }

View file

@ -177,7 +177,7 @@ class ResultFragmentTv : Fragment() {
isVisible = true isVisible = true
} }
this.animate().alpha(if (turnVisible) 1.0f else 0.0f).apply { this.animate().alpha(if (turnVisible) 0.97f else 0.0f).apply {
duration = 200 duration = 200
interpolator = DecelerateInterpolator() interpolator = DecelerateInterpolator()
setListener(object : Animator.AnimatorListener { setListener(object : Animator.AnimatorListener {
@ -294,9 +294,9 @@ class ResultFragmentTv : Fragment() {
toggleEpisodes(true) toggleEpisodes(true)
binding?.apply { binding?.apply {
val views = listOf( val views = listOf(
resultDubSelection,
resultSeasonSelection, resultSeasonSelection,
resultRangeSelection, resultRangeSelection,
resultDubSelection,
resultEpisodes, resultEpisodes,
resultPlayTrailer, resultPlayTrailer,
) )

View file

@ -518,7 +518,8 @@ class ResultViewModel2 : ViewModel() {
val episodeNumber = episodes[currentIndex].episode val episodeNumber = episodes[currentIndex].episode
if (episodeNumber < currentMin) { if (episodeNumber < currentMin) {
currentMin = episodeNumber currentMin = episodeNumber
} else if (episodeNumber > currentMax) { }
if (episodeNumber > currentMax) {
currentMax = episodeNumber currentMax = episodeNumber
} }
++currentIndex ++currentIndex

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient <gradient
android:startColor="@color/transparent" android:centerColor="?attr/primaryBlackBackground"
android:endColor="?attr/primaryBlackBackground"/> android:centerX="0.2"
android:endColor="?attr/primaryBlackBackground"
android:startColor="@color/transparent" />
</shape> </shape>

View file

@ -535,129 +535,150 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
<FrameLayout <androidx.constraintlayout.widget.ConstraintLayout
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/episodes_shadow" android:id="@+id/episodes_shadow"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAccessibility="no"
android:src="@drawable/episodes_shadow"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAccessibility="no"
android:src="@drawable/episodes_shadow"/>
</FrameLayout>
<LinearLayout
android:id="@+id/episode_holder_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:orientation="horizontal"
android:paddingStart="@dimen/result_padding"
android:paddingEnd="@dimen/result_padding"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" tools:visibility="visible">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"
tools:visibility="gone">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_season_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_episodes_show"
android:nextFocusRight="@id/result_range_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_range_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_season_selection"
android:nextFocusRight="@id/result_dub_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection"
tools:visibility="visible" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_dub_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_range_selection"
android:nextFocusRight="@id/result_episodes"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection" />
<!--<androidx.core.widget.ContentLoadingProgressBar <!--
android:id="@+id/result_episode_loading" These two shadow spaces are used to create a view which always x% bigger
than the episode_holder_tv. This is required for creating a consistent shadow.
-->
<Space
android:id="@+id/shadow_space_1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="@+id/episode_holder_tv"
app:layout_constraintStart_toStartOf="@+id/episode_holder_tv" />
style="@style/Widget.AppCompat.ProgressBar" <!--
android:layout_gravity="center" The dimension ratio should and episodes_shadow centerX should add up to
android:layout_width="50dp" 100% for the best results. For example (100:80 + 0.2) or (100:70 + 0.3).
android:layout_height="50dp" />--> Bigger centerX => Larger fade distance.
-->
<Space
android:id="@+id/shadow_space_2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="100:80"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/shadow_space_1" />
<androidx.recyclerview.widget.RecyclerView <ImageView
android:id="@+id/result_episodes" android:layout_width="0dp"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="wrap_content" android:layout_gravity="end"
android:clipToPadding="false" android:clickable="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_dub_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_episode" />
<View
android:id="@+id/temporary_no_focus"
android:layout_width="1dp"
android:layout_height="1dp"
android:focusable="false" android:focusable="false"
android:nextFocusLeft="@id/temporary_no_focus" android:focusableInTouchMode="false"
android:nextFocusRight="@id/temporary_no_focus" android:importantForAccessibility="no"
android:nextFocusUp="@id/temporary_no_focus" android:src="@drawable/episodes_shadow"
android:nextFocusDown="@id/temporary_no_focus" /> app:layout_constraintEnd_toEndOf="parent"
</LinearLayout> app:layout_constraintStart_toStartOf="@+id/shadow_space_2"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/episode_holder_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
android:paddingStart="@dimen/result_padding"
android:paddingEnd="@dimen/result_padding"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"
tools:visibility="visible">
<com.lagradost.cloudstream3.ui.MaxRecyclerView
android:id="@+id/result_dub_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_episodes_show"
android:nextFocusRight="@id/result_season_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection"
tools:visibility="gone" />
<com.lagradost.cloudstream3.ui.MaxRecyclerView
android:id="@+id/result_season_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_dub_selection"
android:nextFocusRight="@id/result_range_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection"
tools:visibility="gone" />
<com.lagradost.cloudstream3.ui.MaxRecyclerView
android:id="@+id/result_range_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_season_selection"
android:nextFocusRight="@id/result_episodes"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection"
tools:visibility="visible" />
<!--<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/result_episode_loading"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="50dp" />-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_episodes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/result_range_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_episode" />
<View
android:id="@+id/temporary_no_focus"
android:layout_width="1dp"
android:layout_height="1dp"
android:focusable="false"
android:nextFocusLeft="@id/temporary_no_focus"
android:nextFocusRight="@id/temporary_no_focus"
android:nextFocusUp="@id/temporary_no_focus"
android:nextFocusDown="@id/temporary_no_focus" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"