Rename LocalTimeZone -> LocalZoneId + collects with lifecycle

Change-Id: I429c563765a489965d0a1741e36c98a30e5d0ef3
pull/1187/head
Tomáš Mlynarič 10 months ago
parent 1e925ed99f
commit 44ae059a2b

@ -28,12 +28,12 @@ import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.metrics.performance.JankStats
@ -47,7 +47,7 @@ import com.google.samples.apps.nowinandroid.core.data.util.TimeZoneMonitor
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand
import com.google.samples.apps.nowinandroid.core.ui.LocalTimeZone
import com.google.samples.apps.nowinandroid.core.ui.LocalZoneId
import com.google.samples.apps.nowinandroid.ui.NiaApp
import com.google.samples.apps.nowinandroid.ui.rememberNiaAppState
import dagger.hilt.android.AndroidEntryPoint
@ -140,11 +140,11 @@ class MainActivity : ComponentActivity() {
timeZoneMonitor = timeZoneMonitor,
)
val currentTimeZone by appState.currentTimeZone.collectAsState()
val currentZoneId by appState.currentTimeZone.collectAsStateWithLifecycle()
CompositionLocalProvider(
LocalAnalyticsHelper provides analyticsHelper,
LocalTimeZone provides currentTimeZone,
LocalZoneId provides currentZoneId,
) {
NiaTheme(
darkTheme = darkTheme,

@ -20,7 +20,7 @@ import androidx.compose.runtime.compositionLocalOf
import java.time.ZoneId
/**
* TimeZone that can be provided with the TimeZoneMonitor.
* ZoneId that can be provided with the TimeZoneMonitor.
* This way, it's not needed to pass every single composable the time zone to show in UI.
*/
val LocalTimeZone = compositionLocalOf { ZoneId.systemDefault() }
val LocalZoneId = compositionLocalOf { ZoneId.systemDefault() }

@ -244,7 +244,7 @@ fun NotificationDot(
fun dateFormatted(publishDate: Instant): String = DateTimeFormatter
.ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(Locale.getDefault())
.withZone(LocalTimeZone.current)
.withZone(LocalZoneId.current)
.format(publishDate.toJavaInstant())
@Composable

Loading…
Cancel
Save