feat(theming): Get rid of textColor property

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2023-02-12 12:56:10 +01:00
parent c9f50bf4ec
commit 05a4fad5d9
38 changed files with 159 additions and 216 deletions

View file

@ -223,8 +223,8 @@ public class FormattingHelpActivity extends BrandedActivity {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
} }
} }

View file

@ -50,8 +50,8 @@ public class AboutActivity extends LockedActivity {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.material.themeTabLayout(binding.tabs); util.material.themeTabLayout(binding.tabs);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
} }

View file

@ -34,8 +34,8 @@ public class AboutFragmentLicenseTab extends BrandedFragment {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
util.material.colorMaterialButtonPrimaryFilled(binding.aboutAppLicenseButton); util.material.colorMaterialButtonPrimaryFilled(binding.aboutAppLicenseButton);
} }
} }

View file

@ -109,7 +109,7 @@ public class AccountPickerDialogFragment extends BrandedDialogFragment {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
// Nothing to do... // Nothing to do...
} }
} }

View file

@ -116,8 +116,8 @@ public class AccountSwitcherDialog extends BrandedDialogFragment {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
util.notes.colorLayerDrawable((LayerDrawable) binding.check.getDrawable(), R.id.area, mainColor); util.notes.colorLayerDrawable((LayerDrawable) binding.check.getDrawable(), R.id.area, color);
} }
} }

View file

@ -5,5 +5,5 @@ import androidx.annotation.UiThread;
public interface Branded { public interface Branded {
@UiThread @UiThread
void applyBrand(@ColorInt int mainColor, @ColorInt int textColor); void applyBrand(@ColorInt int color);
} }

View file

@ -1,6 +1,6 @@
package it.niedermann.owncloud.notes.branding; package it.niedermann.owncloud.notes.branding;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.readBrandColors; import static it.niedermann.owncloud.notes.branding.BrandingUtil.readBrandMainColorLiveData;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
@ -23,7 +23,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand
getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true); getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
colorAccent = typedValue.data; colorAccent = typedValue.data;
readBrandColors(this).observe(this, (pair) -> applyBrand(pair.first, pair.second)); readBrandMainColorLiveData(this).observe(this, this::applyBrand);
} }
@Override @Override

View file

@ -13,8 +13,7 @@ public abstract class BrandedDialogFragment extends DialogFragment implements Br
super.onStart(); super.onStart();
@Nullable final var context = requireContext(); @Nullable final var context = requireContext();
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context); @ColorInt final int color = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context); applyBrand(color);
applyBrand(mainColor, textColor);
} }
} }

View file

@ -28,9 +28,8 @@ public abstract class BrandedFragment extends Fragment implements Branded {
context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
colorPrimary = typedValue.data; colorPrimary = typedValue.data;
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context); @ColorInt final int color = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context); applyBrand(color);
applyBrand(mainColor, textColor);
} }
@Override @Override

View file

@ -17,9 +17,6 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
@ColorInt @ColorInt
private Integer mainColor = null; private Integer mainColor = null;
@ColorInt
private Integer textColor = null;
@SuppressLint("UseSwitchCompatOrMaterialCode") @SuppressLint("UseSwitchCompatOrMaterialCode")
@Nullable @Nullable
private Switch switchView; private Switch switchView;
@ -46,16 +43,15 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
if (holder.itemView instanceof ViewGroup) { if (holder.itemView instanceof ViewGroup) {
switchView = findSwitchWidget(holder.itemView); switchView = findSwitchWidget(holder.itemView);
if (mainColor != null && textColor != null) { if (mainColor != null) {
applyBrand(); applyBrand();
} }
} }
} }
@Override @Override
public void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) { public void applyBrand(@ColorInt int color) {
this.mainColor = mainColor; this.mainColor = color;
this.textColor = textColor;
// onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later. // onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later.
applyBrand(); applyBrand();
} }

View file

