Skip to content

Commit

Permalink
Add support to edit all the theme colors
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed May 5, 2021
1 parent b725067 commit 0f7c5b2
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ protected boolean setCollapsingToolbarLayout() {
public void onAddHeader(@Nullable View view) {
super.onAddHeader(view);

if (view != null) {
Dynamic.set(view.findViewById(R.id.ads_header_appbar_icon),
DynamicPackageUtils.getAppIcon(this));
Dynamic.set(view.findViewById(R.id.ads_header_appbar_title),
DynamicPackageUtils.getAppLabel(this));

if (mPermissionsCount > 0) {
updateSubtitle(mPermissionsCount);
}
if (view == null) {
return;
}

Dynamic.set(view.findViewById(R.id.ads_header_appbar_icon),
DynamicPackageUtils.getAppIcon(this));
Dynamic.set(view.findViewById(R.id.ads_header_appbar_title),
DynamicPackageUtils.getAppLabel(this));

if (mPermissionsCount > 0) {
updateSubtitle(mPermissionsCount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,47 @@ public class DynamicRemoteThemeFragment extends ThemeFragment<DynamicRemoteTheme
private DynamicPresetsView<DynamicRemoteTheme> mPresetsView;

/**
* Dynamic color preference to control the background color.
* Dynamic color preference to control the background colors.
*/
private DynamicColorPreference mColorBackgroundPreference;

/**
* Dynamic color preference to control the surface color.
* Dynamic color preference to control the surface colors.
*/
private DynamicColorPreference mColorSurfacePreference;

/**
* Dynamic color preference to control the primary color.
* Dynamic color preference to control the primary colors.
*/
private DynamicColorPreference mColorPrimaryPreference;

/**
* Dynamic color preference to control the accent color.
* Dynamic color preference to control the accent colors.
*/
private DynamicColorPreference mColorAccentPreference;

/**
* Dynamic color preference to control the dark primary color.
* Dynamic color preference to control the dark primary colors.
*/
private DynamicColorPreference mColorSystemPreference;
private DynamicColorPreference mColorPrimaryDarkPreference;

/**
* Dynamic color preference to control the error color.
* Dynamic color preference to control the dark accent colors.
*/
private DynamicColorPreference mColorAccentDarkPreference;

/**
* Dynamic color preference to control the error colors.
*/
private DynamicColorPreference mColorErrorPreference;

/**
* Dynamic color preference to control the primary text color.
* Dynamic color preference to control the primary text colors.
*/
private DynamicColorPreference mTextPrimaryPreference;

/**
* Dynamic color preference to control the secondary text color.
* Dynamic color preference to control the secondary text colors.
*/
private DynamicColorPreference mTextSecondaryPreference;

Expand Down Expand Up @@ -194,7 +199,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mColorSurfacePreference = view.findViewById(R.id.ads_pref_theme_color_surface);
mColorPrimaryPreference = view.findViewById(R.id.ads_pref_theme_color_primary);
mColorAccentPreference = view.findViewById(R.id.ads_pref_theme_color_accent);
mColorSystemPreference = view.findViewById(R.id.ads_pref_theme_color_system);
mColorPrimaryDarkPreference = view.findViewById(R.id.ads_pref_theme_color_primary_dark);
mColorAccentDarkPreference = view.findViewById(R.id.ads_pref_theme_color_accent_dark);
mColorErrorPreference = view.findViewById(R.id.ads_pref_theme_color_error);
mTextPrimaryPreference = view.findViewById(R.id.ads_pref_theme_text_primary);
mTextSecondaryPreference = view.findViewById(R.id.ads_pref_theme_text_secondary);
Expand Down Expand Up @@ -271,6 +277,17 @@ public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getSurfaceColor();
}
});
mColorSurfacePreference.setAltDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getTintSurfaceColor(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getTintSurfaceColor();
}
});

mColorPrimaryPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
Expand Down Expand Up @@ -318,7 +335,7 @@ public int getAutoColor(@Nullable String tag) {
}
});

