From 5e619c18cc0e5a8f5267f87fde12639318014a9d Mon Sep 17 00:00:00 2001 From: LagradOst Date: Wed, 11 Aug 2021 20:26:19 +0200 Subject: [PATCH] fix semi movie --- .../cloudstream3/ui/result/ResultFragment.kt | 60 +++++++++++-------- .../lagradost/cloudstream3/utils/AppUtils.kt | 19 +++--- 2 files changed, 47 insertions(+), 32 deletions(-) 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 10b41b1a..cb14d20e 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 @@ -237,6 +237,18 @@ class ResultFragment : Fragment() { var startAction: Int? = null + private fun lateFixDownloadButton(show: Boolean) { + if (show) { + result_movie_parent.visibility = VISIBLE + result_episodes_text.visibility = GONE + result_episodes.visibility = GONE + } else { + result_movie_parent.visibility = GONE + result_episodes_text.visibility = VISIBLE + result_episodes.visibility = VISIBLE + } + } + @SuppressLint("SetTextI18n") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -690,6 +702,8 @@ class ResultFragment : Fragment() { } observe(viewModel.episodes) { episodeList -> + lateFixDownloadButton( episodeList.size <= 1) // movies can have multible parts but still be *movies* this will fix this + when (startAction) { START_ACTION_RESUME_LATEST -> { for (ep in episodeList) { @@ -884,11 +898,9 @@ class ResultFragment : Fragment() { } } - if (d.type == TvType.Movie && d is MovieLoadResponse) { + if (d.type == TvType.Movie) { val hasDownloadSupport = api.hasDownloadSupport - result_movie_parent.visibility = VISIBLE - result_episodes_text.visibility = GONE - result_episodes.visibility = GONE + lateFixDownloadButton(true) result_play_movie.setOnClickListener { val card = currentEpisodes?.first() ?: return@setOnClickListener @@ -933,34 +945,34 @@ class ResultFragment : Fragment() { ) ) { downloadClickEvent -> if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) { - handleAction( - EpisodeClickEvent( - ACTION_DOWNLOAD_EPISODE, - ResultEpisode( - d.name, - null, - 0, - null, - d.dataUrl, - d.apiName, - localId, - 0, - 0L, - 0L, - null, - null + currentEpisodes?.first()?.let { episode -> + handleAction( + EpisodeClickEvent( + ACTION_DOWNLOAD_EPISODE, + ResultEpisode( + d.name, + null, + 0, + null, + episode.data, + d.apiName, + localId, + 0, + 0L, + 0L, + null, + null + ) ) ) - ) + } } else { handleDownloadClick(activity, currentHeaderName, downloadClickEvent) } } } } else { - result_movie_parent.visibility = GONE - result_episodes_text.visibility = VISIBLE - result_episodes.visibility = VISIBLE + lateFixDownloadButton(false) } when (d) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt index 842673cb..13eebd83 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -50,19 +50,22 @@ object AppUtils { * | Episode 2 * **/ fun getNameFull(name: String?, episode: Int?, season: Int?): String { + val rEpisode = if(episode == 0) null else episode + val rSeason = if(season == 0) null else season + if (name != null) { - return if(episode != null && season != null) { - "S${season}:E${episode} $name" - } else if(episode != null) { - "Episode $episode. $name" + return if(rEpisode != null && rSeason != null) { + "S${rSeason}:E${rEpisode} $name" + } else if(rEpisode != null) { + "Episode $rEpisode. $name" } else { name } } else { - if(episode != null && season != null) { - return "Season $season - Episode $episode" - } else if(season == null) { - return "Episode $episode" + if(rEpisode != null && rSeason != null) { + return "Season $rSeason - Episode $rEpisode" + } else if(rSeason == null) { + return "Episode $rEpisode" } } return ""