From aa10c09055c7f5edc8cc813b41dfba9d5af4417c Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sun, 8 Nov 2026 13:13:56 +0000 Subject: [PATCH] Profiling fix C: Tonight's Pick card painted once. Ported from release-0.108 Co-Authored-By: Claude Opus 5.5 --- .../src/main/java/tv/orbit/classic/WhatsOn.kt | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/tv/orbit/classic/WhatsOn.kt b/android/app/src/main/java/tv/orbit/classic/WhatsOn.kt index 9a770d11..2efd6bd2 100644 --- a/android/app/src/main/java/tv/orbit/classic/WhatsOn.kt +++ b/android/app/src/main/java/tv/orbit/classic/WhatsOn.kt @@ -19,6 +19,8 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight @@ -100,9 +102,20 @@ internal fun WhatsOnScreen(session: EmbySampleSession, plans: Map(null, picture, size) { + value = if (picture == null || size.width <= 0 || size.height <= 0) null + else kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) { runCatching { pickCard(picture, size.width, size.height) }.getOrNull() } + } + Box(Modifier.fillMaxSize().onSizeChanged { size = it }.background(Panel)) { + val baked = card + if (baked != null) Image(baked.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.FillBounds) + else { + if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop) + Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Navy.copy(alpha = .97f), .45f to Navy.copy(alpha = .88f), .75f to Navy.copy(alpha = .35f), 1f to Navy.copy(alpha = .15f)))) + } Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { Tag("TONIGHT'S PICK", Yellow, 11) Logo(pick.channel, 96, 30) @@ -222,3 +235,25 @@ internal fun ProgrammeReminderCard(reminder: ProgrammeReminder, nowMs: Long, onW } } + + +/** + * Tonight's Pick's card, painted once (profiling fix C): the panel colour, the picture cropped to fill the card as + * ContentScale.Crop does, and the same left-to-right navy fade, all in one bitmap of the card's size. + */ +internal fun pickCard(picture: android.graphics.Bitmap, width: Int, height: Int): android.graphics.Bitmap { + val out = android.graphics.Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888) + val canvas = android.graphics.Canvas(out) + canvas.drawColor(Panel.toArgb()) + val scale = maxOf(width.toFloat() / picture.width, height.toFloat() / picture.height) + val w = picture.width * scale; val h = picture.height * scale + val dst = android.graphics.RectF((width - w) / 2f, (height - h) / 2f, (width + w) / 2f, (height + h) / 2f) + canvas.drawBitmap(picture, null, dst, android.graphics.Paint(android.graphics.Paint.FILTER_BITMAP_FLAG)) + val fade = android.graphics.Paint().apply { + shader = android.graphics.LinearGradient(0f, 0f, width.toFloat(), 0f, + intArrayOf(Navy.copy(alpha = .97f).toArgb(), Navy.copy(alpha = .88f).toArgb(), Navy.copy(alpha = .35f).toArgb(), Navy.copy(alpha = .15f).toArgb()), + floatArrayOf(0f, .45f, .75f, 1f), android.graphics.Shader.TileMode.CLAMP) + } + canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), fade) + return out +}