feat(live): keep screen awake while watching a live stream
Add FLAG_KEEP_SCREEN_ON to the host activity window while LiveStreamScreen is composed, mirroring the behavior already used by the fullscreen video player. The flag is cleared on dispose so it does not leak to other screens.
This commit is contained in:
@@ -53,6 +53,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -147,6 +148,15 @@ fun LiveStreamScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val context = LocalContext.current
|
||||
DisposableEffect(context) {
|
||||
val window = context.findHostActivity()?.window
|
||||
window?.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
onDispose {
|
||||
window?.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
// Top bar
|
||||
TopAppBar(
|
||||
@@ -1088,3 +1098,12 @@ private fun formatZapSats(sats: Long): String = when {
|
||||
sats >= 1_000 -> "${"%.1f".format(sats / 1_000.0)}k"
|
||||
else -> sats.toString()
|
||||
}
|
||||
|
||||
private fun android.content.Context.findHostActivity(): android.app.Activity? {
|
||||
var ctx: android.content.Context = this
|
||||
while (ctx is android.content.ContextWrapper) {
|
||||
if (ctx is android.app.Activity) return ctx
|
||||
ctx = ctx.baseContext
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user