@ -1,56 +1,32 @@
package it.niedermann.owncloud.notes.branding; package it.niedermann.owncloud.notes.branding;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficientBigAreas;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.LayerDrawable;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.util.Pair;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.google.android.material.textfield.TextInputLayout;
import com.nextcloud.android.common.ui.theme.MaterialSchemes; import com.nextcloud.android.common.ui.theme.MaterialSchemes;
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase; import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils; import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils;
import com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils; import com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils;
import com.nextcloud.android.common.ui.theme.utils.DialogViewThemeUtils; import com.nextcloud.android.common.ui.theme.utils.DialogViewThemeUtils;
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils; import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;
import com.nextcloud.android.common.ui.util.PlatformThemeUtil;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData; import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData;
import it.niedermann.android.util.ColorUtil;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.shared.util.NotesColorUtil;
import scheme.Scheme;
public class BrandingUtil extends ViewThemeUtilsBase { public class BrandingUtil extends ViewThemeUtilsBase {
private static final String TAG = BrandingUtil.class.getSimpleName(); private static final String TAG = BrandingUtil.class.getSimpleName();
private static final ConcurrentMap<Integer, BrandingUtil> CACHE = new ConcurrentHashMap<>(); private static final ConcurrentMap<Integer, BrandingUtil> CACHE = new ConcurrentHashMap<>();
private static final String pref_key_branding_main = "branding_main"; private static final String pref_key_branding_main = "branding_main";
private static final String pref_key_branding_text = "branding_text";
public final AndroidViewThemeUtils platform; public final AndroidViewThemeUtils platform;
public final MaterialViewThemeUtils material; public final MaterialViewThemeUtils material;
@ -78,44 +54,12 @@ public class BrandingUtil extends ViewThemeUtilsBase {
)); ));
} }
public static LiveData<Pair<Integer, Integer>> readBrandColors(@NonNull Context context) {
return new BrandingLiveData(context);
}
private static class BrandingLiveData extends MediatorLiveData<Pair<Integer, Integer>> {
@ColorInt
Integer lastMainColor = null;
@ColorInt
Integer lastTextColor = null;
public BrandingLiveData(@NonNull Context context) {
addSource(readBrandMainColorLiveData(context), (nextMainColor) -> {
lastMainColor = nextMainColor;
if (lastTextColor != null) {
postValue(new Pair<>(lastMainColor, lastTextColor));
}
});
addSource(readBrandTextColorLiveData(context), (nextTextColor) -> {
lastTextColor = nextTextColor;
if (lastMainColor != null) {
postValue(new Pair<>(lastMainColor, lastTextColor));
}
});
}
}
public static LiveData<Integer> readBrandMainColorLiveData(@NonNull Context context) { public static LiveData<Integer> readBrandMainColorLiveData(@NonNull Context context) {
final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_main"); Log.v(TAG, "--- Read: shared_preference_theme_main");
return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand)); return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
} }
public static LiveData<Integer> readBrandTextColorLiveData(@NonNull Context context) {
final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_text");
return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_text, Color.WHITE);
}
@ColorInt @ColorInt
public static int readBrandMainColor(@NonNull Context context) { public static int readBrandMainColor(@NonNull Context context) {
final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
@ -123,24 +67,14 @@ public class BrandingUtil extends ViewThemeUtilsBase {
return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand)); return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
} }
@ColorInt public static void saveBrandColor(@NonNull Context context, @ColorInt int color) {
public static int readBrandTextColor(@NonNull Context context) {
final var 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 previousMainColor = readBrandMainColor(context);
final int previousTextColor = readBrandTextColor(context);
final var editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); final var editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
Log.v(TAG, "--- Write: shared_preference_theme_main" + " | " + mainColor); Log.v(TAG, "--- Write: shared_preference_theme_main" + " | " + color);
Log.v(TAG, "--- Write: shared_preference_theme_text" + " | " + textColor); editor.putInt(pref_key_branding_main, color);
editor.putInt(pref_key_branding_main, mainColor);
editor.putInt(pref_key_branding_text, textColor);
editor.apply(); editor.apply();
if (context instanceof BrandedActivity) { if (context instanceof BrandedActivity) {
if (mainColor != previousMainColor || textColor != previousTextColor) { if (color != previousMainColor) {
final var activity = (BrandedActivity) context; final var activity = (BrandedActivity) context;
activity.runOnUiThread(() -> ActivityCompat.recreate(activity)); activity.runOnUiThread(() -> ActivityCompat.recreate(activity));
} }

View file

@ -314,8 +314,8 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
} }
} }

View file

