~singpolyma/cheogram-android

c9b48eccbd1767410efa4ce06d89619649182004 — Stephen Paul Weber 2 months ago 37993c0 + eca7f82
Merge branch 'master' of https://git.sr.ht/~savage_peanut/cheogram-android into custom-theme-background

* 'master' of https://git.sr.ht/~savage_peanut/cheogram-android:
  follow system dark mode with custom theme
  Custom background color
M src/cheogram/res/values/colors.xml => src/cheogram/res/values/colors.xml +8 -0
@@ 9,6 9,14 @@
	<color name="yeller">#FFC700</color>

	<color name="custom_theme_primary">@color/perpy</color>
	<color name="custom_theme_background_primary">@color/grey50</color>
	<color name="custom_theme_background_secondary">@color/grey200</color>
	<color name="custom_theme_background_tertiary">@color/grey300</color>

	<color name="custom_theme_background_primary_dark">@color/grey800</color>
	<color name="custom_theme_background_secondary_dark">@color/grey700</color>
	<color name="custom_theme_background_tertiary_dark">@color/grey900</color>
	<color name="custom_theme_primary_dark">@color/black_perpy</color>

	<color name="custom_theme_accent">@color/black_perpy</color>
</resources>

M src/cheogram/res/values/themes.xml => src/cheogram/res/values/themes.xml +6 -0
@@ 361,6 361,9 @@

    <style name="ConversationsTheme.Custom" parent="ConversationsTheme">
        <item name="colorPrimary">@color/custom_theme_primary</item>
        <item name="color_background_primary">@color/custom_theme_background_primary</item>
        <item name="color_background_secondary">@color/custom_theme_background_secondary</item>
        <item name="color_background_tertiary">@color/custom_theme_background_tertiary</item>
        <item name="colorPrimaryDark">@color/custom_theme_primary_dark</item>
        <item name="colorAccent">@color/custom_theme_accent</item>
        <item name="message_bubble_received_bg">?colorPrimary</item>


@@ 369,6 372,9 @@
    <style name="ConversationsTheme.CustomDark" parent="ConversationsTheme.Dark">
        <item name="colorPrimary">@color/custom_theme_primary</item>
        <item name="colorPrimaryDark">@color/custom_theme_primary_dark</item>
        <item name="color_background_primary">@color/custom_theme_background_primary_dark</item>
        <item name="color_background_secondary">@color/custom_theme_background_secondary_dark</item>
        <item name="color_background_tertiary">@color/custom_theme_background_tertiary_dark</item>
        <item name="colorAccent">@color/custom_theme_accent</item>
        <item name="message_bubble_received_bg">?colorPrimary</item>
    </style>

