Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 025e1681 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Custom Theme 10/n: check for existing theme

If the currently defined custom theme is equivalent to an
existing one, suggest using that one instead of creating a
new custom one.

Bug: 124796742
Change-Id: Ib8436d129f359a53f284f907a566dd16293df6ef
parent 32bb6ef3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -148,4 +148,22 @@
    <!-- Label for a dialog which asks the user the destination (home screen, lock screen, both)
        where to set the theme's bundled image as wallpaper. [CHAR LIMIT=50] -->
    <string name="set_theme_wallpaper_dialog_message">Set style wallpaper</string>

    <!-- Title for a dialog box asking the user to use an existing, equivalent theme (style) instead
        of their customly defined one. [CHAR_LIMIT=30] -->
    <string name="use_style_instead_title">Use <xliff:g name="style_name">%1$s</xliff:g> instead?</string>

    <!-- Body for a dialog box asking the user to use an existing, equivalent theme (style) instead
        of their customly defined one. [CHAR_LIMIT=NONE] -->
    <string name="use_style_instead_body">The components you chose match the <xliff:g name="style_name">%1$s</xliff:g> style. Do you want to use <xliff:g name="style_name">%1$s</xliff:g> instead?</string>

    <!-- Label for a button in the dialog box that asks the user to use an existing, theme (style)
        instead of their customly defined one. The button let's the user use the suggested theme
        [CHAR_LIMIT=15] -->
    <string name="use_style_button">Use <xliff:g name="style_name">%1$s</xliff:g></string>

    <!-- Label for a button in the dialog box that asks the user to use an existing, theme (style)
        instead of their customly defined one. The button dismisses the dialog and goes back to the
        previous screen. [CHAR_LIMIT=15]  -->
    <string name="no_thanks">No, thanks</string>
</resources>
+13 −0
Original line number Diff line number Diff line
@@ -544,4 +544,17 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
       OverlayInfo info = mOverlayInfos.get(packageName);
       return info != null ? info.category : null;
    }

    @Override
    public ThemeBundle findEquivalent(ThemeBundle other) {
        if (mThemes == null) {
            return null;
        }
        for (ThemeBundle theme : mThemes) {
            if (theme.isEquivalent(other)) {
                return theme;
            }
        }
        return null;
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -124,6 +124,21 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        return R.layout.theme_option;
    }

    /**
     * This is similar to #equals() but it only compares this theme's packages with the other, that
     * is, it will return true if applying this theme has the same effect of applying the given one.
     */
    public boolean isEquivalent(ThemeBundle other) {
        if (other == null) {
            return false;
        }
        if (mIsDefault) {
            return other.isDefault() || TextUtils.isEmpty(other.getSerializedPackages());
        }
        // Map#equals ensures keys and values are compared.
        return mPackagesByCategory.equals(other.mPackagesByCategory);
    }

    public PreviewInfo getPreviewInfo() {
        return mPreviewInfo;
    }
+2 −0
Original line number Diff line number Diff line
@@ -44,4 +44,6 @@ public interface ThemeBundleProvider {
    void removeCustomTheme(CustomTheme theme);

    @Nullable Builder parseCustomTheme(String serializedTheme);

    ThemeBundle findEquivalent(ThemeBundle other);
}
+9 −0
Original line number Diff line number Diff line
@@ -232,4 +232,13 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
    public void removeCustomTheme(CustomTheme theme) {
        mProvider.removeCustomTheme(theme);
    }

    /**
     * @return an existing ThemeBundle that matches the same packages as the given one, if one
     * exists, or {@code null} otherwise.
     */
    @Nullable
    public ThemeBundle findThemeByPackages(ThemeBundle other) {
        return mProvider.findEquivalent(other);
    }
}
Loading