package tv.tivilux.nativeplayer.ui.screens import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import tv.tivilux.nativeplayer.R import tv.tivilux.nativeplayer.StartupStage import tv.tivilux.nativeplayer.ui.components.LuxBackground import tv.tivilux.nativeplayer.ui.theme.LuxGold import tv.tivilux.nativeplayer.ui.theme.LuxLine import tv.tivilux.nativeplayer.ui.theme.LuxMuted import tv.tivilux.nativeplayer.ui.theme.LuxPanel import tv.tivilux.nativeplayer.ui.theme.LuxText @Composable fun StartupLoadingScreen( stage: StartupStage, progress: Float, detail: String, liveCount: Int, epgCompleted: Int, epgFound: Int, epgTotal: Int, movieCount: Int, seriesCount: Int, ) { val overall = overallProgress(stage, progress) val percent = (overall * 100f).toInt().coerceIn(0, 100) val stageTitle = when (stage) { StartupStage.LIVE -> "Loading Live TV" StartupStage.EPG -> "Preparing TV Guide" StartupStage.LIBRARY -> "Loading Movies & Series" StartupStage.READY -> "Ready" } val stageSubtitle = when (stage) { StartupStage.LIVE -> "Building your channel lineup" StartupStage.EPG -> "Preparing guide data for fast browsing" StartupStage.LIBRARY -> "Indexing your on-demand library" StartupStage.READY -> "Opening TiviLux" } LuxBackground { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Column( modifier = Modifier.width(680.dp).padding(horizontal = 36.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { Image( painter = painterResource(R.drawable.tivilux_wordmark), contentDescription = "TiviLux", modifier = Modifier.width(205.dp).height(70.dp), ) Spacer(Modifier.height(24.dp)) Text( "Preparing your television", color = LuxText, fontSize = 31.sp, fontWeight = FontWeight.SemiBold, ) Spacer(Modifier.height(8.dp)) Text( "One fast setup pass. Your library is cached on this device for quicker launches after this.", color = LuxMuted, fontSize = 13.sp, textAlign = TextAlign.Center, ) Spacer(Modifier.height(30.dp)) Box( Modifier .fillMaxWidth() .background(LuxPanel.copy(alpha = .88f), RoundedCornerShape(18.dp)) .border(1.dp, LuxLine, RoundedCornerShape(18.dp)) .padding(horizontal = 24.dp, vertical = 22.dp) ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Text( "$percent%", color = LuxText, fontSize = 54.sp, fontWeight = FontWeight.Bold, ) Spacer(Modifier.height(12.dp)) LinearProgressIndicator( progress = { overall }, modifier = Modifier.fillMaxWidth().height(7.dp), color = LuxGold, trackColor = Color.White.copy(alpha = .08f), ) Spacer(Modifier.height(18.dp)) Text( stageTitle, color = LuxGold, fontSize = 15.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.0.sp, ) Spacer(Modifier.height(5.dp)) Text( stageSubtitle, color = LuxMuted, fontSize = 11.sp, textAlign = TextAlign.Center, ) } } Spacer(Modifier.height(18.dp)) Row( horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, ) { repeat(3) { index -> val activeIndex = when (stage) { StartupStage.LIVE -> 0 StartupStage.EPG -> 1 StartupStage.LIBRARY -> 2 StartupStage.READY -> 3 } Box( Modifier .width(if (index <= activeIndex) 30.dp else 18.dp) .height(4.dp) .background( if (index <= activeIndex) LuxGold else Color.White.copy(alpha = .10f), RoundedCornerShape(50), ) ) } } } } } } private fun overallProgress(stage: StartupStage, stageProgress: Float): Float { val p = stageProgress.coerceIn(0f, 1f) return when (stage) { StartupStage.LIVE -> p * .33f StartupStage.EPG -> .33f + p * .34f StartupStage.LIBRARY -> .67f + p * .33f StartupStage.READY -> 1f }.coerceIn(0f, 1f) }