@ -242,7 +242,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
} }
@Override @Override
protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) { protected void colorWithText(@NonNull String newText, @Nullable Integer current, int color) {
if (binding != null && isAttachedToWindow(binding.editContent)) { if (binding != null && isAttachedToWindow(binding.editContent)) {
binding.editContent.clearFocus(); binding.editContent.clearFocus();
binding.editContent.setSearchText(newText, current); binding.editContent.setSearchText(newText, current);
@ -250,12 +250,12 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
super.applyBrand(mainColor, textColor); super.applyBrand(color);
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
binding.editContent.setSearchColor(mainColor); binding.editContent.setSearchColor(color);
binding.editContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), mainColor, colorPrimary, colorAccent)); binding.editContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), color, colorPrimary, colorAccent));
} }
public static BaseNoteFragment newInstance(long accountId, long noteId) { public static BaseNoteFragment newInstance(long accountId, long noteId) {

View file

@ -17,6 +17,7 @@ import android.view.ViewGroup;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -138,7 +139,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
} }
@Override @Override
protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) { protected void colorWithText(@NonNull String newText, @Nullable Integer current, @ColorInt int color) {
if (binding != null && isAttachedToWindow(binding.singleNoteContent)) { if (binding != null && isAttachedToWindow(binding.singleNoteContent)) {
binding.singleNoteContent.clearFocus(); binding.singleNoteContent.clearFocus();
binding.singleNoteContent.setSearchText(newText, current); binding.singleNoteContent.setSearchText(newText, current);
@ -177,12 +178,12 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
super.applyBrand(mainColor, textColor); super.applyBrand(color);
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
binding.singleNoteContent.setSearchColor(mainColor); binding.singleNoteContent.setSearchColor(color);
binding.singleNoteContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), mainColor, colorPrimary, colorAccent)); binding.singleNoteContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), color, colorPrimary, colorAccent));
} }
public static BaseNoteFragment newInstance(long accountId, long noteId) { public static BaseNoteFragment newInstance(long accountId, long noteId) {

View file

@ -7,11 +7,8 @@ import android.text.Layout;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
@ -21,11 +18,9 @@ import androidx.appcompat.widget.SearchView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.branding.BrandingUtil;
public abstract class SearchableBaseNoteFragment extends BaseNoteFragment { public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@ -41,14 +36,11 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts. private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
@ColorInt @ColorInt
private int mainColor; private int color;
@ColorInt
private int textColor;
@Override @Override
public void onStart() { public void onStart() {
this.mainColor = getResources().getColor(R.color.defaultBrand); this.color = getResources().getColor(R.color.defaultBrand);
this.textColor = Color.WHITE;
super.onStart(); super.onStart();
} }
@ -89,12 +81,12 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
if (currentVisibility != oldVisibility) { if (currentVisibility != oldVisibility) {
if (currentVisibility != View.VISIBLE) { if (currentVisibility != View.VISIBLE) {
colorWithText("", null, mainColor, textColor); colorWithText("", null, color);
searchQuery = ""; searchQuery = "";
hideSearchFabs(); hideSearchFabs();
} else { } else {
jumpToOccurrence(); jumpToOccurrence();
colorWithText(searchQuery, null, mainColor, textColor); colorWithText(searchQuery, null, color);
occurrenceCount = countOccurrences(getContent(), searchQuery); occurrenceCount = countOccurrences(getContent(), searchQuery);
showSearchFabs(); showSearchFabs();
} }
@ -112,7 +104,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
next.setOnClickListener(v -> { next.setOnClickListener(v -> {
currentOccurrence++; currentOccurrence++;
jumpToOccurrence(); jumpToOccurrence();
colorWithText(searchView.getQuery().toString(), currentOccurrence, mainColor, textColor); colorWithText(searchView.getQuery().toString(), currentOccurrence, color);
}); });
} }
@ -121,7 +113,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
occurrenceCount = countOccurrences(getContent(), searchView.getQuery().toString()); occurrenceCount = countOccurrences(getContent(), searchView.getQuery().toString());
currentOccurrence--; currentOccurrence--;
jumpToOccurrence(); jumpToOccurrence();
colorWithText(searchView.getQuery().toString(), currentOccurrence, mainColor, textColor); colorWithText(searchView.getQuery().toString(), currentOccurrence, color);
}); });
} }
@ -133,7 +125,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
public boolean onQueryTextSubmit(@NonNull String query) { public boolean onQueryTextSubmit(@NonNull String query) {
currentOccurrence++; currentOccurrence++;
jumpToOccurrence(); jumpToOccurrence();
colorWithText(query, currentOccurrence, mainColor, textColor); colorWithText(query, currentOccurrence, color);
return true; return true;
} }
@ -153,7 +145,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
} }
currentOccurrence = 1; currentOccurrence = 1;
jumpToOccurrence(); jumpToOccurrence();
colorWithText(searchQuery, currentOccurrence, mainColor, textColor); colorWithText(searchQuery, currentOccurrence, color);
} }
private void queryWithHandler(@NonNull String newText) { private void queryWithHandler(@NonNull String newText) {
@ -199,7 +191,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
} }
} }
protected abstract void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor); protected abstract void colorWithText(@NonNull String newText, @Nullable Integer current, @ColorInt int color);
protected abstract Layout getLayout(); protected abstract Layout getLayout();
@ -293,11 +285,10 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@CallSuper @CallSuper
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
this.mainColor = mainColor; this.color = color;
this.textColor = textColor;
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
util.material.themeFAB(getSearchNextButton()); util.material.themeFAB(getSearchNextButton());
util.material.themeFAB(getSearchPrevButton()); util.material.themeFAB(getSearchPrevButton());
} }