M src/main/java/eu/siacs/conversations/ui/SettingsActivity.java => src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +9 -1
@@ 581,7 581,15 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
            xmppConnectionService.reinitializeMuclumbusService();
        } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
            xmppConnectionService.expireOldMessages(true);
        } else if (name.equals(THEME) || name.equals("custom_theme_primary") || name.equals("custom_theme_primary_dark") || name.equals("custom_theme_accent") || name.equals("custom_theme_dark")) {
        } else if ( name.equals(THEME) ||
                    name.equals("custom_theme_automatic") ||
                    name.equals("custom_theme_primary") ||
                    name.equals("custom_theme_primary_dark") ||
                    name.equals("custom_theme_accent") ||
                    name.equals("custom_theme_dark") ||
                    name.equals("custom_theme_background_primary") ||
                    name.equals("custom_theme_background_primary_dark"))
        {
            final int theme = findTheme();
            xmppConnectionService.setTheme(theme);
            ThemeHelper.applyCustomColors(xmppConnectionService);

M src/main/java/eu/siacs/conversations/utils/ThemeHelper.java => src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +23 -1
@@ 64,6 64,26 @@ public class ThemeHelper {
		if (sharedPreferences.contains("custom_theme_primary")) colors.put(R.color.custom_theme_primary, sharedPreferences.getInt("custom_theme_primary", 0));
		if (sharedPreferences.contains("custom_theme_primary_dark")) colors.put(R.color.custom_theme_primary_dark, sharedPreferences.getInt("custom_theme_primary_dark", 0));
		if (sharedPreferences.contains("custom_theme_accent")) colors.put(R.color.custom_theme_accent, sharedPreferences.getInt("custom_theme_accent", 0));
		if (sharedPreferences.contains("custom_theme_background_primary")) {
			int background_primary = sharedPreferences.getInt("custom_theme_background_primary", 0);
			int alpha = (background_primary >> 24) & 0xFF;
			int red = (background_primary >> 16) & 0xFF;
			int green = (background_primary >> 8) & 0xFF;
			int blue = background_primary & 0xFF;
			colors.put(R.color.custom_theme_background_primary, background_primary);
			colors.put(R.color.custom_theme_background_secondary, (int)((alpha << 24) | ((int)(red*.9) << 16) | ((int)(green*.9) << 8) | (int)(blue*.9)));
			colors.put(R.color.custom_theme_background_tertiary, (int)((alpha << 24) | ((int)(red*.85) << 16) | ((int)(green*.85) << 8) | (int)(blue*.85)));
		}
		if (sharedPreferences.contains("custom_theme_background_primary_dark")) {
			int background_primary = sharedPreferences.getInt("custom_theme_background_primary_dark", 0);
			int alpha = (background_primary >> 24) & 0xFF;
			int red = (background_primary >> 16) & 0xFF;
			int green = (background_primary >> 8) & 0xFF;
			int blue = background_primary & 0xFF;
			colors.put(R.color.custom_theme_background_primary_dark, background_primary);
			colors.put(R.color.custom_theme_background_secondary_dark, (int)((alpha << 24) | ((int)(40 + red*.84) << 16) | ((int)(40 + green*.84) << 8) | (int)(40 + blue*.84)));
			colors.put(R.color.custom_theme_background_tertiary_dark, (int)((alpha << 24) | ((int)(red*.5) << 16) | ((int)(green*.5) << 8) | (int)(blue*.5)));
		}
		if (colors.isEmpty()) return colors;

		ResourcesLoader loader = ColorResourcesLoaderCreator.create(context, colors);


@@ 117,7 137,9 @@ public class ThemeHelper {

	private static boolean isDark(final SharedPreferences sharedPreferences, final Resources resources) {
		final String setting = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme));
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) {
		if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) ||
			("custom".equals(setting) && sharedPreferences.getBoolean("custom_theme_automatic", false))
		) {
			return (resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
		} else {
			if ("custom".equals(setting)) return sharedPreferences.getBoolean("custom_theme_dark", false);

M src/main/res/xml/preferences.xml => src/main/res/xml/preferences.xml +16 -0
@@ 209,9 209,25 @@

                <CheckBoxPreference
                    android:defaultValue="false"
                    android:disableDependentsState="true"
                    android:key="custom_theme_automatic"
                    android:title="Follow System Dark Mode?" />
                <CheckBoxPreference
                    android:defaultValue="false"
                    android:dependency="custom_theme_automatic"
                    android:key="custom_theme_dark"
                    android:title="Custom Theme is Dark?" />
                <com.rarepebble.colorpicker.ColorPreference
                    android:key="custom_theme_background_primary"
                    android:title="Custom Background Color"
                    android:defaultValue="@color/grey50"
                    app:colorpicker_showAlpha="false" />
                <com.rarepebble.colorpicker.ColorPreference
                    android:key="custom_theme_background_primary_dark"
                    android:title="Custom Dark Background Color"
                    android:defaultValue="@color/grey800"
                    app:colorpicker_showAlpha="false" />
                <com.rarepebble.colorpicker.ColorPreference
                    android:key="custom_theme_primary"
                    android:title="Custom Primary Color"
                    android:defaultValue="@color/perpy"