Skip to content

Commit

Permalink
Fixed an issue where widgets would not respond properly to dark theme…
Browse files Browse the repository at this point in the history
… changes.
  • Loading branch information
hwki committed Jan 21, 2024
1 parent 36699e2 commit ad2e097
Show file tree
Hide file tree
Showing 25 changed files with 194 additions and 27 deletions.
4 changes: 2 additions & 2 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 34
versionCode 327
versionName "8.5.2"
versionCode 328
versionName "8.5.3"

}

Expand Down
49 changes: 32 additions & 17 deletions bitcoin/src/main/java/com/brentpanther/bitcoinwidget/Enums.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,38 @@ import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes

enum class Theme(@LayoutRes val lightPrice: Int, @LayoutRes val darkPrice: Int,
@LayoutRes val lightValue: Int, @LayoutRes val darkValue: Int) {

SOLID(R.layout.widget_price_solid_light, R.layout.widget_price_solid_dark,
R.layout.widget_value_solid_light, R.layout.widget_value_solid_dark),
TRANSPARENT(R.layout.widget_price_transparent_light, R.layout.widget_price_transparent_dark,
R.layout.widget_value_transparent_light, R.layout.widget_value_transparent_dark),
MATERIAL(R.layout.widget_price_material_light, R.layout.widget_price_material_dark,
R.layout.widget_value_material_light, R.layout.widget_value_material_dark),
TRANSPARENT_MATERIAL(R.layout.widget_price_transparent_light_material, R.layout.widget_price_transparent_dark_material,
R.layout.widget_value_transparent_light_material, R.layout.widget_value_transparent_dark_material);

fun getLayout(isDark: Boolean, type: WidgetType): Int {
return when(type) {
WidgetType.PRICE -> if (isDark) darkPrice else lightPrice
WidgetType.VALUE -> if (isDark) darkValue else lightValue
}
enum class Theme(@LayoutRes val lightPrice: Int, @LayoutRes val darkPrice: Int, @LayoutRes val autoPrice: Int,
@LayoutRes val lightValue: Int, @LayoutRes val darkValue: Int, @LayoutRes val autoValue: Int) {

SOLID(R.layout.widget_price_solid_light,
R.layout.widget_price_solid_dark,
R.layout.widget_price_solid_auto,
R.layout.widget_value_solid_light,
R.layout.widget_value_solid_dark,
R.layout.widget_value_solid_auto),
TRANSPARENT(R.layout.widget_price_transparent_light,
R.layout.widget_price_transparent_dark,
R.layout.widget_price_transparent_auto,
R.layout.widget_value_transparent_light,
R.layout.widget_value_transparent_dark,
R.layout.widget_value_transparent_auto),
MATERIAL(R.layout.widget_price_material_light,
R.layout.widget_price_material_dark,
R.layout.widget_price_material_auto,
R.layout.widget_value_material_light,
R.layout.widget_value_material_dark,
R.layout.widget_value_material_auto),
TRANSPARENT_MATERIAL(R.layout.widget_price_transparent_light_material,
R.layout.widget_price_transparent_dark_material,
R.layout.widget_price_transparent_auto_material,
R.layout.widget_value_transparent_light_material,
R.layout.widget_value_transparent_dark_material,
R.layout.widget_value_transparent_auto_material);

fun getLayout(mode: NightMode, type: WidgetType) = when(mode) {
NightMode.LIGHT -> if (type == WidgetType.PRICE) lightPrice else lightValue
NightMode.DARK -> if (type == WidgetType.PRICE) darkPrice else darkValue
NightMode.SYSTEM -> if (type == WidgetType.PRICE) autoPrice else autoValue
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract class PriceWidgetDisplayStrategy(context: Context, widget: Widget, widg
}

protected fun getView(@IdRes layoutId: Int): TextView {
val layout = widget.theme.getLayout(widget.nightMode.isDark(appContext), widget.widgetType)
val layout = widget.theme.getLayout(widget.nightMode, widget.widgetType)
val vg = LayoutInflater.from(appContext).inflate(layout, null) as ViewGroup
return vg.findViewById(layoutId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class ComposePreviewWidgetPresenter(widget: Widget, private val view: View) : Wi

init {
val context = view.context
val isDark = widget.nightMode.isDark(context)
val layout = widget.theme.getLayout(isDark, widget.widgetType)
val layout = widget.theme.getLayout(widget.nightMode, widget.widgetType)
view.findViewById<ViewGroup>(R.id.widgetContainer).apply {
removeAllViews()
View.inflate(context, layout, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class RemoteWidgetPresenter(context: Context, widget: Widget) : WidgetPresenter
private var remoteViews: RemoteViews

init {
val isDark = widget.nightMode.isDark(context)
val layout = widget.theme.getLayout(isDark, widget.widgetType)
val layout = widget.theme.getLayout(widget.nightMode, widget.widgetType)
remoteViews = RemoteViews(context.packageName, layout)
}

Expand Down
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout-night/widget_price_material_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Material">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout-night/widget_price_solid_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Transparent">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Transparent.Material">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout-night/widget_value_material_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Material">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout-night/widget_value_solid_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Transparent">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Dark.Transparent.Material">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout/widget_price_material_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Material">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout/widget_price_solid_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Light">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
9 changes: 9 additions & 0 deletions bitcoin/src/main/res/layout/widget_price_transparent_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Transparent">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Transparent.Material">

<include layout="@layout/widget_price_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout/widget_value_material_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Material">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
10 changes: 10 additions & 0 deletions bitcoin/src/main/res/layout/widget_value_solid_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_widget_solid"
android:theme="@style/Theme.MyApp.WidgetContainer.Light">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
9 changes: 9 additions & 0 deletions bitcoin/src/main/res/layout/widget_value_transparent_auto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Transparent">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.MyApp.WidgetContainer.Light.Transparent.Material">

<include layout="@layout/widget_value_solid" />

</FrameLayout>
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/xml/widget_price.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:updatePeriodMillis="0"
android:updatePeriodMillis="30000"
android:minWidth="110dp"
android:minHeight="40dp"
android:minResizeWidth="1dp"
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/xml/widget_value.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:updatePeriodMillis="0"
android:updatePeriodMillis="30000"
android:minWidth="110dp"
android:minHeight="40dp"
android:minResizeWidth="1dp"
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/328.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where widgets would not respond properly to dark theme changes.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#Sun Jul 25 18:15:31 CDT 2021
org.gradle.jvmargs=-Xmx2048M -XX:+UseParallelGC
android.useAndroidX=true
android.enableJetifier=true
org.gradle.unsafe.configuration-cache=true
android.nonTransitiveRClass=true
android.nonFinalResIds=false

0 comments on commit ad2e097

Please sign in to comment.