Show time on playback overlay (#336)

If enable, show the current time in the upper right corner of the
playback overlay/controls

Closes #219
This commit is contained in:
damontecres 2025-11-28 13:03:41 -05:00 committed by GitHub
parent babfe011a1
commit 8bc6fce0cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 22 deletions

View file

@ -11,7 +11,7 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
import java.util.Locale import java.util.Locale
val TimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) val TimeFormatter: DateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
/** /**
* Format a [LocalDateTime] as `Aug 24, 2000` * Format a [LocalDateTime] as `Aug 24, 2000`

View file

@ -0,0 +1,40 @@
package com.github.damontecres.wholphin.ui.components
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.github.damontecres.wholphin.ui.TimeFormatter
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import java.time.LocalTime
@Composable
fun BoxScope.TimeDisplay(modifier: Modifier = Modifier) {
var now by remember { mutableStateOf(LocalTime.now()) }
LaunchedEffect(Unit) {
while (isActive) {
now = LocalTime.now()
delay(1000L)
}
}
Text(
text = TimeFormatter.format(now),
fontSize = 18.sp,
color = MaterialTheme.colorScheme.onSurface,
modifier =
modifier
.align(Alignment.TopEnd)
.padding(vertical = 16.dp, horizontal = 24.dp),
)
}

View file

@ -32,7 +32,6 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
@ -77,7 +76,7 @@ import com.github.damontecres.wholphin.preferences.AppThemeColors
import com.github.damontecres.wholphin.preferences.UserPreferences import com.github.damontecres.wholphin.preferences.UserPreferences
import com.github.damontecres.wholphin.services.NavigationManager import com.github.damontecres.wholphin.services.NavigationManager
import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.FontAwesome
import com.github.damontecres.wholphin.ui.TimeFormatter import com.github.damontecres.wholphin.ui.components.TimeDisplay
import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.ifElse
import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.launchIO
import com.github.damontecres.wholphin.ui.preferences.PreferenceScreenOption import com.github.damontecres.wholphin.ui.preferences.PreferenceScreenOption
@ -89,11 +88,9 @@ import com.github.damontecres.wholphin.ui.tryRequestFocus
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jellyfin.sdk.model.api.CollectionType import org.jellyfin.sdk.model.api.CollectionType
import org.jellyfin.sdk.model.api.DeviceProfile import org.jellyfin.sdk.model.api.DeviceProfile
import java.time.LocalTime
import java.util.UUID import java.util.UUID
import javax.inject.Inject import javax.inject.Inject
@ -498,23 +495,7 @@ fun NavDrawer(
.fillMaxSize(), .fillMaxSize(),
) )
if (preferences.appPreferences.interfacePreferences.showClock) { if (preferences.appPreferences.interfacePreferences.showClock) {
var now by remember { mutableStateOf(LocalTime.now()) } TimeDisplay()
LaunchedEffect(Unit) {
while (isActive) {
now = LocalTime.now()
delay(1000L)
}
}
Text(
text = TimeFormatter.format(now),
// style = MaterialTheme.typography.titleMedium,
fontSize = 18.sp,
color = MaterialTheme.colorScheme.onSurface,
modifier =
Modifier
.align(Alignment.TopEnd)
.padding(vertical = 16.dp, horizontal = 24.dp),
)
} }
} }
} }

View file

@ -56,6 +56,7 @@ import com.github.damontecres.wholphin.ui.AspectRatios
import com.github.damontecres.wholphin.ui.TimeFormatter import com.github.damontecres.wholphin.ui.TimeFormatter
import com.github.damontecres.wholphin.ui.cards.ChapterCard import com.github.damontecres.wholphin.ui.cards.ChapterCard
import com.github.damontecres.wholphin.ui.cards.SeasonCard import com.github.damontecres.wholphin.ui.cards.SeasonCard
import com.github.damontecres.wholphin.ui.components.TimeDisplay
import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.ifElse
import com.github.damontecres.wholphin.ui.isNotNullOrBlank import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import com.github.damontecres.wholphin.ui.tryRequestFocus import com.github.damontecres.wholphin.ui.tryRequestFocus
@ -395,6 +396,14 @@ fun PlaybackOverlay(
.padding(16.dp), .padding(16.dp),
) )
} }
AnimatedVisibility(
!showDebugInfo && showClock && controllerViewState.controlsVisible,
modifier =
Modifier
.align(Alignment.TopEnd),
) {
TimeDisplay()
}
AnimatedVisibility( AnimatedVisibility(
showDebugInfo && controllerViewState.controlsVisible, showDebugInfo && controllerViewState.controlsVisible,
modifier = modifier =