View file

@ -48,8 +48,8 @@ public class CategoryDialogFragment extends BrandedDialogFragment {
private LiveData<List<NavigationItem.CategoryNavigationItem>> categoryLiveData; private LiveData<List<NavigationItem.CategoryNavigationItem>> categoryLiveData;
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
util.material.colorTextInputLayout(binding.inputWrapper); util.material.colorTextInputLayout(binding.inputWrapper);
} }

View file

@ -86,8 +86,8 @@ public class EditTitleDialogFragment extends BrandedDialogFragment {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, requireContext()); final var util = BrandingUtil.of(color, requireContext());
util.material.colorTextInputLayout(binding.inputWrapper); util.material.colorTextInputLayout(binding.inputWrapper);
} }

View file

@ -33,7 +33,6 @@ import it.niedermann.owncloud.notes.persistence.ApiProvider;
import it.niedermann.owncloud.notes.persistence.CapabilitiesClient; import it.niedermann.owncloud.notes.persistence.CapabilitiesClient;
import it.niedermann.owncloud.notes.persistence.SyncWorker; import it.niedermann.owncloud.notes.persistence.SyncWorker;
import it.niedermann.owncloud.notes.persistence.entity.Account; import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
import it.niedermann.owncloud.notes.shared.model.IResponseCallback; import it.niedermann.owncloud.notes.shared.model.IResponseCallback;
public class ImportAccountActivity extends AppCompatActivity { public class ImportAccountActivity extends AppCompatActivity {
@ -107,7 +106,7 @@ public class ImportAccountActivity extends AppCompatActivity {
public void onSuccess(Account account) { public void onSuccess(Account account) {
runOnUiThread(() -> { runOnUiThread(() -> {
Log.i(TAG, capabilities.toString()); Log.i(TAG, capabilities.toString());
BrandingUtil.saveBrandColors(ImportAccountActivity.this, capabilities.getColor(), capabilities.getTextColor()); BrandingUtil.saveBrandColor(ImportAccountActivity.this, capabilities.getColor());
setResult(RESULT_OK); setResult(RESULT_OK);
finish(); finish();
}); });

View file

@ -24,6 +24,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
@ -63,6 +64,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import it.niedermann.android.util.ColorUtil;
import it.niedermann.owncloud.notes.LockedActivity; import it.niedermann.owncloud.notes.LockedActivity;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener; import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener;
@ -590,22 +592,22 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.material.themeFAB(activityBinding.fabCreate); util.material.themeFAB(activityBinding.fabCreate);
util.platform.colorCircularProgressBar(activityBinding.progressCircular); util.platform.colorCircularProgressBar(activityBinding.progressCircular);
util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent);
binding.headerView.setBackgroundColor(mainColor); binding.headerView.setBackgroundColor(color);
binding.appName.setTextColor(textColor); @ColorInt final int headerTextColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(color);
binding.appName.setTextColor(headerTextColor);
DrawableCompat.setTint(binding.logo.getDrawable(), headerTextColor);
// TODO We assume, that the background of the spinner is always white // TODO We assume, that the background of the spinner is always white
activityBinding.swiperefreshlayout.setColorSchemeColors(contrastRatioIsSufficient(Color.WHITE, mainColor) ? mainColor : Color.BLACK); activityBinding.swiperefreshlayout.setColorSchemeColors(contrastRatioIsSufficient(Color.WHITE, color) ? color : Color.BLACK);
binding.appName.setTextColor(textColor);
DrawableCompat.setTint(binding.logo.getDrawable(), textColor);
adapter.applyBrand(mainColor, textColor); adapter.applyBrand(color);
adapterCategories.applyBrand(mainColor, textColor); adapterCategories.applyBrand(color);
invalidateOptionsMenu(); invalidateOptionsMenu();
} }

View file

@ -120,7 +120,7 @@ public class MainViewModel extends AndroidViewModel {
public void postCurrentAccount(@NonNull Account account) { public void postCurrentAccount(@NonNull Account account) {
state.set(KEY_CURRENT_ACCOUNT, account); state.set(KEY_CURRENT_ACCOUNT, account);
BrandingUtil.saveBrandColors(getApplication(), account.getColor(), account.getTextColor()); BrandingUtil.saveBrandColor(getApplication(), account.getColor());
SingleAccountHelper.setCurrentAccount(getApplication(), account.getAccountName()); SingleAccountHelper.setCurrentAccount(getApplication(), account.getAccountName());
final var currentAccount = this.currentAccount.getValue(); final var currentAccount = this.currentAccount.getValue();
@ -410,10 +410,9 @@ public class MainViewModel extends AndroidViewModel {
try { try {
final var capabilities = CapabilitiesClient.getCapabilities(getApplication(), ssoAccount, localAccount.getCapabilitiesETag(), ApiProvider.getInstance()); final var capabilities = CapabilitiesClient.getCapabilities(getApplication(), ssoAccount, localAccount.getCapabilitiesETag(), ApiProvider.getInstance());
repo.updateCapabilitiesETag(localAccount.getId(), capabilities.getETag()); repo.updateCapabilitiesETag(localAccount.getId(), capabilities.getETag());
repo.updateBrand(localAccount.getId(), capabilities.getColor(), capabilities.getTextColor()); repo.updateBrand(localAccount.getId(), capabilities.getColor());
localAccount.setColor(capabilities.getColor()); localAccount.setColor(capabilities.getColor());
localAccount.setTextColor(capabilities.getTextColor()); BrandingUtil.saveBrandColor(getApplication(), localAccount.getColor());
BrandingUtil.saveBrandColors(getApplication(), localAccount.getColor(), localAccount.getTextColor());
repo.updateApiVersion(localAccount.getId(), capabilities.getApiVersion()); repo.updateApiVersion(localAccount.getId(), capabilities.getApiVersion());
callback.onSuccess(null); callback.onSuccess(null);
} catch (Throwable t) { } catch (Throwable t) {

View file

@ -1,8 +1,6 @@
package it.niedermann.owncloud.notes.main.items; package it.niedermann.owncloud.notes.main.items;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -59,17 +57,14 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
private final float fontSize; private final float fontSize;
private final boolean monospace; private final boolean monospace;
@ColorInt @ColorInt
private int mainColor; private int color;
@ColorInt
private int textColor;
@Nullable @Nullable
private Integer swipedPosition; private Integer swipedPosition;
public <T extends Context & NoteClickListener> ItemAdapter(@NonNull T context, boolean gridView) { public <T extends Context & NoteClickListener> ItemAdapter(@NonNull T context, boolean gridView) {
this.noteClickListener = context; this.noteClickListener = context;
this.gridView = gridView; this.gridView = gridView;
this.mainColor = ContextCompat.getColor(context, R.color.defaultBrand); this.color = ContextCompat.getColor(context, R.color.defaultBrand);
this.textColor = Color.WHITE;
final var sp = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); final var sp = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
this.fontSize = getFontSizeFromPreferences(context, sp); this.fontSize = getFontSizeFromPreferences(context, sp);
this.monospace = sp.getBoolean(context.getString(R.string.pref_key_font), false); this.monospace = sp.getBoolean(context.getString(R.string.pref_key_font), false);
@ -156,7 +151,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
case TYPE_NOTE_WITH_EXCERPT: case TYPE_NOTE_WITH_EXCERPT:
case TYPE_NOTE_WITHOUT_EXCERPT: case TYPE_NOTE_WITHOUT_EXCERPT:
case TYPE_NOTE_ONLY_TITLE: { case TYPE_NOTE_ONLY_TITLE: {
((NoteViewHolder) holder).bind(isSelected, (Note) itemList.get(position), showCategory, mainColor, textColor, searchQuery); ((NoteViewHolder) holder).bind(isSelected, (Note) itemList.get(position), showCategory, color, searchQuery);
break; break;
} }
} }
@ -208,9 +203,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
this.mainColor = mainColor; this.color = color;
this.textColor = textColor;
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -49,7 +49,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
} }
@CallSuper @CallSuper
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @ColorInt int color, @Nullable CharSequence searchQuery) {
itemView.setSelected(isSelected); itemView.setSelected(isSelected);
itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view)); itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view));
} }

