Skip to content

Commit

Permalink
Do not offer dynamic theme for widgets below API 31
Browse files Browse the repository at this point in the history
  • Loading branch information
nevenz committed Sep 20, 2022
1 parent 4ee8529 commit c865d0e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 12 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/orgzly/android/widgets/WidgetColors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ object WidgetColors {
)
)

// TODO:
val colorDayNight = mapOf(
val dataDependentColors = mapOf(
"dynamic-day" to mapOf(
"todo" to R.color.widget_light_state_todo_color,
"done" to R.color.widget_light_state_done_color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object WidgetStyle {

@ColorInt
private fun getColor(context: Context, scheme: String, name: String): Int {
val s = WidgetColors.colorDayNight[scheme]?.get(name).let { value ->
val s = WidgetColors.dataDependentColors[scheme]?.get(name).let { value ->
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "$scheme/$name: $value")
value ?: throw Exception("Not defined: $scheme/$name")
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_list_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_list_widget_layout"
android:theme="@style/Theme.Material3.DynamicColors.DayNight"
android:theme="@style/ListWidgetTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_list_widget_divider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_list_item_divider_value"
android:theme="@style/Theme.Material3.DynamicColors.DayNight"
android:theme="@style/ListWidgetTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/list_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/Theme.Material3.DynamicColors.DayNight"
android:theme="@style/ListWidgetTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/values-v31/prefs_keys.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<resources xmlns:tools="http://schemas.android.com/tools">
<string-array name="widget_color_scheme" tools:ignore="InconsistentArrays">
<item>@string/color_scheme_dynamic</item>
<item>@string/color_scheme_light</item>
<item>@string/color_scheme_dark</item>
<item>@string/color_scheme_black</item>
</string-array>
<string-array name="widget_color_scheme_values" tools:ignore="InconsistentArrays">
<item>dynamic</item>
<item>light</item>
<item>dark</item>
<item>black</item>
</string-array>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values-v31/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<style name="ListWidgetTheme" parent="Theme.Material3.DynamicColors.DayNight" />
</resources>
8 changes: 3 additions & 5 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Overwrite system Locale -->
<string name="pref_key_ignore_system_locale" translatable="false">pref_key_ignore_system_locale</string>
<bool name="pref_default_ignore_system_locale" translatable="false">false</bool>
Expand Down Expand Up @@ -510,14 +510,12 @@

<string name="pref_key_widget_color_scheme" translatable="false">pref_key_widget_color_scheme</string>
<string name="pref_default_widget_color_scheme" translatable="false">light</string>
<string-array name="widget_color_scheme">
<item>@string/color_scheme_dynamic</item>
<string-array name="widget_color_scheme" tools:ignore="InconsistentArrays">
<item>@string/color_scheme_light</item>
<item>@string/color_scheme_dark</item>
<item>@string/color_scheme_black</item>
</string-array>
<string-array name="widget_color_scheme_values">
<item>dynamic</item>
<string-array name="widget_color_scheme_values" tools:ignore="InconsistentArrays">
<item>light</item>
<item>dark</item>
<item>black</item>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
<item name="colorTertiaryContainer">@color/grey_800</item>
<item name="colorOnTertiaryContainer">@color/grey_400</item>
<item name="colorError">@color/red_200</item>

</style>

<!-- Color scheme -->
Expand Down Expand Up @@ -225,6 +224,8 @@
<!--<item name="android:textAppearanceMedium">@style/TextAppearance.AppCompat.Large</item>-->
</style>

<style name="ListWidgetTheme" parent="Theme.Material3.DynamicColors.DayNight" />

<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="tint">?android:textColorPrimary</item>
</style>
Expand Down

0 comments on commit c865d0e

Please sign in to comment.