made tv UI better on resultspage + ep range + focus bugfix

This commit is contained in:
LagradOst 2023-07-26 05:44:37 +02:00
parent 31da089eb1
commit a1824c86a3
7 changed files with 545 additions and 464 deletions

View file

@ -771,7 +771,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
val wasGone = focusOutline.isGone
val visible =
newFocus != null && newFocus.measuredHeight > 0 && newFocus.measuredWidth > 0 && newFocus.isVisible && newFocus.tag != "tv_no_focus_tag"
newFocus != null && newFocus.measuredHeight > 0 && newFocus.measuredWidth > 0 && newFocus.isShown && newFocus.tag != "tv_no_focus_tag"
focusOutline.isVisible = visible
if (newFocus != null) {
lastFocus = WeakReference(newFocus)
@ -779,6 +779,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
val out = IntArray(2)
newFocus.getLocationInWindow(out)
val (x, y) = out
// out of bounds = 0,0
if(x == 0 && y == 0) {
focusOutline.isVisible = false
}
/*(newFocus.parent as? RecyclerView)?.let { recycle ->
println("PARET IS RECYLE")
val position = recycle.getChildAdapterPosition(newFocus)

View file

@ -1,11 +1,16 @@
package com.lagradost.cloudstream3.ui.result
import android.animation.Animator
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.DecelerateInterpolator
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isGone
import androidx.core.view.isVisible
@ -34,6 +39,7 @@ import com.lagradost.cloudstream3.ui.search.SearchHelper
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogInstant
@ -64,6 +70,7 @@ class ResultFragmentTv : Fragment() {
): View {
viewModel =
ViewModelProvider(this)[ResultViewModel2::class.java]
viewModel.EPISODE_RANGE_SIZE = 50
updateUIEvent += ::updateUI
val localBinding = FragmentResultTvBinding.inflate(inflater, container, false)
@ -170,10 +177,39 @@ class ResultFragmentTv : Fragment() {
super.onStop()
}
private fun View.fade(turnVisible: Boolean) {
if (turnVisible) {
isVisible = true
}
this.animate().alpha(if (turnVisible) 1.0f else 0.0f).apply {
duration = 200
interpolator = DecelerateInterpolator()
setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {
}
override fun onAnimationEnd(animation: Animator) {
this@fade.isVisible = turnVisible
}
override fun onAnimationCancel(animation: Animator) {
}
override fun onAnimationRepeat(animation: Animator) {
}
})
}
this.animate().translationX(if (turnVisible) 0f else 100f).apply {
duration = 200
interpolator = DecelerateInterpolator()
}
}
private fun toggleEpisodes(show: Boolean) {
binding?.apply {
episodeHolderTv.isVisible = show
leftLayout.isGone = show
episodesShadow.fade(show)
episodeHolderTv.fade(show)
}
}

View file

@ -321,7 +321,7 @@ data class ExtractedTrailerData(
class ResultViewModel2 : ViewModel() {
private var currentResponse: LoadResponse? = null
var EPISODE_RANGE_SIZE : Int = 20
fun clear() {
currentResponse = null
_page.postValue(null)
@ -426,8 +426,8 @@ class ResultViewModel2 : ViewModel() {
companion object {
const val TAG = "RVM2"
private const val EPISODE_RANGE_SIZE = 20
private const val EPISODE_RANGE_OVERLOAD = 30
//private const val EPISODE_RANGE_SIZE = 20
//private const val EPISODE_RANGE_OVERLOAD = 30
private fun List<SeasonData>?.getSeason(season: Int?): SeasonData? {
if (season == null) return null
@ -477,12 +477,13 @@ class ResultViewModel2 : ViewModel() {
)
)
private fun getRanges(allEpisodes: Map<EpisodeIndexer, List<ResultEpisode>>): Map<EpisodeIndexer, List<EpisodeRange>> {
private fun getRanges(allEpisodes: Map<EpisodeIndexer, List<ResultEpisode>>, EPISODE_RANGE_SIZE : Int): Map<EpisodeIndexer, List<EpisodeRange>> {
return allEpisodes.keys.mapNotNull { index ->
val episodes =
allEpisodes[index] ?: return@mapNotNull null // this should never happened
// fast case
val EPISODE_RANGE_OVERLOAD = EPISODE_RANGE_SIZE + 10
if (episodes.size <= EPISODE_RANGE_OVERLOAD) {
return@mapNotNull index to listOf(
EpisodeRange(
@ -2088,7 +2089,7 @@ class ResultViewModel2 : ViewModel() {
}
currentEpisodes = allEpisodes
val ranges = getRanges(allEpisodes)
val ranges = getRanges(allEpisodes, EPISODE_RANGE_SIZE)
currentRanges = ranges

View file

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

View file

@ -150,38 +150,40 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
</FrameLayout>
<View
android:id="@+id/redirect_to_episodes"
android:layout_width="0dp"
android:layout_height="0dp"></View>
<View
android:id="@+id/redirect_to_play"
android:layout_width="0dp"
android:layout_height="0dp"></View>
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:id="@+id/result_finish_loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:paddingStart="@dimen/result_padding"
android:paddingEnd="@dimen/result_padding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="0"
android:orientation="vertical">
<TextView
android:id="@+id/result_title"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:maxLines="1"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textSize="20sp"
android:textStyle="bold"
@ -244,8 +246,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_movie"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusUp="@id/result_back"
android:nextFocusRight="@id/result_description"
android:nextFocusDown="@id/result_play_series"
android:text="@string/play_movie_button"
android:visibility="visible"
@ -261,25 +262,23 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_series"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_play_movie"
android:nextFocusDown="@id/result_resume_series"
android:text="@string/play_episode"
android:visibility="visible"
app:icon="@drawable/ic_baseline_play_arrow_24"
tools:visibility="gone" />
app:icon="@drawable/ic_baseline_play_arrow_24" />
<com.google.android.material.button.MaterialButton
android:id="@+id/result_resume_series"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_play_series"
android:nextFocusDown="@id/result_play_trailer"
android:text="@string/resume"
android:visibility="visible"
app:icon="@drawable/ic_baseline_play_arrow_24"
tools:visibility="gone" />
app:icon="@drawable/ic_baseline_play_arrow_24" />
</LinearLayout>
@ -287,13 +286,13 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_trailer"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_resume_series"
android:nextFocusDown="@id/result_bookmark_button"
android:text="@string/play_trailer_button"
android:visibility="gone"
app:icon="@drawable/ic_baseline_play_arrow_24"
tools:visibility="gone" />
tools:visibility="visible" />
<!-- <com.lagradost.cloudstream3.ui.download.button.DownloadButton
@ -309,10 +308,10 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
<com.google.android.material.button.MaterialButton
android:id="@+id/result_bookmark_button"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_play_trailer"
android:nextFocusDown="@id/result_episodes_show"
android:text="@string/type_none"
android:visibility="visible"
app:icon="@drawable/ic_baseline_bookmark_24" />
@ -324,20 +323,36 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_cast_items"
android:text="@string/episodes"
android:visibility="visible"
app:icon="@drawable/ic_baseline_sort_24"
tools:visibility="visible" />
<View
android:id="@+id/redirect_to_episodes"
android:layout_width="1dp"
android:layout_height="1dp"
android:focusable="true"
android:focusableInTouchMode="true" />
<View
android:id="@+id/redirect_to_play"
android:layout_width="1dp"
android:layout_height="1dp"
android:focusable="true"
android:focusableInTouchMode="true" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/left_layout"
android:id="@+id/right_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/linearLayout2"
@ -453,17 +468,99 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_cast_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:fadingEdge="horizontal"
android:focusable="false"
android:focusableInTouchMode="false"
android:nextFocusUp="@id/result_back"
android:nextFocusDown="@id/result_play_movie"
android:orientation="horizontal"
android:paddingTop="5dp"
android:requiresFadingEdge="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/cast_item"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/result_recommendations_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_recommendations_filter_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:nextFocusUp="@id/result_episodes"
android:nextFocusDown="@id/result_recommendations_list"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/result_selection" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/recommended"
android:textColor="?attr/textColor"
android:textSize="17sp" />
</LinearLayout>
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
android:id="@+id/result_recommendations_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBlackBackground"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusUp="@id/result_recommendations_filter_selection"
android:orientation="vertical"
app:spanCount="8"
tools:listitem="@layout/search_result_grid" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<ImageView
android:id="@+id/episodes_shadow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAccessibility="no"
android:src="@drawable/episodes_shadow"
android:visibility="gone"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/episode_holder_tv"
android:layout_width="500dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_gravity="right"
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">
<androidx.recyclerview.widget.RecyclerView
@ -471,10 +568,11 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:nextFocusLeft="@id/result_episodes_show"
android:nextFocusRight="@id/result_range_selection"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection" />
@ -482,23 +580,26 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_range_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:nextFocusLeft="@id/result_season_selection"
android:nextFocusRight="@id/result_dub_selection"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection" />
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:nextFocusLeft="@id/result_range_selection"
android:nextFocusRight="@id/result_episodes"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_selection" />
@ -519,6 +620,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:nextFocusLeft="@id/result_dub_selection"
android:nextFocusRight="@id/result_recommendations_filter_selection"
android:orientation="vertical"
android:paddingVertical="@dimen/result_padding"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/result_episode" />
@ -532,11 +634,8 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:nextFocusUp="@id/temporary_no_focus"
android:nextFocusDown="@id/temporary_no_focus" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/result_finish_loading"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -956,75 +1055,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
</LinearLayout>
</LinearLayout>-->
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_cast_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:fadingEdge="horizontal"
android:focusable="false"
android:focusableInTouchMode="false"
android:nextFocusUp="@id/result_back"
android:nextFocusDown="@id/result_play_movie"
android:orientation="horizontal"
android:paddingTop="5dp"
android:requiresFadingEdge="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/cast_item"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/result_recommendations_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_recommendations_filter_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:nextFocusUp="@id/result_episodes"
android:nextFocusDown="@id/result_recommendations_list"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/result_selection" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/recommended"
android:textColor="?attr/textColor"
android:textSize="17sp" />
</LinearLayout>
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
android:id="@+id/result_recommendations_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBlackBackground"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:nextFocusUp="@id/result_recommendations_filter_selection"
android:orientation="vertical"
app:spanCount="8"
tools:listitem="@layout/search_result_grid" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</FrameLayout>

View file

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
style="@style/RegularButtonTV"
android:layout_gravity="start"
android:layout_marginStart="0dp"
android:layout_marginEnd="10dp"
tools:text="Season 1" />
android:layout_margin="2dp"
android:minWidth="115dp"
android:singleLine="true"
tools:text="1000-1000" />

View file

@ -727,6 +727,7 @@
</style>
<style name="ResultButtonTV" parent="@style/RegularButtonTV">
<item name="android:tag">@string/tv_no_focus_tag</item>
<item name="iconGravity">start</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_width">250dp</item>
@ -736,6 +737,7 @@
</style>
<style name="RegularButtonTV">
<item name="android:tag">@string/tv_no_focus_tag</item>
<item name="android:stateListAnimator">@null</item>
<item name="strokeColor">@color/transparent</item>
<item name="backgroundTint">@null</item>