View file

@ -6,6 +6,7 @@ import android.text.TextUtils;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.Px; import androidx.annotation.Px;
@ -39,14 +40,14 @@ public class NoteViewGridHolder extends NoteViewHolder {
throw new UnsupportedOperationException(NoteViewGridHolder.class.getSimpleName() + " does not support swiping"); throw new UnsupportedOperationException(NoteViewGridHolder.class.getSimpleName() + " does not support swiping");
} }
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @ColorInt int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery); super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final Context context = itemView.getContext(); @NonNull final Context context = itemView.getContext();
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), color);
bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite()); bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt().replace(EXCERPT_LINE_SEPARATOR, "\n"), mainColor); bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt().replace(EXCERPT_LINE_SEPARATOR, "\n"), color);
binding.noteExcerpt.setVisibility(TextUtils.isEmpty(note.getExcerpt()) ? GONE : VISIBLE); binding.noteExcerpt.setVisibility(TextUtils.isEmpty(note.getExcerpt()) ? GONE : VISIBLE);
} }

View file

@ -32,12 +32,12 @@ public class NoteViewGridHolderOnlyTitle extends NoteViewHolder {
throw new UnsupportedOperationException(NoteViewGridHolderOnlyTitle.class.getSimpleName() + " does not support swiping"); throw new UnsupportedOperationException(NoteViewGridHolderOnlyTitle.class.getSimpleName() + " does not support swiping");
} }
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery); super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final Context context = itemView.getContext(); @NonNull final Context context = itemView.getContext();
bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite()); bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
} }
@Nullable @Nullable

