tv layout fixed

This commit is contained in:
reduplicated 2022-08-06 18:08:20 +02:00
parent 3a2041c52f
commit f063a4b3a1
3 changed files with 119 additions and 35 deletions

View file

@ -243,7 +243,7 @@ open class ResultFragment : ResultTrailerPlayer() {
private var updateUIListener: (() -> Unit)? = null private var updateUIListener: (() -> Unit)? = null
} }
open fun setTrailers(trailers: List<ExtractorLink>?) { } open fun setTrailers(trailers: List<ExtractorLink>?) {}
protected lateinit var viewModel: ResultViewModel2 //by activityViewModels() protected lateinit var viewModel: ResultViewModel2 //by activityViewModels()
protected lateinit var syncModel: SyncViewModel protected lateinit var syncModel: SyncViewModel
@ -328,7 +328,7 @@ open class ResultFragment : ResultTrailerPlayer() {
viewModel.reloadEpisodes() viewModel.reloadEpisodes()
} }
open fun updateMovie(data : ResourceSome<Pair<UiText, ResultEpisode>>) { open fun updateMovie(data: ResourceSome<Pair<UiText, ResultEpisode>>) {
when (data) { when (data) {
is ResourceSome.Success -> { is ResourceSome.Success -> {
data.value.let { (text, ep) -> data.value.let { (text, ep) ->
@ -381,7 +381,7 @@ open class ResultFragment : ResultTrailerPlayer() {
System.currentTimeMillis(), System.currentTimeMillis(),
) )
) { click -> ) { click ->
when(click.action) { when (click.action) {
DOWNLOAD_ACTION_DOWNLOAD -> { DOWNLOAD_ACTION_DOWNLOAD -> {
viewModel.handleAction( viewModel.handleAction(
activity, activity,
@ -402,7 +402,7 @@ open class ResultFragment : ResultTrailerPlayer() {
} }
} }
open fun updateEpisodes(episodes : ResourceSome<List<ResultEpisode>>) { open fun updateEpisodes(episodes: ResourceSome<List<ResultEpisode>>) {
when (episodes) { when (episodes) {
is ResourceSome.None -> { is ResourceSome.None -> {
result_episode_loading?.isVisible = false result_episode_loading?.isVisible = false
@ -462,7 +462,12 @@ open class ResultFragment : ResultTrailerPlayer() {
arguments?.remove(START_VALUE_BUNDLE) arguments?.remove(START_VALUE_BUNDLE)
arguments?.remove(START_ACTION_BUNDLE) arguments?.remove(START_ACTION_BUNDLE)
AutoResume(startAction = action, id = startValue, episode = resumeEpisode, season = resumeSeason) AutoResume(
startAction = action,
id = startValue,
episode = resumeEpisode,
season = resumeSeason
)
} }
syncModel.addFromUrl(url) syncModel.addFromUrl(url)
@ -845,6 +850,7 @@ open class ResultFragment : ResultTrailerPlayer() {
} }
result_description.setTextHtml(d.plotText) result_description.setTextHtml(d.plotText)
if (this !is ResultFragmentTv) // dont want this clickable on tv layout
result_description?.setOnClickListener { view -> result_description?.setOnClickListener { view ->
view.context?.let { ctx -> view.context?.let { ctx ->
val builder: AlertDialog.Builder = val builder: AlertDialog.Builder =
@ -889,7 +895,9 @@ open class ResultFragment : ResultTrailerPlayer() {
} }
context?.let { ctx -> context?.let { ctx ->
val dubStatus = if(ctx.getApiDubstatusSettings().contains(DubStatus.Dubbed)) DubStatus.Dubbed else DubStatus.Subbed val dubStatus = if (ctx.getApiDubstatusSettings()
.contains(DubStatus.Dubbed)
) DubStatus.Dubbed else DubStatus.Subbed
result_bookmark_button?.isVisible = ctx.isTvSettings() result_bookmark_button?.isVisible = ctx.isTvSettings()

View file

@ -2,11 +2,9 @@ package com.lagradost.cloudstream3.ui.result
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.view.children
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.discord.panels.OverlappingPanelsLayout
import com.lagradost.cloudstream3.DubStatus import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.SearchResponse
@ -14,14 +12,14 @@ import com.lagradost.cloudstream3.mvvm.ResourceSome
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.ui.search.SearchAdapter import com.lagradost.cloudstream3.ui.search.SearchAdapter
import com.lagradost.cloudstream3.ui.search.SearchHelper import com.lagradost.cloudstream3.ui.search.SearchHelper
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
import kotlinx.android.synthetic.main.fragment_result_swipe.*
import kotlinx.android.synthetic.main.fragment_result_tv.* import kotlinx.android.synthetic.main.fragment_result_tv.*
import kotlinx.android.synthetic.main.result_recommendations.*
class ResultFragmentTv : ResultFragment() { class ResultFragmentTv : ResultFragment() {
override val resultLayout = R.layout.fragment_result_tv override val resultLayout = R.layout.fragment_result_tv
private var currentRecommendations: List<SearchResponse> = emptyList()
private fun handleSelection(data: Any) { private fun handleSelection(data: Any) {
when (data) { when (data) {
is EpisodeRange -> { is EpisodeRange -> {
@ -33,6 +31,9 @@ class ResultFragmentTv : ResultFragment() {
is DubStatus -> { is DubStatus -> {
viewModel.changeDubStatus(data) viewModel.changeDubStatus(data)
} }
is String -> {
setRecommendations(currentRecommendations, data)
}
} }
} }
@ -72,19 +73,21 @@ class ResultFragmentTv : ResultFragment() {
} }
override fun setRecommendations(rec: List<SearchResponse>?, validApiName: String?) { override fun setRecommendations(rec: List<SearchResponse>?, validApiName: String?) {
currentRecommendations = rec ?: emptyList()
val isInvalid = rec.isNullOrEmpty() val isInvalid = rec.isNullOrEmpty()
result_recommendations?.isGone = isInvalid result_recommendations?.isGone = isInvalid
result_recommendations_btt?.isGone = isInvalid result_recommendations_holder?.isGone = isInvalid
val matchAgainst = validApiName ?: rec?.firstOrNull()?.apiName val matchAgainst = validApiName ?: rec?.firstOrNull()?.apiName
(result_recommendations?.adapter as SearchAdapter?)?.updateList(rec?.filter { it.apiName == matchAgainst } ?: emptyList()) (result_recommendations?.adapter as SearchAdapter?)?.updateList(rec?.filter { it.apiName == matchAgainst }
?: emptyList())
rec?.map { it.apiName }?.distinct()?.let { apiNames -> rec?.map { it.apiName }?.distinct()?.let { apiNames ->
// very dirty selection // very dirty selection
result_recommendations_filter_button?.isVisible = apiNames.size > 1 result_recommendations_filter_selection?.isVisible = apiNames.size > 1
result_recommendations_filter_button?.text = matchAgainst result_recommendations_filter_selection?.update(apiNames.map { txt(it) to it })
result_recommendations_filter_selection?.select(apiNames.indexOf(matchAgainst))
} ?: run { } ?: run {
result_recommendations_filter_button?.isVisible = false result_recommendations_filter_selection?.isVisible = false
} }
} }
@ -97,6 +100,7 @@ class ResultFragmentTv : ResultFragment() {
result_season_selection.setAdapter() result_season_selection.setAdapter()
result_range_selection.setAdapter() result_range_selection.setAdapter()
result_dub_selection.setAdapter() result_dub_selection.setAdapter()
result_recommendations_filter_selection.setAdapter()
observe(viewModel.selectedRangeIndex) { selected -> observe(viewModel.selectedRangeIndex) { selected ->
result_range_selection.select(selected) result_range_selection.select(selected)
@ -117,6 +121,10 @@ class ResultFragmentTv : ResultFragment() {
result_season_selection.update(it) result_season_selection.update(it)
} }
result_back?.setOnClickListener {
activity?.popCurrentPage()
}
result_recommendations?.spanCount = 8 result_recommendations?.spanCount = 8
result_recommendations?.adapter = result_recommendations?.adapter =
SearchAdapter( SearchAdapter(

View file

@ -189,16 +189,42 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_marginBottom="10dp"
android:layout_height="30dp">
<ImageView
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginEnd="10dp"
android:nextFocusDown="@id/result_description"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:id="@+id/result_back"
android:clickable="true"
android:focusable="true"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_baseline_arrow_back_24"
android:contentDescription="@string/go_back"
app:tint="?attr/white" />
<TextView <TextView
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="30dp"
android:gravity="center_vertical"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:maxLines="2" android:maxLines="1"
android:textColor="?attr/textColor" android:textColor="?attr/textColor"
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold" android:textStyle="bold"
tools:text="The Perfect Run The Perfect Run" /> tools:text="The Perfect Run The Perfect Run" />
</LinearLayout>
<com.lagradost.cloudstream3.widget.FlowLayout <com.lagradost.cloudstream3.widget.FlowLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -687,6 +713,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:nextFocusUp="@id/result_dub_selection" android:nextFocusUp="@id/result_dub_selection"
android:nextFocusDown="@id/result_recommendations_filter_selection"
android:id="@+id/result_episodes" android:id="@+id/result_episodes"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -696,8 +723,49 @@
tools:listitem="@layout/result_episode" /> tools:listitem="@layout/result_episode" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<include layout="@layout/result_recommendations" />
<LinearLayout
android:id="@+id/result_recommendations_holder"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
tools:itemCount="2"
android:nextFocusUp="@id/result_episodes"
android:nextFocusDown="@id/result_recommendations"
android:id="@+id/result_recommendations_filter_selection"
android:layout_marginEnd="10dp"
tools:listitem="@layout/result_selection"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:textSize="17sp"
android:textColor="?attr/textColor"
android:text="@string/recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
android:nextFocusUp="@id/result_recommendations_filter_selection"
android:descendantFocusability="afterDescendants"
android:background="?attr/primaryBlackBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:spanCount="8"
android:id="@+id/result_recommendations"
tools:listitem="@layout/search_result_grid"
android:orientation="vertical" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>