Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -143,6 +146,8 @@ object ResultFragment {
private const val START_VALUE_BUNDLE = "startValue"
private const val RESTART_BUNDLE = "restart"

private val logoTitleToggleCache = LruCache<String, Boolean>(100)

fun newInstance(
card: SearchResponse, startAction: Int = 0, startValue: Int? = null
): Bundle {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/fragment_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

</FrameLayout>
</FrameLayout>
Expand Down Expand Up @@ -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" />

<com.lagradost.cloudstream3.widget.FlowLayout
Expand Down
63 changes: 42 additions & 21 deletions app/src/main/res/layout/fragment_result_tv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:layout_gravity="bottom"
android:src="@drawable/background_shadow" />

<ImageView
android:id="@+id/background_poster_watermark_badge_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="220dp"
android:maxHeight="72dp"
android:layout_gravity="bottom|start"
android:layout_marginStart="@dimen/result_padding"
android:layout_marginBottom="56dp"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:contentDescription="@null" />

</FrameLayout>

<com.facebook.shimmer.ShimmerFrameLayout
Expand Down Expand Up @@ -191,6 +178,12 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:textColor="?attr/textColor"
android:textSize="25sp"
android:textStyle="bold"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:foreground="@drawable/outline_drawable"
android:nextFocusUp="@id/background_poster_watermark_badge_holder"
android:nextFocusDown="@id/result_play_parent"
tools:text="The Perfect Run The Perfect Run" />

<TextView
Expand Down Expand Up @@ -326,7 +319,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_movie_button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_play_movie_button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/ic_baseline_play_arrow_24"
Expand All @@ -352,7 +345,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_series_button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_play_series_button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/ic_baseline_play_arrow_24"
Expand All @@ -378,7 +371,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_resume_series_button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_resume_series_button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/ic_baseline_resume_arrow2"
Expand All @@ -404,7 +397,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_play_trailer_button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_play_trailer_button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/ic_baseline_film_roll_24"
Expand All @@ -428,7 +421,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_bookmark_Button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_bookmark_Button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/outline_bookmark_add_24"
Expand All @@ -452,7 +445,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_favorite_Button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_favorite_Button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/ic_baseline_favorite_border_24"
Expand All @@ -476,7 +469,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_subscribe_Button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_subscribe_Button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/baseline_notifications_none_24"
Expand All @@ -500,7 +493,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
android:id="@+id/result_search_Button"
style="@style/ResultSmallButtonTV"
android:focusable="true"
android:nextFocusUp="@id/result_search_Button"
android:nextFocusUp="@id/result_title"
android:nextFocusDown="@id/result_description"
android:tag="@string/tv_no_focus_tag"
app:icon="@drawable/search_icon"
Expand Down Expand Up @@ -1104,4 +1097,32 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
</LinearLayout>

</androidx.core.widget.NestedScrollView>

<!-- Logo overlay: must be AFTER the NestedScrollView so it sits above it
in the Z-order and can receive touch events for the toggle -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="275dp"
android:clickable="false"
android:focusable="false">

<ImageView
android:id="@+id/background_poster_watermark_badge_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="220dp"
android:maxHeight="72dp"
android:layout_gravity="bottom|start"
android:layout_marginStart="@dimen/result_padding"
android:layout_marginBottom="56dp"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:foreground="@drawable/outline_drawable"
android:nextFocusDown="@id/result_title"
android:contentDescription="@string/result_logo_img_des" />
</FrameLayout>

</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="play_from_beginning_img_des">Play from the Beginning</string>
<string name="home_change_provider_img_des">Change Provider</string>
<string name="preview_background_img_des">Preview Background</string>
<string name="result_logo_img_des">Logo</string>
<!-- TRANSLATE, BUT DON'T FORGET FORMAT -->
<string name="player_speed_text_format" formatted="true">Speed (%.2fx)</string>
<string name="rated_format" formatted="true">Rated: %.1f</string>
Expand Down