View file

@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.main.items.list;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -28,16 +29,16 @@ public class NoteViewHolderWithExcerpt extends NoteViewHolder {
binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention);
} }
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @ColorInt int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery); super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final var context = itemView.getContext(); @NonNull final var context = itemView.getContext();
binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f);
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), color);
bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite()); bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt(), mainColor); bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt(), color);
} }
@NonNull @NonNull

View file

@ -28,14 +28,14 @@ public class NoteViewHolderWithoutExcerpt extends NoteViewHolder {
binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention);
} }
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery); super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final Context context = itemView.getContext(); @NonNull final Context context = itemView.getContext();
binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f);
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), color);
bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite()); bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
} }
@NonNull @NonNull

View file

@ -24,7 +24,6 @@ public class MenuViewHolder extends RecyclerView.ViewHolder {
public void bind(@NonNull MenuItem menuItem, @NonNull Consumer<MenuItem> onClick) { public void bind(@NonNull MenuItem menuItem, @NonNull Consumer<MenuItem> onClick) {
@NonNull Context context = itemView.getContext(); @NonNull Context context = itemView.getContext();
binding.navigationItemLabel.setText(context.getString(menuItem.getLabelResource())); binding.navigationItemLabel.setText(context.getString(menuItem.getLabelResource()));
binding.navigationItemLabel.setTextColor(binding.getRoot().getResources().getColor(R.color.fg_default));
binding.navigationItemIcon.setImageDrawable(ContextCompat.getDrawable(context, menuItem.getDrawableResource())); binding.navigationItemIcon.setImageDrawable(ContextCompat.getDrawable(context, menuItem.getDrawableResource()));
binding.navigationItemCount.setVisibility(GONE); binding.navigationItemCount.setVisibility(GONE);
binding.getRoot().setOnClickListener((v) -> onClick.accept(menuItem)); binding.getRoot().setOnClickListener((v) -> onClick.accept(menuItem));

View file

@ -24,7 +24,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationViewHolder
@NonNull @NonNull
private final Context context; private final Context context;
@ColorInt @ColorInt
private int mainColor; private int color;
@DrawableRes @DrawableRes
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp; public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
@DrawableRes @DrawableRes
@ -38,9 +38,9 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationViewHolder
@DrawableRes @DrawableRes
public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp; public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp;
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, context); final var util = BrandingUtil.of(color, context);
this.mainColor = util.notes.getOnPrimaryContainer(context); this.color = util.notes.getOnPrimaryContainer(context);
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -53,7 +53,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationViewHolder
public NavigationAdapter(@NonNull Context context, @NonNull NavigationClickListener navigationClickListener) { public NavigationAdapter(@NonNull Context context, @NonNull NavigationClickListener navigationClickListener) {
this.context = context; this.context = context;
final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context); final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context);
this.mainColor = util.notes.getOnPrimaryContainer(context); this.color = util.notes.getOnPrimaryContainer(context);
this.navigationClickListener = navigationClickListener; this.navigationClickListener = navigationClickListener;
} }
@ -65,7 +65,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationViewHolder
@Override @Override
public void onBindViewHolder(@NonNull NavigationViewHolder holder, int position) { public void onBindViewHolder(@NonNull NavigationViewHolder holder, int position) {
holder.bind(items.get(position), mainColor, selectedItem); holder.bind(items.get(position), color, selectedItem);
} }
@Override @Override

