diff --git a/src/main/java/eu/siacs/conversations/Conversations.java b/src/main/java/eu/siacs/conversations/Conversations.java
index 695ea68ac1f8d4aad93fc1d443a9ad7282c45873..8f1d77d49b4ce682025fb7a1f978b505732e1a40 100644
--- a/src/main/java/eu/siacs/conversations/Conversations.java
+++ b/src/main/java/eu/siacs/conversations/Conversations.java
@@ -74,6 +74,7 @@ public class Conversations extends Application {
.putString(AppSettings.THEME, "custom")
.putBoolean("custom_theme_automatic", false)
.putBoolean("custom_theme_dark", true)
+ .putBoolean("custom_theme_color_match", true)
.putInt("custom_dark_theme_primary", context.getColor(R.color.white))
.putInt("custom_dark_theme_primary_dark", context.getColor(android.R.color.black))
.putInt("custom_dark_theme_accent", context.getColor(R.color.yeller))
diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceSettingsFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceSettingsFragment.java
index d15c3c2156efc3f50ca874196b611da2821b801d..d60715289d82fbdb01a55a46f5400ac31eecca56 100644
--- a/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceSettingsFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceSettingsFragment.java
@@ -49,6 +49,7 @@ public class InterfaceSettingsFragment extends XmppPreferenceFragment {
final var sharedPreferences = getPreferenceManager().getSharedPreferences();
findPreference("custom_theme_automatic").setVisible(custom);
findPreference("custom_theme_dark").setVisible(custom && !sharedPreferences.getBoolean("custom_theme_automatic", true));
+ findPreference("custom_theme_color_match").setVisible(custom);
findPreference("custom_theme_primary").setVisible(custom && !dark);
findPreference("custom_theme_primary_dark").setVisible(custom && !dark);
@@ -73,6 +74,7 @@ public class InterfaceSettingsFragment extends XmppPreferenceFragment {
if (
key.equals("custom_theme_automatic") ||
key.equals("custom_theme_dark") ||
+ key.equals("custom_theme_color_match") ||
key.equals("custom_theme_primary") ||
key.equals("custom_theme_primary_dark") ||
key.equals("custom_theme_accent") ||
diff --git a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java
index 81427c402a2f2f0cf2ba584efacdba6bb7e483b4..42b3fadb14b1f4e6f18afbb9a162f0588da8265e 100644
--- a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java
@@ -62,25 +62,29 @@ public class ThemeHelper {
if (!Conversations.isCustomColorsDesired(context)) return colors;
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ final var colorMatch = sharedPreferences.getBoolean("custom_theme_color_match", false);
if (sharedPreferences.contains("custom_theme_primary")) {
- final var roles = MaterialColors.getColorRoles(sharedPreferences.getInt("custom_theme_primary", 0), true);
- colors.put(R.color.md_theme_light_primary, roles.getAccent());
+ final var base = sharedPreferences.getInt("custom_theme_primary", 0);
+ final var roles = MaterialColors.getColorRoles(base, true);
+ colors.put(R.color.md_theme_light_primary, colorMatch ? base : roles.getAccent());
colors.put(R.color.md_theme_light_onPrimary, roles.getOnAccent());
- colors.put(R.color.md_theme_light_primaryContainer, roles.getAccentContainer());
+ colors.put(R.color.md_theme_light_primaryContainer, colorMatch ? base : roles.getAccentContainer());
colors.put(R.color.md_theme_light_onPrimaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_theme_primary_dark")) {
- final var roles = MaterialColors.getColorRoles(sharedPreferences.getInt("custom_theme_primary_dark", 0), true);
- colors.put(R.color.md_theme_light_secondary, roles.getAccent());
+ final var base = sharedPreferences.getInt("custom_theme_primary_dark", 0);
+ final var roles = MaterialColors.getColorRoles(base, true);
+ colors.put(R.color.md_theme_light_secondary, colorMatch ? base : roles.getAccent());
colors.put(R.color.md_theme_light_onSecondary, roles.getOnAccent());
- colors.put(R.color.md_theme_light_secondaryContainer, roles.getAccentContainer());
+ colors.put(R.color.md_theme_light_secondaryContainer, colorMatch ? base : roles.getAccentContainer());
colors.put(R.color.md_theme_light_onSecondaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_theme_accent")) {
- final var roles = MaterialColors.getColorRoles(sharedPreferences.getInt("custom_theme_accent", 0), true);
- colors.put(R.color.md_theme_light_tertiary, roles.getAccent());
+ final var base = sharedPreferences.getInt("custom_theme_accent", 0);
+ final var roles = MaterialColors.getColorRoles(base, true);
+ colors.put(R.color.md_theme_light_tertiary, colorMatch ? base : roles.getAccent());
colors.put(R.color.md_theme_light_onTertiary, roles.getOnAccent());
- colors.put(R.color.md_theme_light_tertiaryContainer, roles.getAccentContainer());
+ colors.put(R.color.md_theme_light_tertiaryContainer, colorMatch ? base : roles.getAccentContainer());
colors.put(R.color.md_theme_light_onTertiaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_theme_background_primary")) {
@@ -96,30 +100,27 @@ public class ThemeHelper {
}
if (sharedPreferences.contains("custom_dark_theme_primary")) {
final var base = sharedPreferences.getInt("custom_dark_theme_primary", 0);
- final var black = base == context.getColor(android.R.color.black);
final var roles = MaterialColors.getColorRoles(base, false);
- colors.put(R.color.md_theme_dark_primary, black ? base : roles.getAccent());
- colors.put(R.color.md_theme_dark_onPrimary, black ? context.getColor(R.color.white) : roles.getOnAccent());
- colors.put(R.color.md_theme_dark_primaryContainer, black ? base : roles.getAccentContainer());
- colors.put(R.color.md_theme_dark_onPrimaryContainer, black ? context.getColor(R.color.white) : roles.getOnAccentContainer());
+ colors.put(R.color.md_theme_dark_primary, colorMatch ? base : roles.getAccent());
+ colors.put(R.color.md_theme_dark_onPrimary, roles.getOnAccent());
+ colors.put(R.color.md_theme_dark_primaryContainer, colorMatch ? base : roles.getAccentContainer());
+ colors.put(R.color.md_theme_dark_onPrimaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_dark_theme_primary_dark")) {
final var base = sharedPreferences.getInt("custom_dark_theme_primary_dark", 0);
- final var black = base == context.getColor(android.R.color.black);
final var roles = MaterialColors.getColorRoles(base, false);
- colors.put(R.color.md_theme_dark_secondary, black ? base : roles.getAccent());
- colors.put(R.color.md_theme_dark_onSecondary, black ? context.getColor(R.color.white) : roles.getOnAccent());
- colors.put(R.color.md_theme_dark_secondaryContainer, black ? base : roles.getAccentContainer());
- colors.put(R.color.md_theme_dark_onSecondaryContainer, black ? context.getColor(R.color.white) : roles.getOnAccentContainer());
+ colors.put(R.color.md_theme_dark_secondary, colorMatch ? base : roles.getAccent());
+ colors.put(R.color.md_theme_dark_onSecondary, roles.getOnAccent());
+ colors.put(R.color.md_theme_dark_secondaryContainer, colorMatch ? base : roles.getAccentContainer());
+ colors.put(R.color.md_theme_dark_onSecondaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_dark_theme_accent")) {
final var base = sharedPreferences.getInt("custom_dark_theme_accent", 0);
- final var black = base == context.getColor(android.R.color.black);
final var roles = MaterialColors.getColorRoles(base, false);
- colors.put(R.color.md_theme_dark_tertiary, black ? base : roles.getAccent());
- colors.put(R.color.md_theme_dark_onTertiary, black ? context.getColor(R.color.white) : roles.getOnAccent());
- colors.put(R.color.md_theme_dark_tertiaryContainer, black ? base : roles.getAccentContainer());
- colors.put(R.color.md_theme_dark_onTertiaryContainer, black ? context.getColor(R.color.white) : roles.getOnAccentContainer());
+ colors.put(R.color.md_theme_dark_tertiary, colorMatch ? base : roles.getAccent());
+ colors.put(R.color.md_theme_dark_onTertiary, roles.getOnAccent());
+ colors.put(R.color.md_theme_dark_tertiaryContainer, colorMatch ? base : roles.getAccentContainer());
+ colors.put(R.color.md_theme_dark_onTertiaryContainer, roles.getOnAccentContainer());
}
if (sharedPreferences.contains("custom_dark_theme_background_primary")) {
int background_primary = sharedPreferences.getInt("custom_dark_theme_background_primary", 0);
diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml
index 45d133bd7cf9aab94d313c95b29336f4e14684df..a4d54ea8dc01239a544bb79658c347f4be0911e3 100644
--- a/src/main/res/xml/preferences_interface.xml
+++ b/src/main/res/xml/preferences_interface.xml
@@ -25,6 +25,12 @@
android:icon="@drawable/ic_dark_mode_24dp"
android:key="custom_theme_dark"
android:title="Custom Theme is Dark" />
+