Fixed some focus and layout stuff for android TV

This commit is contained in:
Blatzar 2022-07-01 19:10:57 +02:00
parent 63b313395a
commit d581c4b627
5 changed files with 31 additions and 14 deletions

View file

@ -876,6 +876,10 @@ class CS3IPlayer : IPlayer {
return Pair(subSources, activeSubtitles) return Pair(subSources, activeSubtitles)
} }
override fun isActive(): Boolean {
return exoPlayer != null
}
private fun loadOnlinePlayer(context: Context, link: ExtractorLink) { private fun loadOnlinePlayer(context: Context, link: ExtractorLink) {
Log.i(TAG, "loadOnlinePlayer $link") Log.i(TAG, "loadOnlinePlayer $link")
try { try {

View file

@ -1143,10 +1143,13 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
// handle tv controls directly based on player state // handle tv controls directly based on player state
keyEventListener = { eventNav -> keyEventListener = { eventNav ->
// Don't hook player keys if player isn't active
if (player.isActive()) {
val (event, hasNavigated) = eventNav val (event, hasNavigated) = eventNav
if (event != null) if (event != null)
handleKeyEvent(event, hasNavigated) handleKeyEvent(event, hasNavigated)
else false else false
} else false
} }
try { try {

View file

@ -116,4 +116,7 @@ interface IPlayer {
fun onResume(context: Context) fun onResume(context: Context)
fun release() fun release()
/** Get if player is actually used */
fun isActive() : Boolean
} }

View file

@ -24,7 +24,6 @@ import android.widget.*
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.text.HtmlCompat
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
@ -98,10 +97,7 @@ import kotlinx.android.synthetic.main.fragment_trailer.*
import kotlinx.android.synthetic.main.result_recommendations.* import kotlinx.android.synthetic.main.result_recommendations.*
import kotlinx.android.synthetic.main.result_sync.* import kotlinx.android.synthetic.main.result_sync.*
import kotlinx.android.synthetic.main.trailer_custom_layout.* import kotlinx.android.synthetic.main.trailer_custom_layout.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.*
import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -646,6 +642,13 @@ class ResultFragment : ResultTrailerPlayer() {
} }
result_trailer_loading?.isVisible = isSuccess result_trailer_loading?.isVisible = isSuccess
result_smallscreen_holder?.isVisible = !isSuccess && !isFullScreenPlayer result_smallscreen_holder?.isVisible = !isSuccess && !isFullScreenPlayer
// We don't want the trailer to be focusable if it's not visible
result_smallscreen_holder?.descendantFocusability = if (isSuccess) {
ViewGroup.FOCUS_AFTER_DESCENDANTS
} else {
ViewGroup.FOCUS_BLOCK_DESCENDANTS
}
result_fullscreen_holder?.isVisible = !isSuccess && isFullScreenPlayer result_fullscreen_holder?.isVisible = !isSuccess && isFullScreenPlayer
} }

View file

@ -167,6 +167,7 @@
</com.facebook.shimmer.ShimmerFrameLayout> </com.facebook.shimmer.ShimmerFrameLayout>
<FrameLayout <FrameLayout
android:descendantFocusability="blocksDescendants"
android:id="@+id/result_smallscreen_holder" android:id="@+id/result_smallscreen_holder"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -307,10 +308,10 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_marginHorizontal="10dp"
android:id="@+id/result_title" android:id="@+id/result_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -322,6 +323,7 @@
tools:text="The Perfect Run The Perfect Run" /> tools:text="The Perfect Run The Perfect Run" />
<com.lagradost.cloudstream3.widget.FlowLayout <com.lagradost.cloudstream3.widget.FlowLayout
android:layout_marginHorizontal="10dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:itemSpacing="10dp"> app:itemSpacing="10dp">
@ -358,11 +360,16 @@
tools:text="121min" /> tools:text="121min" />
</com.lagradost.cloudstream3.widget.FlowLayout> </com.lagradost.cloudstream3.widget.FlowLayout>
<!--
This has half margin and half padding to make TV focus on description look better.
The focus outline now settles between the poster and text.
-->
<FrameLayout <FrameLayout
android:layout_marginHorizontal="5dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView <TextView
android:padding="5dp"
android:maxLength="1000" android:maxLength="1000"
android:ellipsize="end" android:ellipsize="end"
android:id="@+id/result_description" android:id="@+id/result_description"
@ -371,9 +378,6 @@
android:foreground="@drawable/outline_drawable" android:foreground="@drawable/outline_drawable"
android:nextFocusUp="@id/result_back" android:nextFocusUp="@id/result_back"
android:nextFocusDown="@id/result_bookmark_button" android:nextFocusDown="@id/result_bookmark_button"
android:paddingTop="5dp"
android:paddingBottom="0dp"
android:textColor="?attr/textColor" android:textColor="?attr/textColor"
android:textSize="15sp" android:textSize="15sp"
tools:text="Ryan Quicksave Romano is an eccentric adventurer with a strange power: he can create a save-point in time and redo his life whenever he dies. Arriving in New Rome, the glitzy capital of sin of a rebuilding Europe, he finds the city torn between mega-corporations, sponsored heroes, superpowered criminals, and true monsters. It's a time of chaos, where potions can grant the power to rule the world and dangers lurk everywhere. " /> tools:text="Ryan Quicksave Romano is an eccentric adventurer with a strange power: he can create a save-point in time and redo his life whenever he dies. Arriving in New Rome, the glitzy capital of sin of a rebuilding Europe, he finds the city torn between mega-corporations, sponsored heroes, superpowered criminals, and true monsters. It's a time of chaos, where potions can grant the power to rule the world and dangers lurk everywhere. " />