@@ -59,6 +59,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectSt
5959import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarMargin
6060import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
6161import com.lagradost.cloudstream3.utils.UIHelper.populateChips
62+ import androidx.core.graphics.toColorInt
6263
6364class HomeParentItemAdapterPreview (
6465 val fragment : LifecycleOwner ,
@@ -339,41 +340,44 @@ class HomeParentItemAdapterPreview(
339340
340341 fun onSelect (item : LoadResponse , position : Int ) {
341342 (binding as ? FragmentHomeHeadTvBinding )?.apply {
342- homePreviewDescription.isGone =
343- item.plot.isNullOrBlank()
344- homePreviewDescription.text =
345- item.plot?.html() ? : " "
346-
347- homePreviewDescription.text =
348- item.plot?.html() ? : " "
349-
350- homePreviewScore.text = item.score?.let { score ->
351- homePreviewScore.context.getString(R .string.extension_rating, score.toString())
352- } ? : " "
353-
354- item.score?.toString()?.toDoubleOrNull()?.let { rating ->
343+ homePreviewDescription.isGone = item.plot.isNullOrBlank()
344+ homePreviewDescription.text = item.plot?.html() ? : " "
345+
346+ val scoreText = item.score?.toStringNull(0.1 , 10 , 1 , false )
347+
348+ scoreText?.let { score ->
349+ homePreviewScore.text =
350+ homePreviewScore.context.getString(R .string.extension_rating, score)
351+
352+ // while it should never fail, we do this just in case
353+ val rating = score.toDoubleOrNull() ? : item.score?.toDouble() ? : 0.0
354+
355355 val color = when {
356- rating < 5.0 -> android.graphics. Color .parseColor( " #eb2f2f" ) // Red
357- rating < 8.0 -> android.graphics. Color .parseColor( " #eda009" ) // Yellow
358- else -> android.graphics. Color .parseColor( " #3bb33b" ) // Green
356+ rating < 5.0 -> " #eb2f2f" .toColorInt( ) // Red
357+ rating < 8.0 -> " #eda009" .toColorInt( ) // Yellow
358+ else -> " #3bb33b" .toColorInt( ) // Green
359359 }
360- homePreviewScore.backgroundTintList = android.content.res. ColorStateList .valueOf(color)
361- homePreviewScore.setTextColor( android.graphics. Color . WHITE )
360+ homePreviewScore.backgroundTintList =
361+ android.content.res. ColorStateList .valueOf(color )
362362 }
363-
364- homePreviewScore.isGone = item.score == null
363+ homePreviewScore.isGone = scoreText == null
365364
366- homePreviewYear.text = item.year?.toString() ? : " "
365+ item.year?.let { year ->
366+ homePreviewYear.text = year.toString()
367+ }
367368 homePreviewYear.isGone = item.year == null
368369
369- homePreviewDuration.text = item.duration?.let { min ->
370- homePreviewDuration.context.getString(R .string.duration_format, min)
371- } ? : " "
372- homePreviewDuration.isGone = item.duration == null
370+ val duration = item.duration
371+ duration?.let { min ->
372+ homePreviewDuration.text =
373+ homePreviewDuration.context.getString(R .string.duration_format, min)
374+ }
375+ homePreviewDuration.isGone = duration == null || duration <= 0
373376
374- val castText = item.actors?.take(3 )?.mapNotNull { it.actor.name }?.joinToString( " , " )
377+ val castText = item.actors?.take(3 )?.joinToString( " , " ) { it.actor.name }
375378 if (! castText.isNullOrBlank()) {
376- homePreviewCast.text = homePreviewCast.context.getString(R .string.cast_format, castText)
379+ homePreviewCast.text =
380+ homePreviewCast.context.getString(R .string.cast_format, castText)
377381 homePreviewCast.isVisible = true
378382 } else {
379383 homePreviewCast.isVisible = false
0 commit comments