@@ -59,6 +59,7 @@ import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
5959import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
6060import com.lagradost.cloudstream3.ui.player.FullScreenPlayer
6161import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
62+ import com.lagradost.cloudstream3.ui.result.ResultFragment.bindLogo
6263import com.lagradost.cloudstream3.ui.result.ResultFragment.getStoredData
6364import com.lagradost.cloudstream3.ui.result.ResultFragment.updateUIEvent
6465import com.lagradost.cloudstream3.ui.search.SearchAdapter
@@ -86,14 +87,11 @@ import com.lagradost.cloudstream3.utils.UIHelper.populateChips
8687import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
8788import com.lagradost.cloudstream3.utils.UIHelper.setListViewHeightBasedOnItems
8889import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat
89- import com.lagradost.cloudstream3.utils.UiImage
9090import com.lagradost.cloudstream3.utils.VideoDownloadHelper
9191import com.lagradost.cloudstream3.utils.getImageFromDrawable
9292import com.lagradost.cloudstream3.utils.setText
9393import com.lagradost.cloudstream3.utils.setTextHtml
9494import java.net.URLEncoder
95- import java.nio.charset.Charset
96- import kotlin.io.encoding.Base64
9795import kotlin.math.roundToInt
9896
9997open class ResultFragmentPhone : FullScreenPlayer () {
@@ -141,7 +139,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
141139 }
142140 }
143141
144- var currentTrailers: List <Pair <ExtractorLink ,String >> = emptyList()
142+ var currentTrailers: List <Pair <ExtractorLink , String >> = emptyList()
145143 var currentTrailerIndex = 0
146144
147145 override fun nextMirror () {
@@ -164,25 +162,26 @@ open class ResultFragmentPhone : FullScreenPlayer() {
164162 private fun loadTrailer (index : Int? = null) {
165163
166164 val isSuccess =
167- currentTrailers.getOrNull(index ? : currentTrailerIndex)?.let { (extractedTrailerLink,_) ->
168- context?.let { ctx ->
169- player.onPause()
170- player.loadPlayer(
171- ctx,
172- false ,
173- extractedTrailerLink,
174- null ,
175- startPosition = 0L ,
176- subtitles = emptySet(),
177- subtitle = null ,
178- autoPlay = false ,
179- preview = false
180- )
181- true
165+ currentTrailers.getOrNull(index ? : currentTrailerIndex)
166+ ?.let { (extractedTrailerLink, _) ->
167+ context?.let { ctx ->
168+ player.onPause()
169+ player.loadPlayer(
170+ ctx,
171+ false ,
172+ extractedTrailerLink,
173+ null ,
174+ startPosition = 0L ,
175+ subtitles = emptySet(),
176+ subtitle = null ,
177+ autoPlay = false ,
178+ preview = false
179+ )
180+ true
181+ } ? : run {
182+ false
183+ }
182184 } ? : run {
183- false
184- }
185- } ? : run {
186185 false
187186 }
188187 // result_trailer_thumbnail?.setImageBitmap(result_poster_background?.drawable?.toBitmap())
@@ -191,7 +190,17 @@ open class ResultFragmentPhone : FullScreenPlayer() {
191190 // result_trailer_loading?.isVisible = isSuccess
192191 val turnVis = ! isSuccess && ! isFullScreenPlayer
193192 resultBinding?.apply {
194- resultTitle.isVisible = isSuccess
193+ // If we load a trailer, then cancel the big logo and only show the small title
194+ if (isSuccess) {
195+ // This is still a bit of a race condition, but it should work if we have the
196+ // trailers observe after the page observe!
197+ bindLogo(
198+ url = null ,
199+ headers = null ,
200+ logoView = backgroundPosterWatermarkBadge,
201+ titleView = resultTitle
202+ )
203+ }
195204 resultSmallscreenHolder.isVisible = turnVis
196205 resultPosterBackgroundHolder.apply {
197206 val fadeIn: Animation = AlphaAnimation (alpha, if (turnVis) 1.0f else 0.0f ).apply {
@@ -227,7 +236,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
227236 // }
228237 }
229238
230- private fun setTrailers (trailers : List <Pair <ExtractorLink ,String >>? ) {
239+ private fun setTrailers (trailers : List <Pair <ExtractorLink , String >>? ) {
231240 context?.updateHasTrailers()
232241 if (! LoadResponse .isTrailersEnabled) return
233242 currentTrailers = trailers?.sortedBy { - it.first.quality } ? : emptyList()
@@ -571,7 +580,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
571580
572581 playerBinding?.apply {
573582 playerOpenSource.setOnClickListener {
574- currentTrailers.getOrNull(currentTrailerIndex)?.let {(_,ogTrailerLink)->
583+ currentTrailers.getOrNull(currentTrailerIndex)?.let { (_, ogTrailerLink) ->
575584 context?.openBrowser(ogTrailerLink)
576585 }
577586 }
@@ -683,10 +692,6 @@ open class ResultFragmentPhone : FullScreenPlayer() {
683692 binding?.resultFavorite?.setImageResource(drawable)
684693 }
685694
686- observe(viewModel.trailers) { trailers ->
687- setTrailers(trailers.flatMap { it.mirros }) // I dont care about subtitles yet!
688- }
689-
690695 observeNullable(viewModel.episodes) { episodes ->
691696 resultBinding?.apply {
692697 // no failure?
@@ -803,31 +808,12 @@ open class ResultFragmentPhone : FullScreenPlayer() {
803808 }
804809 }
805810
806- if (! d.logoUrl.isNullOrBlank()) {
807- backgroundPosterWatermarkBadge.isVisible = true
808- resultTitle.isVisible = false
809-
810- backgroundPosterWatermarkBadge.loadImage(
811- imageData = UiImage .Image (d.logoUrl,headers = d.posterHeaders),
812- builder = {
813- listener(
814- onSuccess = { _, _ ->
815- backgroundPosterWatermarkBadge.isVisible = true
816- resultTitle.isVisible = false
817- },
818- onError = { _, _ ->
819- backgroundPosterWatermarkBadge.isVisible = false
820- resultTitle.isVisible = true
821- }
822- )
823- }
824- )
825-
826- } else {
827- backgroundPosterWatermarkBadge.isVisible = false
828- resultTitle.isVisible = true
829- }
830-
811+ bindLogo(
812+ url = d.logoUrl,
813+ headers = d.posterHeaders,
814+ titleView = resultTitle,
815+ logoView = backgroundPosterWatermarkBadge
816+ )
831817
832818 var isExpanded = false
833819 resultDescription.apply {
@@ -945,6 +931,10 @@ open class ResultFragmentPhone : FullScreenPlayer() {
945931 }
946932 }
947933
934+ observe(viewModel.trailers) { trailers ->
935+ setTrailers(trailers.flatMap { it.mirros }) // I dont care about subtitles yet!
936+ }
937+
948938 observe(syncModel.synced) { list ->
949939 syncBinding?.resultSyncNames?.text =
950940 list.filter { it.isSynced && it.hasAccount }.joinToString { it.name }
0 commit comments