Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
fix: respect system 24-hour time setting#1111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
91e9b4ac54dc978ca5c38d595b70f292f6336978bb3e900240a102b03e0713eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package to.bitkit.ui.utils | ||
| import android.content.BroadcastReceiver | ||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.content.IntentFilter | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.DisposableEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.core.content.ContextCompat | ||
| import to.bitkit.ext.UiDateStyle | ||
| import to.bitkit.ext.dateTimeFormatterOf | ||
| import to.bitkit.ext.is24HourTimeFormat | ||
| import to.bitkit.ui.LocalIs24HourFormat | ||
| import java.time.Instant | ||
| import java.time.ZoneId | ||
| import java.util.Locale | ||
| @Composable | ||
| fun uiDateText( | ||
| timestamp: ULong, | ||
| style: UiDateStyle, | ||
| locale: Locale = Locale.getDefault(), | ||
| zone: ZoneId = ZoneId.systemDefault(), | ||
jvsena42 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ): String { | ||
| val is24Hour = LocalIs24HourFormat.current | ||
| val formatter = remember(style, is24Hour, locale, zone) { | ||
| dateTimeFormatterOf(style.pattern(is24Hour), locale, zone) | ||
| } | ||
| return remember(formatter, timestamp) { formatter.format(Instant.ofEpochSecond(timestamp.toLong())) } | ||
| } | ||
| @Composable | ||
| fun rememberIs24HourFormat(context: Context = LocalContext.current): Boolean { | ||
| var is24Hour by remember(context) { mutableStateOf(context.is24HourTimeFormat) } | ||
| DisposableEffect(context) { | ||
| val receiver = object : BroadcastReceiver() { | ||
| override fun onReceive(receiverContext: Context?, intent: Intent?) = run { | ||
| is24Hour = context.is24HourTimeFormat | ||
| } | ||
| } | ||
| ContextCompat.registerReceiver( | ||
| context, | ||
| receiver, | ||
| IntentFilter(Intent.ACTION_TIME_CHANGED), | ||
| ContextCompat.RECEIVER_NOT_EXPORTED, | ||
| ) | ||
jvsena42 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| onDispose { context.unregisterReceiver(receiver) } | ||
| } | ||
| return is24Hour | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.