From a1824c86a3bfb6dce786b883d2293afea72563e9 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Wed, 26 Jul 2023 05:44:37 +0200 Subject: [PATCH] made tv UI better on resultspage + ep range + focus bugfix --- .../lagradost/cloudstream3/MainActivity.kt | 6 +- .../ui/result/ResultFragmentTv.kt | 40 +- .../ui/result/ResultViewModel2.kt | 11 +- app/src/main/res/drawable/episodes_shadow.xml | 6 + .../main/res/layout/fragment_result_tv.xml | 937 +++++++++--------- app/src/main/res/layout/result_selection.xml | 7 +- app/src/main/res/values/styles.xml | 2 + 7 files changed, 545 insertions(+), 464 deletions(-) create mode 100644 app/src/main/res/drawable/episodes_shadow.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 73664dc0..7e7624eb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -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) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt index 796037c9..506f7f10 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt @@ -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) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 6bf5ac47..88f55444 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -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?.getSeason(season: Int?): SeasonData? { if (season == null) return null @@ -477,12 +477,13 @@ class ResultViewModel2 : ViewModel() { ) ) - private fun getRanges(allEpisodes: Map>): Map> { + private fun getRanges(allEpisodes: Map>, EPISODE_RANGE_SIZE : Int): Map> { 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 diff --git a/app/src/main/res/drawable/episodes_shadow.xml b/app/src/main/res/drawable/episodes_shadow.xml new file mode 100644 index 00000000..b4cdd382 --- /dev/null +++ b/app/src/main/res/drawable/episodes_shadow.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_result_tv.xml b/app/src/main/res/layout/fragment_result_tv.xml index 83ba332a..a70262d2 100644 --- a/app/src/main/res/layout/fragment_result_tv.xml +++ b/app/src/main/res/layout/fragment_result_tv.xml @@ -150,393 +150,492 @@ https://developer.android.com/design/ui/tv/samples/jet-fit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -956,75 +1055,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit --> - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/result_selection.xml b/app/src/main/res/layout/result_selection.xml index d30b9949..925c65c9 100644 --- a/app/src/main/res/layout/result_selection.xml +++ b/app/src/main/res/layout/result_selection.xml @@ -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" /> \ No newline at end of file + android:layout_margin="2dp" + android:minWidth="115dp" + android:singleLine="true" + tools:text="1000-1000" /> \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ca6a3c7c..3977c7ac 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -727,6 +727,7 @@