View file

@ -208,8 +208,8 @@ public class ManageAccountsActivity extends LockedActivity implements IManageAcc
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
} }
} }

View file

@ -49,7 +49,7 @@ public class CapabilitiesWorker extends Worker {
Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name); Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
final var capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag(), ApiProvider.getInstance()); final var capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag(), ApiProvider.getInstance());
repo.updateCapabilitiesETag(account.getId(), capabilities.getETag()); repo.updateCapabilitiesETag(account.getId(), capabilities.getETag());
repo.updateBrand(account.getId(), capabilities.getColor(), capabilities.getTextColor()); repo.updateBrand(account.getId(), capabilities.getColor());
repo.updateApiVersion(account.getId(), capabilities.getApiVersion()); repo.updateApiVersion(account.getId(), capabilities.getApiVersion());
Log.i(TAG, capabilities.toString()); Log.i(TAG, capabilities.toString());
repo.updateDisplayName(account.getId(), CapabilitiesClient.getDisplayName(getApplicationContext(), ssoAccount, ApiProvider.getInstance())); repo.updateDisplayName(account.getId(), CapabilitiesClient.getDisplayName(getApplicationContext(), ssoAccount, ApiProvider.getInstance()));

View file

@ -34,6 +34,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_19_20;
import it.niedermann.owncloud.notes.persistence.migration.Migration_20_21; import it.niedermann.owncloud.notes.persistence.migration.Migration_20_21;
import it.niedermann.owncloud.notes.persistence.migration.Migration_21_22; import it.niedermann.owncloud.notes.persistence.migration.Migration_21_22;
import it.niedermann.owncloud.notes.persistence.migration.Migration_22_23; import it.niedermann.owncloud.notes.persistence.migration.Migration_22_23;
import it.niedermann.owncloud.notes.persistence.migration.Migration_23_24;
import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10; import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10;
@Database( @Database(
@ -43,7 +44,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10;
CategoryOptions.class, CategoryOptions.class,
SingleNoteWidgetData.class, SingleNoteWidgetData.class,
NotesListWidgetData.class NotesListWidgetData.class
}, version = 23 }, version = 24
) )
@TypeConverters({Converters.class}) @TypeConverters({Converters.class})
public abstract class NotesDatabase extends RoomDatabase { public abstract class NotesDatabase extends RoomDatabase {
@ -78,7 +79,8 @@ public abstract class NotesDatabase extends RoomDatabase {
new Migration_19_20(context), new Migration_19_20(context),
new Migration_20_21(), new Migration_20_21(),
new Migration_21_22(context), new Migration_21_22(context),
new Migration_22_23() new Migration_22_23(),
new Migration_23_24(context)
) )
.fallbackToDestructiveMigrationOnDowngrade() .fallbackToDestructiveMigrationOnDowngrade()
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()

View file

@ -248,8 +248,8 @@ public class NotesRepository {
return db.getAccountDao().countAccounts$(); return db.getAccountDao().countAccounts$();
} }
public void updateBrand(long id, @ColorInt Integer color, @ColorInt Integer textColor) { public void updateBrand(long id, @ColorInt Integer color) {
db.getAccountDao().updateBrand(id, color, textColor); db.getAccountDao().updateBrand(id, color);
} }
public void updateETag(long id, String eTag) { public void updateETag(long id, String eTag) {

View file

@ -42,8 +42,8 @@ public interface AccountDao {
@Query("SELECT COUNT(*) FROM Account") @Query("SELECT COUNT(*) FROM Account")
LiveData<Integer> countAccounts$(); LiveData<Integer> countAccounts$();
@Query("UPDATE Account SET COLOR = :color, TEXTCOLOR = :textColor WHERE id = :id") @Query("UPDATE Account SET COLOR = :color WHERE id = :id")
void updateBrand(long id, @ColorInt Integer color, @ColorInt Integer textColor); void updateBrand(long id, @ColorInt Integer color);
@Query("UPDATE Account SET ETAG = :eTag WHERE ID = :id") @Query("UPDATE Account SET ETAG = :eTag WHERE ID = :id")
void updateETag(long id, String eTag); void updateETag(long id, String eTag);

View file

@ -77,7 +77,6 @@ public class Account implements Serializable {
capabilitiesETag = capabilities.getETag(); capabilitiesETag = capabilities.getETag();
apiVersion = capabilities.getApiVersion(); apiVersion = capabilities.getApiVersion();
setColor(capabilities.getColor()); setColor(capabilities.getColor());
setTextColor(capabilities.getTextColor());
} }
public long getId() { public long getId() {

View file

@ -0,0 +1,28 @@
package it.niedermann.owncloud.notes.persistence.migration;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
/**
* Remove <code>textColor</code> property from {@link android.content.SharedPreferences} and the
* database as it is no longer needed for theming.
*/
public class Migration_23_24 extends Migration {
@NonNull
private final Context context;
public Migration_23_24(@NonNull Context context) {
super(23, 24);
this.context = context;
}
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
PreferenceManager.getDefaultSharedPreferences(context).edit().remove("branding_text").apply();
}
}

View file

@ -32,8 +32,8 @@ public class PreferencesActivity extends LockedActivity {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
final var util = BrandingUtil.of(mainColor, this); final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
} }
} }

