diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index cbf94fd9796..870b3b83d73 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -1,6 +1,7 @@ package com.lagradost.cloudstream3.ui.result import android.os.Bundle +import android.util.LruCache import android.widget.ImageView import android.widget.TextView import androidx.core.view.isVisible @@ -14,6 +15,8 @@ import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.SeasonData import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.ui.result.EpisodeAdapter.Companion.getPlayerAction +import com.lagradost.cloudstream3.ui.settings.Globals.TV +import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.AppContextUtils.getApiDubstatusSettings import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper.getVideoWatchState @@ -143,6 +146,8 @@ object ResultFragment { private const val START_VALUE_BUNDLE = "startValue" private const val RESTART_BUNDLE = "restart" + private val logoTitleToggleCache = LruCache(100) + fun newInstance( card: SearchResponse, startAction: Int = 0, startValue: Int? = null ): Bundle { @@ -245,38 +250,80 @@ object ResultFragment { logoView: ImageView, titleView: TextView ) { - // Cancel it, as we want to remove the listener onSuccess race condition + // Cancel any pending image load to avoid race conditions when scrolling fast logoView.dispose() + // Clean up the views completely before we do anything. + // This stops weird state bleeding when RecyclerView recycles these views. + logoView.clearAnimation() + titleView.clearAnimation() + logoView.setOnClickListener(null) + titleView.setOnClickListener(null) + logoView.isEnabled = true + titleView.isEnabled = true + logoView.alpha = 1f + titleView.alpha = 1f + + // CloudStream convention for TV touch focus + logoView.isFocusable = true + logoView.isFocusableInTouchMode = isLayout(TV) + titleView.isFocusable = true + titleView.isFocusableInTouchMode = isLayout(TV) + if (url.isNullOrBlank()) { logoView.isVisible = false titleView.isVisible = true return } - logoView.isVisible = true - titleView.isVisible = false + // Grab the toggle state from our session cache (in case they've clicked it before) + val isShowingTitle = logoTitleToggleCache.get(url) == true + + logoView.isVisible = !isShowingTitle + titleView.isVisible = isShowingTitle + + // Hiding logo, showing title + logoView.setOnClickListener { + val wasFocused = logoView.isFocused + logoTitleToggleCache.put(url, true) + logoView.isVisible = false + titleView.isVisible = true + if (wasFocused) titleView.requestFocus() + } + + // Hiding title, showing logo + titleView.setOnClickListener { + val wasFocused = titleView.isFocused + logoTitleToggleCache.put(url, false) + logoView.isVisible = true + titleView.isVisible = false + if (wasFocused) logoView.requestFocus() + } logoView.loadImage( imageData = UiImage.Image(url, headers = headers), builder = { listener( onSuccess = { _, _ -> - logoView.isVisible = true - titleView.isVisible = false + // Only show the logo if the user hasn't already toggled to the title while we were loading + if (logoTitleToggleCache.get(url) != true) { + logoView.isVisible = true + titleView.isVisible = false + } }, onError = { _, _ -> + // If the logo is broken or missing, force the title text and disable the toggle so they aren't stuck with a blank image logoView.isVisible = false titleView.isVisible = true + titleView.setOnClickListener(null) }, onCancel = { - // If we manually cancel, then it should not do anything + // If we manually cancelled it (like when scrolling away), just do nothing } ) } ) } - fun Fragment.getStoredData(): StoredData? { val context = this.context ?: this.activity ?: return null val settingsManager = PreferenceManager.getDefaultSharedPreferences(context) diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index a5c933d6a03..c46b40e9481 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -311,7 +311,9 @@ android:paddingBottom="4dp" android:adjustViewBounds="true" android:scaleType="fitStart" - android:contentDescription="@null" /> + android:focusable="true" + android:foreground="@drawable/outline_drawable" + android:contentDescription="@string/result_logo_img_des" /> @@ -366,6 +368,7 @@ android:textColor="?attr/textColor" android:textSize="20sp" android:textStyle="bold" + android:foreground="@drawable/outline_drawable" tools:text="The Perfect Run The Perfect Run" /> - - + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 31cf951cf5f..38be7cef215 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ Play from the Beginning Change Provider Preview Background + Logo Speed (%.2fx) Rated: %.1f