Rename LocalTimeZone -> LocalZoneId + collects with lifecycle

Change-Id: I429c563765a489965d0a1741e36c98a30e5d0ef3
pull/1837/head
Tomáš Mlynarič 2 years ago
parent 64a325ae6c
commit e19d435317

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

@ -20,7 +20,7 @@ import androidx.compose.runtime.compositionLocalOf
import java.time.ZoneId 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. * 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 fun dateFormatted(publishDate: Instant): String = DateTimeFormatter
.ofLocalizedDate(FormatStyle.MEDIUM) .ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(Locale.getDefault()) .withLocale(Locale.getDefault())
.withZone(LocalTimeZone.current) .withZone(LocalZoneId.current)
.format(publishDate.toJavaInstant()) .format(publishDate.toJavaInstant())
@Composable @Composable

Loading…
Cancel
Save