Remove branding toggle

This commit is contained in:
Stefan Niedermann 2021-04-01 14:52:37 +02:00
parent 5944fbacf4
commit c3debd3da5
12 changed files with 47 additions and 73 deletions

View file

@ -37,11 +37,9 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand
getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
colorAccent = typedValue.data;
if (BrandingUtil.isBrandingEnabled(this)) {
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(this);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(this);
applyBrand(mainColor, textColor);
}
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(this);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(this);
applyBrand(mainColor, textColor);
}
@Override

View file

@ -14,11 +14,9 @@ public abstract class BrandedDialogFragment extends DialogFragment implements Br
@Nullable Context context = getContext();
if (context != null) {
if (BrandingUtil.isBrandingEnabled(context)) {
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
applyBrand(mainColor, textColor);
}
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
applyBrand(mainColor, textColor);
}
}
}

View file

@ -32,7 +32,7 @@ public abstract class BrandedFragment extends Fragment implements Branded {
colorPrimary = typedValue.data;
@Nullable Context context = getContext();
if (context != null && BrandingUtil.isBrandingEnabled(context)) {
if (context != null) {
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
applyBrand(mainColor, textColor);

View file

@ -34,13 +34,11 @@ public class BrandedPreferenceCategory extends PreferenceCategory {
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
if (BrandingUtil.isBrandingEnabled(getContext())) {
final View v = holder.itemView.findViewById(android.R.id.title);
@Nullable final Context context = getContext();
if (context != null && v instanceof TextView) {
@ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
((TextView) v).setTextColor(mainColor);
}
final View v = holder.itemView.findViewById(android.R.id.title);
@Nullable final Context context = getContext();
if (context != null && v instanceof TextView) {
@ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
((TextView) v).setTextColor(mainColor);
}
}
}

View file

@ -15,10 +15,8 @@ public class BrandedSnackbar {
@NonNull
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @Snackbar.Duration int duration) {
final Snackbar snackbar = Snackbar.make(view, text, duration);
if (BrandingUtil.isBrandingEnabled(view.getContext())) {
int color = BrandingUtil.readBrandMainColor(view.getContext());
snackbar.setActionTextColor(ColorUtil.INSTANCE.isColorDark(color) ? Color.WHITE : color);
}
final int color = BrandingUtil.readBrandMainColor(view.getContext());
snackbar.setActionTextColor(ColorUtil.INSTANCE.isColorDark(color) ? Color.WHITE : color);
return snackbar;
}

View file

@ -61,13 +61,8 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
@Override
public void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) {
if (BrandingUtil.isBrandingEnabled(getContext())) {
this.mainColor = mainColor;
this.textColor = textColor;
} else {
this.mainColor = getContext().getResources().getColor(R.color.defaultBrand);
this.textColor = Color.WHITE;
}
this.mainColor = mainColor;
this.textColor = textColor;
// onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later.
applyBrand();
}

View file

@ -33,43 +33,30 @@ public class BrandingUtil {
}
public static boolean isBrandingEnabled(@NonNull Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.pref_key_branding), true);
}
@ColorInt
public static int readBrandMainColor(@NonNull Context context) {
if (BrandingUtil.isBrandingEnabled(context)) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_main");
return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
} else {
return ContextCompat.getColor(context, R.color.defaultBrand);
}
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_main");
return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
}
@ColorInt
public static int readBrandTextColor(@NonNull Context context) {
if (isBrandingEnabled(context)) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_text");
return sharedPreferences.getInt(pref_key_branding_text, Color.WHITE);
} else {
return Color.WHITE;
}
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_text");
return sharedPreferences.getInt(pref_key_branding_text, Color.WHITE);
}
public static void saveBrandColors(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor) {
final int previousMainColor = readBrandMainColor(context);
final int previousTextColor = readBrandTextColor(context);
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
Log.v(TAG, "--- Write: shared_preference_theme_main" + " | " + mainColor);
Log.v(TAG, "--- Write: shared_preference_theme_text" + " | " + textColor);
editor.putInt(pref_key_branding_main, mainColor);
editor.putInt(pref_key_branding_text, textColor);
editor.apply();
if (isBrandingEnabled(context) && context instanceof BrandedActivity) {
if (context instanceof BrandedActivity) {
if (mainColor != previousMainColor || textColor != previousTextColor) {
final BrandedActivity activity = (BrandedActivity) context;
activity.runOnUiThread(() -> ActivityCompat.recreate(activity));

View file

@ -16,6 +16,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_15_16;
import it.niedermann.owncloud.notes.persistence.migration.Migration_16_17;
import it.niedermann.owncloud.notes.persistence.migration.Migration_17_18;
import it.niedermann.owncloud.notes.persistence.migration.Migration_18_19;
import it.niedermann.owncloud.notes.persistence.migration.Migration_19_20;
import it.niedermann.owncloud.notes.persistence.migration.Migration_4_5;
import it.niedermann.owncloud.notes.persistence.migration.Migration_5_6;
import it.niedermann.owncloud.notes.persistence.migration.Migration_6_7;
@ -26,7 +27,7 @@ import it.niedermann.owncloud.notes.shared.util.DatabaseIndexUtil;
abstract class AbstractNotesDatabase extends SQLiteOpenHelper {
private static final int database_version = 19;
private static final int database_version = 20;
@NonNull
protected final Context context;
@ -194,6 +195,8 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper {
new Migration_17_18(db);
case 18:
new Migration_18_19(context);
case 19:
new Migration_19_20(context);
}
}

View file

@ -0,0 +1,19 @@
package it.niedermann.owncloud.notes.persistence.migration;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
public class Migration_19_20 {
/**
* Removes <code>branding</code> from {@link SharedPreferences} because we do no longer allow to disable it.
*
* @param context {@link Context}
*/
public Migration_19_20(@NonNull Context context) {
PreferenceManager.getDefaultSharedPreferences(context).edit().remove("branding").apply();
}
}

View file

@ -44,20 +44,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
fontPref = findPreference(getString(R.string.pref_key_font));
brandingPref = findPreference(getString(R.string.pref_key_branding));
if (brandingPref != null) {
brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
updateNoteListWidgets(requireContext());
final Boolean branding = (Boolean) newValue;
Log.v(TAG, "branding: " + branding);
requireActivity().setResult(Activity.RESULT_OK);
ActivityCompat.recreate(requireActivity());
return true;
});
} else {
Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
}
gridViewPref = findPreference(getString(R.string.pref_key_gridview));
if (gridViewPref != null) {
gridViewPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {

View file

@ -99,7 +99,6 @@
<string name="pref_key_note_mode" translatable="false">noteMode</string>
<string name="pref_key_theme" translatable="false">darkTheme</string>
<string name="pref_key_font" translatable="false">font</string>
<string name="pref_key_branding" translatable="false">branding</string>
<string name="pref_key_gridview" translatable="false">gridview</string>
<string name="pref_key_font_size" translatable="false">fontSize</string>
<string name="pref_key_wifi_only" translatable="false">wifiOnly</string>

View file

@ -38,13 +38,6 @@
android:summary="%s"
android:title="@string/settings_theme_title" />
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_color_lens_grey600_24dp"
android:key="@string/pref_key_branding"
android:layout="@layout/item_pref"
android:title="@string/settings_branding" />
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:icon="@drawable/ic_baseline_dashboard_24"
android:key="@string/pref_key_gridview"