From b0bdd457be6b452bec6905fde15195bc80c635c3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 8 Apr 2022 21:48:50 +0200 Subject: [PATCH] adding a helper function for Material You date and time picker themes --- .../commons/extensions/Activity.kt | 2 +- .../commons/extensions/Context-styling.kt | 14 ++++++++++++-- commons/src/main/res/values/styles.xml | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt index 716a16bd3..0e7ea1e8f 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt @@ -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() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt index d62bc0c3a..dd5bd6bde 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt @@ -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 } diff --git a/commons/src/main/res/values/styles.xml b/commons/src/main/res/values/styles.xml index 70d1865c3..c5901f866 100644 --- a/commons/src/main/res/values/styles.xml +++ b/commons/src/main/res/values/styles.xml @@ -113,8 +113,8 @@ @color/theme_dark_text_color - - + + +