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
public void applyBrand(int mainColor, int textColor) {
final var util = BrandingUtil.of(mainColor, this);
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -5,5 +5,5 @@ import androidx.annotation.UiThread;
public interface Branded {
@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;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.readBrandColors;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.readBrandMainColorLiveData;
import android.util.TypedValue;
import android.view.Menu;
@ -23,7 +23,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand
getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
colorAccent = typedValue.data;
readBrandColors(this).observe(this, (pair) -> applyBrand(pair.first, pair.second));
readBrandMainColorLiveData(this).observe(this, this::applyBrand);
}
@Override

View file

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

View file

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

View file

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

View file

@ -1,56 +1,32 @@
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.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.LayerDrawable;
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.IdRes;
import androidx.annotation.NonNull;
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.MediatorLiveData;
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.ViewThemeUtilsBase;
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.DialogViewThemeUtils;
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.ConcurrentMap;
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.shared.util.NotesColorUtil;
import scheme.Scheme;
public class BrandingUtil extends ViewThemeUtilsBase {
private static final String TAG = BrandingUtil.class.getSimpleName();
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_text = "branding_text";
public final AndroidViewThemeUtils platform;
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) {
final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Log.v(TAG, "--- Read: shared_preference_theme_main");
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
public static int readBrandMainColor(@NonNull Context context) {
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));
}
@ColorInt
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) {
public static void saveBrandColor(@NonNull Context context, @ColorInt int color) {
final int previousMainColor = readBrandMainColor(context);
final int previousTextColor = readBrandTextColor(context);
final var 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);
Log.v(TAG, "--- Write: shared_preference_theme_main" + " | " + color);
editor.putInt(pref_key_branding_main, color);
editor.apply();
if (context instanceof BrandedActivity) {
if (mainColor != previousMainColor || textColor != previousTextColor) {
if (color != previousMainColor) {
final var activity = (BrandedActivity) context;
activity.runOnUiThread(() -> ActivityCompat.recreate(activity));
}

View file

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

View file

@ -242,7 +242,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
}
@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)) {
binding.editContent.clearFocus();
binding.editContent.setSearchText(newText, current);
@ -250,12 +250,12 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
}
@Override
public void applyBrand(int mainColor, int textColor) {
super.applyBrand(mainColor, textColor);
public void applyBrand(int color) {
super.applyBrand(color);
final var util = BrandingUtil.of(mainColor, requireContext());
binding.editContent.setSearchColor(mainColor);
binding.editContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), mainColor, colorPrimary, colorAccent));
final var util = BrandingUtil.of(color, requireContext());
binding.editContent.setSearchColor(color);
binding.editContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), color, colorPrimary, colorAccent));
}
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.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
@ -138,7 +139,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
}
@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)) {
binding.singleNoteContent.clearFocus();
binding.singleNoteContent.setSearchText(newText, current);
@ -177,12 +178,12 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
}
@Override
public void applyBrand(int mainColor, int textColor) {
super.applyBrand(mainColor, textColor);
public void applyBrand(int color) {
super.applyBrand(color);
final var util = BrandingUtil.of(mainColor, requireContext());
binding.singleNoteContent.setSearchColor(mainColor);
binding.singleNoteContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), mainColor, colorPrimary, colorAccent));
final var util = BrandingUtil.of(color, requireContext());
binding.singleNoteContent.setSearchColor(color);
binding.singleNoteContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), color, colorPrimary, colorAccent));
}
public static BaseNoteFragment newInstance(long accountId, long noteId) {

View file

@ -7,11 +7,8 @@ import android.text.Layout;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.CallSuper;
import androidx.annotation.ColorInt;
@ -21,11 +18,9 @@ import androidx.appcompat.widget.SearchView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
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.
@ColorInt
private int mainColor;
@ColorInt
private int textColor;
private int color;
@Override
public void onStart() {
this.mainColor = getResources().getColor(R.color.defaultBrand);
this.textColor = Color.WHITE;
this.color = getResources().getColor(R.color.defaultBrand);
super.onStart();
}
@ -89,12 +81,12 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
if (currentVisibility != oldVisibility) {
if (currentVisibility != View.VISIBLE) {
colorWithText("", null, mainColor, textColor);
colorWithText("", null, color);
searchQuery = "";
hideSearchFabs();
} else {
jumpToOccurrence();
colorWithText(searchQuery, null, mainColor, textColor);
colorWithText(searchQuery, null, color);
occurrenceCount = countOccurrences(getContent(), searchQuery);
showSearchFabs();
}
@ -112,7 +104,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
next.setOnClickListener(v -> {
currentOccurrence++;
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());
currentOccurrence--;
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) {
currentOccurrence++;
jumpToOccurrence();
colorWithText(query, currentOccurrence, mainColor, textColor);
colorWithText(query, currentOccurrence, color);
return true;
}
@ -153,7 +145,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
}
currentOccurrence = 1;
jumpToOccurrence();
colorWithText(searchQuery, currentOccurrence, mainColor, textColor);
colorWithText(searchQuery, currentOccurrence, color);
}
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();
@ -293,11 +285,10 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@CallSuper
@Override
public void applyBrand(int mainColor, int textColor) {
this.mainColor = mainColor;
this.textColor = textColor;
public void applyBrand(int color) {
this.color = color;
final var util = BrandingUtil.of(mainColor, requireContext());
final var util = BrandingUtil.of(color, requireContext());
util.material.themeFAB(getSearchNextButton());
util.material.themeFAB(getSearchPrevButton());
}

View file

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

View file

@ -86,8 +86,8 @@ public class EditTitleDialogFragment extends BrandedDialogFragment {
}
@Override
public void applyBrand(int mainColor, int textColor) {
final var util = BrandingUtil.of(mainColor, requireContext());
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, requireContext());
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.SyncWorker;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
import it.niedermann.owncloud.notes.shared.model.IResponseCallback;
public class ImportAccountActivity extends AppCompatActivity {
@ -107,7 +106,7 @@ public class ImportAccountActivity extends AppCompatActivity {
public void onSuccess(Account account) {
runOnUiThread(() -> {
Log.i(TAG, capabilities.toString());
BrandingUtil.saveBrandColors(ImportAccountActivity.this, capabilities.getColor(), capabilities.getTextColor());
BrandingUtil.saveBrandColor(ImportAccountActivity.this, capabilities.getColor());
setResult(RESULT_OK);
finish();
});

View file

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

View file

@ -120,7 +120,7 @@ public class MainViewModel extends AndroidViewModel {
public void postCurrentAccount(@NonNull 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());
final var currentAccount = this.currentAccount.getValue();
@ -410,10 +410,9 @@ public class MainViewModel extends AndroidViewModel {
try {
final var capabilities = CapabilitiesClient.getCapabilities(getApplication(), ssoAccount, localAccount.getCapabilitiesETag(), ApiProvider.getInstance());
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.setTextColor(capabilities.getTextColor());
BrandingUtil.saveBrandColors(getApplication(), localAccount.getColor(), localAccount.getTextColor());
BrandingUtil.saveBrandColor(getApplication(), localAccount.getColor());
repo.updateApiVersion(localAccount.getId(), capabilities.getApiVersion());
callback.onSuccess(null);
} catch (Throwable t) {

View file

@ -1,8 +1,6 @@
package it.niedermann.owncloud.notes.main.items;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;
@ -59,17 +57,14 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
private final float fontSize;
private final boolean monospace;
@ColorInt
private int mainColor;
@ColorInt
private int textColor;
private int color;
@Nullable
private Integer swipedPosition;
public <T extends Context & NoteClickListener> ItemAdapter(@NonNull T context, boolean gridView) {
this.noteClickListener = context;
this.gridView = gridView;
this.mainColor = ContextCompat.getColor(context, R.color.defaultBrand);
this.textColor = Color.WHITE;
this.color = ContextCompat.getColor(context, R.color.defaultBrand);
final var sp = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
this.fontSize = getFontSizeFromPreferences(context, sp);
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_WITHOUT_EXCERPT:
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;
}
}
@ -208,9 +203,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
}
@Override
public void applyBrand(int mainColor, int textColor) {
this.mainColor = mainColor;
this.textColor = textColor;
public void applyBrand(int color) {
this.color = color;
notifyDataSetChanged();
}

View file

@ -49,7 +49,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
}
@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.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view));
}

View file

@ -6,6 +6,7 @@ import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
@ -39,14 +40,14 @@ public class NoteViewGridHolder extends NoteViewHolder {
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) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery);
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @ColorInt int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final Context context = itemView.getContext();
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor);
bindStatus(binding.noteStatus, note.getStatus(), mainColor);
bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), color);
bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor);
bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt().replace(EXCERPT_LINE_SEPARATOR, "\n"), mainColor);
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
bindSearchableContent(context, binding.noteExcerpt, searchQuery, note.getExcerpt().replace(EXCERPT_LINE_SEPARATOR, "\n"), color);
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");
}
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, mainColor, textColor, searchQuery);
public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, int color, @Nullable CharSequence searchQuery) {
super.bind(isSelected, note, showCategory, color, searchQuery);
@NonNull final Context context = itemView.getContext();
bindStatus(binding.noteStatus, note.getStatus(), mainColor);
bindStatus(binding.noteStatus, note.getStatus(), color);
bindFavorite(binding.noteFavorite, note.getFavorite());
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor);
bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), color);
}
@Nullable

