From 4688f7d43cc6532f8de1024b2dc755487d095d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 5 Aug 2023 21:57:09 +0100 Subject: [PATCH] Fix chart legend text color on dark theme --- .../freeyourgadget/gadgetbridge/GBApplication.java | 13 +++++++++---- .../activities/BatteryInfoChartFragment.java | 2 +- .../charts/AbstractActivityChartFragment.java | 2 +- .../activities/charts/StressChartFragment.java | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 1414d06d7..8c0e2d2d7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -1329,10 +1329,15 @@ public class GBApplication extends Application { } public static int getTextColor(Context context) { - TypedValue typedValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.textColorPrimary, typedValue, true); - return typedValue.data; + if (GBApplication.isDarkThemeEnabled()) { + return context.getResources().getColor(R.color.primarytext_dark); + } else { + return context.getResources().getColor(R.color.primarytext_light); + } + } + + public static int getSecondaryTextColor(Context context) { + return context.getResources().getColor(R.color.secondarytext); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/BatteryInfoChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/BatteryInfoChartFragment.java index e367629c4..afcc86a01 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/BatteryInfoChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/BatteryInfoChartFragment.java @@ -125,7 +125,7 @@ public class BatteryInfoChartFragment extends AbstractGBFragment { private void init() { BACKGROUND_COLOR = GBApplication.getBackgroundColor(getContext()); LEGEND_TEXT_COLOR = DESCRIPTION_COLOR = GBApplication.getTextColor(getContext()); - CHART_TEXT_COLOR = ContextCompat.getColor(getContext(), R.color.secondarytext); + CHART_TEXT_COLOR = GBApplication.getSecondaryTextColor(getContext()); BATTERY_LABEL = getString(R.string.battery_level); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java index 67ebd6be6..0d7359b89 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java @@ -101,7 +101,7 @@ public abstract class AbstractActivityChartFragment extend TypedValue runningColor = new TypedValue(); BACKGROUND_COLOR = GBApplication.getBackgroundColor(getContext()); LEGEND_TEXT_COLOR = DESCRIPTION_COLOR = GBApplication.getTextColor(getContext()); - CHART_TEXT_COLOR = ContextCompat.getColor(getContext(), R.color.secondarytext); + CHART_TEXT_COLOR = GBApplication.getSecondaryTextColor(getContext()); if (prefs.getBoolean("chart_heartrate_color", false)) { HEARTRATE_COLOR = ContextCompat.getColor(getContext(), R.color.chart_heartrate_alternative); }else{ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java index d587e900a..ea0163261 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java @@ -84,7 +84,7 @@ public class StressChartFragment extends AbstractChartFragment