Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/src/main/kotlin/com/arflix/tv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ class MainActivity : ComponentActivity() {
DeviceType.PHONE -> ActivityInfo.SCREEN_ORIENTATION_FULL_USER
}

// Keep screen on during playback
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

// All devices use edge-to-edge (setDecorFitsSystemWindows=false).
// TV hides the bars; mobile keeps them visible and Compose handles
// insets via systemBarsPadding() in the root layout.
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/kotlin/com/arflix/tv/ui/components/KeepScreenOn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.arflix.tv.ui.components

import android.app.Activity
import android.content.ContextWrapper
import android.view.WindowManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext

/**
* Keeps the screen on while this composable is in the composition and [active] is true.
* Releases the flag when [active] becomes false or the composable leaves composition.
*
* Use in any screen where media is playing (player, live TV, trailer).
*/
@Composable
fun KeepScreenOn(active: Boolean = true) {
val context = LocalContext.current
DisposableEffect(active) {
if (!active) return@DisposableEffect onDispose {}
val window = generateSequence(context) { (it as? ContextWrapper)?.baseContext }
.filterIsInstance<Activity>()
.firstOrNull()
?.window
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
onDispose {
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import com.arflix.tv.data.model.MediaType
import com.arflix.tv.data.model.Review
import com.arflix.tv.network.OkHttpProvider
import com.arflix.tv.ui.components.EpisodeContextMenu
import com.arflix.tv.ui.components.KeepScreenOn
import com.arflix.tv.ui.components.SeasonContextMenu
import com.arflix.tv.ui.components.LoadingIndicator
import com.arflix.tv.ui.components.AppTopBar
Expand Down Expand Up @@ -228,6 +229,7 @@ fun DetailsScreen(
// Stream Selector state
var showStreamSelector by remember { mutableStateOf(false) }
var showTrailerPlayer by remember { mutableStateOf(false) }
KeepScreenOn(active = showTrailerPlayer)
var pendingAutoPlayRequest by remember { mutableStateOf<PendingAutoPlayRequest?>(null) }

// Episode Context Menu state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import com.arflix.tv.network.OkHttpProvider
import com.arflix.tv.data.model.MediaType
import com.arflix.tv.data.model.StreamSource
import com.arflix.tv.data.model.Subtitle
import com.arflix.tv.ui.components.KeepScreenOn
import com.arflix.tv.ui.components.LoadingIndicator
import com.arflix.tv.ui.components.Toast
import com.arflix.tv.ui.components.ToastType
Expand Down Expand Up @@ -302,6 +303,7 @@ fun PlayerScreen(
onDispose { }
}

KeepScreenOn()
var isPlaying by remember { mutableStateOf(false) }
var isBuffering by remember { mutableStateOf(true) }
var hasPlaybackStarted by remember { mutableStateOf(false) } // Track if playback has actually started
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/com/arflix/tv/ui/screens/tv/TvScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import com.arflix.tv.data.model.IptvNowNext
import com.arflix.tv.data.model.IptvProgram
import com.arflix.tv.network.OkHttpProvider
import com.arflix.tv.ui.components.AppTopBar
import com.arflix.tv.ui.components.KeepScreenOn
import com.arflix.tv.ui.components.AppTopBarContentTopInset
import com.arflix.tv.util.LocalDeviceType
import com.arflix.tv.ui.components.SidebarItem
Expand Down Expand Up @@ -240,6 +241,7 @@ fun TvScreen(
var channelIndex by rememberSaveable { mutableIntStateOf(0) }
var selectedChannelId by rememberSaveable { mutableStateOf<String?>(null) }
var playingChannelId by rememberSaveable { mutableStateOf<String?>(null) }
KeepScreenOn(active = playingChannelId != null)
var showGroupContextMenu by remember { mutableStateOf(false) }
// When launched from Home with a stream URL, start in fullscreen immediately
// to avoid a flash of the TV page channel list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import com.arflix.tv.ui.screens.tv.TvUiState
import com.arflix.tv.ui.screens.tv.TvViewModel
import com.arflix.tv.network.OkHttpProvider
import com.arflix.tv.ui.components.AppTopBar
import com.arflix.tv.ui.components.KeepScreenOn
import com.arflix.tv.ui.components.AppTopBarHeight
import com.arflix.tv.ui.components.SidebarItem
import com.arflix.tv.ui.components.topBarFocusedItem
Expand Down Expand Up @@ -519,6 +520,7 @@ fun LiveTvScreen(
// channel of the first non-empty category.
val rememberedChannelByCategory = remember { mutableMapOf<String, String>() }
var playingChannelId by rememberSaveable { mutableStateOf<String?>(initialChannelId) }
KeepScreenOn(active = playingChannelId != null)
var focusedChannelId by rememberSaveable { mutableStateOf<String?>(initialChannelId) }
var epgPrefetchAnchorId by rememberSaveable { mutableStateOf<String?>(initialChannelId) }
var startupChannelApplied by rememberSaveable(selectedProviderId) { mutableStateOf(false) }
Expand Down
Loading