View file

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

View file

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

View file

@ -24,7 +24,6 @@ public class MenuViewHolder extends RecyclerView.ViewHolder {
public void bind(@NonNull MenuItem menuItem, @NonNull Consumer<MenuItem> onClick) {
@NonNull Context context = itemView.getContext();
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.navigationItemCount.setVisibility(GONE);
binding.getRoot().setOnClickListener((v) -> onClick.accept(menuItem));

View file

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

View file

@ -208,8 +208,8 @@ public class ManageAccountsActivity extends LockedActivity implements IManageAcc
}
@Override
public void applyBrand(int mainColor, int textColor) {
final var util = BrandingUtil.of(mainColor, this);
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
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);
final var capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag(), ApiProvider.getInstance());
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());
Log.i(TAG, capabilities.toString());
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_21_22;
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;
@Database(
@ -43,7 +44,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10;
CategoryOptions.class,
SingleNoteWidgetData.class,
NotesListWidgetData.class
}, version = 23
}, version = 24
)
@TypeConverters({Converters.class})
public abstract class NotesDatabase extends RoomDatabase {
@ -78,7 +79,8 @@ public abstract class NotesDatabase extends RoomDatabase {
new Migration_19_20(context),
new Migration_20_21(),
new Migration_21_22(context),
new Migration_22_23()
new Migration_22_23(),
new Migration_23_24(context)
)
.fallbackToDestructiveMigrationOnDowngrade()
.fallbackToDestructiveMigration()

View file

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

View file

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

View file

@ -77,7 +77,6 @@ public class Account implements Serializable {
capabilitiesETag = capabilities.getETag();
apiVersion = capabilities.getApiVersion();
setColor(capabilities.getColor());
setTextColor(capabilities.getTextColor());
}
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
public void applyBrand(int mainColor, int textColor) {
final var util = BrandingUtil.of(mainColor, this);
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
}
}

View file

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

View file

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