mColorSystemPreference.setDynamicColorResolver(new DynamicColorResolver() {
mColorPrimaryDarkPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getPrimaryColorDark(false);
Expand All @@ -329,15 +346,38 @@ public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getPrimaryColorDark();
}
});
mColorSystemPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
mColorPrimaryDarkPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getSurfaceColor(false);
return mDynamicThemeDefault.getTintPrimaryColorDark(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getSurfaceColor();
return mThemePreview.getDynamicTheme().getTintPrimaryColorDark();
}
});

mColorAccentDarkPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getAccentColorDark(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getAccentColorDark();
}
});
mColorAccentDarkPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getTintAccentColorDark(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getTintAccentColorDark();
}
});

Expand Down Expand Up @@ -486,12 +526,15 @@ public void onLoadTheme(@NonNull DynamicRemoteTheme theme) {
mColorBackgroundPreference.setColor(theme.getBackgroundColor(false, false));
mColorBackgroundPreference.setAltColor(theme.getTintBackgroundColor(false, false));
mColorSurfacePreference.setColor(theme.getSurfaceColor(false));
mColorSurfacePreference.setAltColor(theme.getTintSurfaceColor(false));
mColorPrimaryPreference.setColor(theme.getPrimaryColor(false));
mColorPrimaryPreference.setAltColor(theme.getTintPrimaryColor(false));
mColorAccentPreference.setColor(theme.getAccentColor(false));
mColorAccentPreference.setAltColor(theme.getTintAccentColor(false));
mColorSystemPreference.setColor(theme.getPrimaryColorDark(false));
mColorSystemPreference.setAltColor(theme.getAccentColorDark(false));
mColorPrimaryDarkPreference.setColor(theme.getPrimaryColorDark(false));
mColorPrimaryDarkPreference.setAltColor(theme.getTintPrimaryColorDark(false));
mColorAccentDarkPreference.setColor(theme.getAccentColorDark(false));
mColorAccentDarkPreference.setAltColor(theme.getTintAccentColorDark(false));
mColorErrorPreference.setColor(theme.getErrorColor(false));
mColorErrorPreference.setAltColor(theme.getTintErrorColor(false));
mTextPrimaryPreference.setColor(theme.getTextPrimaryColor(false, false));
Expand Down Expand Up @@ -599,7 +642,8 @@ private void updatePreferences() {
mColorSurfacePreference.update();
mColorPrimaryPreference.update();
mColorAccentPreference.update();
mColorSystemPreference.update();
mColorPrimaryDarkPreference.update();
mColorAccentDarkPreference.update();
mColorErrorPreference.update();
mTextPrimaryPreference.update();
mTextSecondaryPreference.update();
Expand All @@ -618,15 +662,15 @@ private void updateThemePreview() {
.setBackgroundColor(mColorBackgroundPreference.getColor(false))
.setTintBackgroundColor(mColorBackgroundPreference.getAltColor(false))
.setSurfaceColor(mColorSurfacePreference.getColor(false))
.setTintSurfaceColor(mDynamicTheme.getTintSurfaceColor(false))
.setTintSurfaceColor(mColorSurfacePreference.getAltColor(false))
.setPrimaryColor(mColorPrimaryPreference.getColor(false))
.setTintPrimaryColor(mColorPrimaryPreference.getAltColor(false))
.setPrimaryColorDark(mColorSystemPreference.getColor(false))
.setTintPrimaryColorDark(mDynamicTheme.getTintPrimaryColorDark(false))
.setPrimaryColorDark(mColorPrimaryDarkPreference.getColor(false))
.setTintPrimaryColorDark(mColorPrimaryDarkPreference.getAltColor(false))
.setAccentColor(mColorAccentPreference.getColor(false))
.setTintAccentColor(mColorAccentPreference.getAltColor(false))
.setAccentColorDark(mColorSystemPreference.getAltColor(false))
.setTintAccentColorDark(mDynamicTheme.getTintAccentColorDark(false))
.setAccentColorDark(mColorAccentDarkPreference.getColor(false))
.setTintAccentColorDark(mColorAccentDarkPreference.getAltColor(false))
.setErrorColor(mColorErrorPreference.getColor(false))
.setTintErrorColor(mColorErrorPreference.getAltColor(false))
.setTextPrimaryColor(mTextPrimaryPreference.getColor(false))
Expand Down Expand Up @@ -662,9 +706,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case ADS_PREF_THEME_COLOR_PRIMARY:
case ADS_PREF_THEME_COLOR_TINT_PRIMARY:
case ADS_PREF_THEME_COLOR_PRIMARY_DARK:
case ADS_PREF_THEME_COLOR_TINT_PRIMARY_DARK:
case ADS_PREF_THEME_COLOR_ACCENT:
case ADS_PREF_THEME_COLOR_TINT_ACCENT:
case ADS_PREF_THEME_COLOR_ACCENT_DARK:
case ADS_PREF_THEME_COLOR_TINT_ACCENT_DARK:
case ADS_PREF_THEME_COLOR_ERROR:
case ADS_PREF_THEME_COLOR_TINT_ERROR:
case ADS_PREF_THEME_TEXT_PRIMARY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ public class DynamicThemeFragment extends ThemeFragment<DynamicAppTheme> {
private DynamicColorPreference mColorAccentPreference;

/**
* Dynamic color preference to control the system colors.
* Dynamic color preference to control the dark primary colors.
*/
private DynamicColorPreference mColorSystemPreference;
private DynamicColorPreference mColorPrimaryDarkPreference;

/**
* Dynamic color preference to control the dark accent colors.
*/
private DynamicColorPreference mColorAccentDarkPreference;

/**
* Dynamic color preference to control the error colors.
Expand Down Expand Up @@ -192,7 +197,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mColorSurfacePreference = view.findViewById(R.id.ads_pref_theme_color_surface);
mColorPrimaryPreference = view.findViewById(R.id.ads_pref_theme_color_primary);
mColorAccentPreference = view.findViewById(R.id.ads_pref_theme_color_accent);
mColorSystemPreference = view.findViewById(R.id.ads_pref_theme_color_system);
mColorPrimaryDarkPreference = view.findViewById(R.id.ads_pref_theme_color_primary_dark);
mColorAccentDarkPreference = view.findViewById(R.id.ads_pref_theme_color_accent_dark);
mColorErrorPreference = view.findViewById(R.id.ads_pref_theme_color_error);
mTextPrimaryPreference = view.findViewById(R.id.ads_pref_theme_text_primary);
mTextSecondaryPreference = view.findViewById(R.id.ads_pref_theme_text_secondary);
Expand Down Expand Up @@ -322,7 +328,7 @@ public int getAutoColor(@Nullable String tag) {
}
});

mColorSystemPreference.setDynamicColorResolver(new DynamicColorResolver() {
mColorPrimaryDarkPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getPrimaryColorDark(false);
Expand All @@ -333,7 +339,19 @@ public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getPrimaryColorDark();
}
});
mColorSystemPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
mColorPrimaryDarkPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getTintPrimaryColorDark(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getTintPrimaryColorDark();
}
});

mColorAccentDarkPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getAccentColorDark(false);
Expand All @@ -344,6 +362,17 @@ public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getAccentColorDark();
}
});
mColorAccentDarkPreference.setAltDynamicColorResolver(new DynamicColorResolver() {
@Override
public int getDefaultColor(@Nullable String tag) {
return mDynamicThemeDefault.getTintAccentColorDark(false);
}

@Override
public int getAutoColor(@Nullable String tag) {
return mThemePreview.getDynamicTheme().getTintAccentColorDark();
}
});

mColorErrorPreference.setDynamicColorResolver(new DynamicColorResolver() {
@Override
Expand Down Expand Up @@ -493,8 +522,10 @@ public void onLoadTheme(@NonNull DynamicAppTheme theme) {
mColorPrimaryPreference.setAltColor(theme.getTintPrimaryColor(false));
mColorAccentPreference.setColor(theme.getAccentColor(false));
mColorAccentPreference.setAltColor(theme.getTintAccentColor(false));
mColorSystemPreference.setColor(theme.getPrimaryColorDark(false));
mColorSystemPreference.setAltColor(theme.getAccentColorDark(false));
mColorPrimaryDarkPreference.setColor(theme.getPrimaryColorDark(false));
mColorPrimaryDarkPreference.setAltColor(theme.getTintPrimaryColorDark(false));
mColorAccentDarkPreference.setColor(theme.getAccentColorDark(false));
mColorAccentDarkPreference.setAltColor(theme.getTintAccentColorDark(false));
mColorErrorPreference.setColor(theme.getErrorColor(false));
mColorErrorPreference.setAltColor(theme.getTintErrorColor(false));
mTextPrimaryPreference.setColor(theme.getTextPrimaryColor(false, false));
Expand Down Expand Up @@ -592,7 +623,8 @@ private void updatePreferences() {
mColorSurfacePreference.update();
mColorPrimaryPreference.update();
mColorAccentPreference.update();
mColorSystemPreference.update();
mColorPrimaryDarkPreference.update();
mColorAccentDarkPreference.update();
mColorErrorPreference.update();
mTextPrimaryPreference.update();
mTextSecondaryPreference.update();
Expand All @@ -614,12 +646,12 @@ private void updateThemePreview() {
.setTintSurfaceColor(mColorSurfacePreference.getAltColor(false))
.setPrimaryColor(mColorPrimaryPreference.getColor(false))
.setTintPrimaryColor(mColorPrimaryPreference.getAltColor(false))
.setPrimaryColorDark(mColorSystemPreference.getColor(false))
.setTintPrimaryColorDark(mDynamicTheme.getTintPrimaryColorDark(false))
.setPrimaryColorDark(mColorPrimaryDarkPreference.getColor(false))
.setTintPrimaryColorDark(mColorPrimaryDarkPreference.getAltColor(false))
.setAccentColor(mColorAccentPreference.getColor(false))
.setTintAccentColor(mColorAccentPreference.getAltColor(false))
.setAccentColorDark(mColorSystemPreference.getAltColor(false))
.setTintAccentColorDark(mDynamicTheme.getTintAccentColorDark(false))
.setAccentColorDark(mColorAccentDarkPreference.getColor(false))
.setTintAccentColorDark(mColorAccentDarkPreference.getAltColor(false))
.setErrorColor(mColorErrorPreference.getColor(false))
.setTintErrorColor(mColorErrorPreference.getAltColor(false))
.setTextPrimaryColor(mTextPrimaryPreference.getColor(false))
Expand Down Expand Up @@ -655,9 +687,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case ADS_PREF_THEME_COLOR_PRIMARY:
case ADS_PREF_THEME_COLOR_TINT_PRIMARY:
case ADS_PREF_THEME_COLOR_PRIMARY_DARK:
case ADS_PREF_THEME_COLOR_TINT_PRIMARY_DARK:
case ADS_PREF_THEME_COLOR_ACCENT:
case ADS_PREF_THEME_COLOR_TINT_ACCENT:
case ADS_PREF_THEME_COLOR_ACCENT_DARK:
case ADS_PREF_THEME_COLOR_TINT_ACCENT_DARK:
case ADS_PREF_THEME_COLOR_ERROR:
case ADS_PREF_THEME_COLOR_TINT_ERROR:
case ADS_PREF_THEME_TEXT_PRIMARY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public abstract class ThemeFragment<T extends DynamicAppTheme> extends DynamicFr
public static final String ADS_PREF_THEME_COLOR_PRIMARY_DARK =
"ads_pref_settings_theme_color_primary_dark";

/**
* Key for the tint dark primary color preference.
*/
public static final String ADS_PREF_THEME_COLOR_TINT_PRIMARY_DARK =
"ads_pref_settings_theme_color_tint_primary_dark";

/**
* Key for the accent color preference.
*/
Expand All @@ -152,6 +158,12 @@ public abstract class ThemeFragment<T extends DynamicAppTheme> extends DynamicFr
public static final String ADS_PREF_THEME_COLOR_ACCENT_DARK =
"ads_pref_settings_theme_color_accent_dark";

/**
* Key for the tint dark accent color preference.
*/
public static final String ADS_PREF_THEME_COLOR_TINT_ACCENT_DARK =
"ads_pref_settings_theme_color_tint_accent_dark";

/**
* Key for the error color preference.
*/
Expand Down

0 comments on commit 0f7c5b2

Please sign in to comment.