adding a helper function for Material You date and time picker themes
This commit is contained in:
parent
2ef6d8a03a
commit
b0bdd457be
3 changed files with 25 additions and 5 deletions
|
@ -1460,7 +1460,7 @@ fun Activity.showPickSecondsDialog(
|
|||
}
|
||||
-3 -> {
|
||||
TimePickerDialog(
|
||||
this, getDialogTheme(),
|
||||
this, getTimePickerDialogTheme(),
|
||||
{ view, hourOfDay, minute -> callback(hourOfDay * -3600 + minute * -60) },
|
||||
curSeconds / 3600, curSeconds % 3600, baseConfig.use24HourFormat
|
||||
).show()
|
||||
|
|
|
@ -77,8 +77,18 @@ fun Context.isWhiteTheme() = baseConfig.textColor == DARK_GREY && baseConfig.pri
|
|||
|
||||
fun Context.isUsingSystemDarkTheme() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_YES != 0
|
||||
|
||||
fun Context.getDialogTheme() = when {
|
||||
baseConfig.isUsingSystemTheme -> R.style.MyDialogMaterialTheme
|
||||
fun Context.getTimePickerDialogTheme() = when {
|
||||
baseConfig.isUsingSystemTheme -> if (isUsingSystemDarkTheme()) {
|
||||
R.style.MyTimePickerMaterialTheme_Dark
|
||||
} else {
|
||||
R.style.MyDateTimePickerMaterialTheme
|
||||
}
|
||||
baseConfig.backgroundColor.getContrastColor() == Color.WHITE -> R.style.MyDialogTheme_Dark
|
||||
else -> R.style.MyDialogTheme
|
||||
}
|
||||
|
||||
fun Context.getDatePickerDialogTheme() = when {
|
||||
baseConfig.isUsingSystemTheme -> R.style.MyDateTimePickerMaterialTheme
|
||||
baseConfig.backgroundColor.getContrastColor() == Color.WHITE -> R.style.MyDialogTheme_Dark
|
||||
else -> R.style.MyDialogTheme
|
||||
}
|
||||
|
|
|
@ -113,8 +113,8 @@
|
|||
<item name="android:textColor">@color/theme_dark_text_color</item>
|
||||
</style>
|
||||
|
||||
<!-- used at Date and Time pickers -->
|
||||
<style name="MyDialogMaterialTheme" parent="@style/Theme.AppCompat.Light.Dialog">
|
||||
<!-- Used at dark Material You Time picker. Some of its parts cannot be customized through themes, we use these hacky ways. -->
|
||||
<style name="MyTimePickerMaterialTheme.Dark" parent="@android:style/Theme.DeviceDefault.Dialog">
|
||||
<item name="colorAccent">@color/you_primary_color</item>
|
||||
<item name="android:colorAccent">@color/you_primary_color</item>
|
||||
<item name="android:windowBackground">@drawable/dialog_you_background</item>
|
||||
|
@ -123,6 +123,16 @@
|
|||
<item name="android:textColorPrimary">@color/you_neutral_text_color</item>
|
||||
</style>
|
||||
|
||||
<!-- Used at both dark and light Material You Date pickers and light Time Picker, as otherwise it glitches -->
|
||||
<style name="MyDateTimePickerMaterialTheme" parent="@style/Theme.AppCompat.Light.Dialog">
|
||||
<item name="colorAccent">@color/you_primary_color</item>
|
||||
<item name="android:colorAccent">@color/you_primary_color</item>
|
||||
<item name="android:windowBackground">@drawable/dialog_you_background</item>
|
||||
<item name="android:textColor">@color/you_primary_color</item>
|
||||
<item name="android:textColorPrimary">@color/you_neutral_text_color</item>
|
||||
<item name="android:textColorSecondary">@color/you_neutral_text_color</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
|
|
Loading…
Reference in a new issue