-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91e9b4a
fix: respect system 24-hour time setting
guzino c54dc97
chore: rename changelog fragment
guzino 8ca5c38
fix: observe system clock format changes
guzino d595b70
refactor: move uiDateText to ui utils
guzino f292f63
Merge branch 'master' into fix/system-time-format
guzino 36978bb
Merge branch 'master' into fix/system-time-format
guzino 3e90024
refactor: provide clock format via composition local
guzino 0a102b0
refactor: extract pure uiDateStyleFor into ext
guzino 3e0713e
refactor: simplify clock format local
guzino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
|
||
| ): 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.
|
||
|
|
||
| onDispose { context.unregisterReceiver(receiver) } | ||
| } | ||
|
|
||
| return is24Hour | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.