View file

@ -115,27 +115,25 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
final var context = requireContext(); final var context = requireContext();
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context); @ColorInt final int color = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context); applyBrand(color);
applyBrand(mainColor, textColor);
} }
/** /**
* Change color for backgroundSyncPref as well * Change color for backgroundSyncPref as well
* https://github.com/stefan-niedermann/nextcloud-deck/issues/531 * https://github.com/stefan-niedermann/nextcloud-deck/issues/531
* *
* @param mainColor color of main brand * @param color color of main brand
* @param textColor color of text
*/ */
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
fontPref.applyBrand(mainColor, textColor); fontPref.applyBrand(color);
lockPref.applyBrand(mainColor, textColor); lockPref.applyBrand(color);
wifiOnlyPref.applyBrand(mainColor, textColor); wifiOnlyPref.applyBrand(color);
gridViewPref.applyBrand(mainColor, textColor); gridViewPref.applyBrand(color);
preventScreenCapturePref.applyBrand(mainColor, textColor); preventScreenCapturePref.applyBrand(color);
backgroundSyncPref.applyBrand(mainColor, textColor); backgroundSyncPref.applyBrand(color);
keepScreenOnPref.applyBrand(mainColor, textColor); keepScreenOnPref.applyBrand(color);
} }
} }

View file

@ -142,6 +142,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
} }
@Override @Override
public void applyBrand(int mainColor, int textColor) { public void applyBrand(int color) {
// Nothing to do...
} }
} }