mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 12:56:02 +03:00
Fix some coloring issues with dark theme
This commit is contained in:
parent
9664561935
commit
93cb684791
5 changed files with 14 additions and 15 deletions
|
@ -242,7 +242,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
|
|||
protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) {
|
||||
if (binding != null && isAttachedToWindow(binding.editContent)) {
|
||||
binding.editContent.clearFocus();
|
||||
binding.editContent.setText(searchAndColor(new SpannableString(getContent()), newText, getResources(), current, mainColor, textColor), TextView.BufferType.SPANNABLE);
|
||||
binding.editContent.setText(searchAndColor(new SpannableString(getContent()), newText, requireContext(), current, mainColor, textColor), TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
|
|||
protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) {
|
||||
if (binding != null && ViewCompat.isAttachedToWindow(binding.singleNoteContent)) {
|
||||
binding.singleNoteContent.setText(
|
||||
searchAndColor(new SpannableString(parseCompat(markdownProcessor, getContent())), newText, getResources(), current, mainColor, textColor),
|
||||
searchAndColor(new SpannableString(parseCompat(markdownProcessor, getContent())), newText, requireContext(), current, mainColor, textColor),
|
||||
TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {
|
|||
@Override
|
||||
protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) {
|
||||
if ((binding != null) && isAttachedToWindow(binding.singleNoteContent)) {
|
||||
binding.singleNoteContent.setText(searchAndColor(new SpannableString(parseCompat(markdownProcessor, getContent())), newText, getResources(), current, mainColor, textColor), TextView.BufferType.SPANNABLE);
|
||||
binding.singleNoteContent.setText(searchAndColor(new SpannableString(parseCompat(markdownProcessor, getContent())), newText, requireContext(), current, mainColor, textColor), TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandingUtil;
|
||||
import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemBinding;
|
||||
import it.niedermann.owncloud.notes.util.ColorUtil;
|
||||
import it.niedermann.owncloud.notes.util.Notes;
|
||||
|
||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||
|
@ -69,7 +69,7 @@ public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLo
|
|||
binding.noteFavorite.setOnClickListener(view -> noteClickListener.onNoteFavoriteClick(getAdapterPosition(), view));
|
||||
|
||||
@ColorInt final int searchBackground = binding.noteExcerpt.getContext().getResources().getColor(R.color.bg_highlighted);
|
||||
@ColorInt final int searchForeground = ColorUtil.contrastRatioIsSufficient(mainColor, searchBackground) ? mainColor : Color.BLACK;
|
||||
@ColorInt final int searchForeground = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(binding.noteExcerpt.getContext(), mainColor);
|
||||
if (!TextUtils.isEmpty(searchQuery)) {
|
||||
final Pattern pattern = Pattern.compile("(" + searchQuery + ")", Pattern.CASE_INSENSITIVE);
|
||||
SpannableString spannableString = new SpannableString(note.getTitle());
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
*/
|
||||
package it.niedermann.owncloud.notes.util;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
|
@ -34,8 +33,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandingUtil;
|
||||
|
||||
import static it.niedermann.owncloud.notes.util.ColorUtil.contrastRatioIsSufficient;
|
||||
import static it.niedermann.owncloud.notes.util.ColorUtil.isColorDark;
|
||||
|
||||
public class DisplayUtils {
|
||||
|
@ -44,7 +43,7 @@ public class DisplayUtils {
|
|||
|
||||
}
|
||||
|
||||
public static Spannable searchAndColor(Spannable spannable, CharSequence searchText, @NonNull Resources resources, @Nullable Integer current, @ColorInt int mainColor, @ColorInt int textColor) {
|
||||
public static Spannable searchAndColor(Spannable spannable, CharSequence searchText, @NonNull Context context, @Nullable Integer current, @ColorInt int mainColor, @ColorInt int textColor) {
|
||||
CharSequence text = spannable.toString();
|
||||
|
||||
Object[] spansToRemove = spannable.getSpans(0, text.length(), Object.class);
|
||||
|
@ -64,7 +63,7 @@ public class DisplayUtils {
|
|||
while (m.find()) {
|
||||
int start = m.start();
|
||||
int end = m.end();
|
||||
spannable.setSpan(new SearchSpan(resources, mainColor, textColor, (current != null && i == current)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannable.setSpan(new SearchSpan(context, mainColor, textColor, (current != null && i == current)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -76,14 +75,14 @@ public class DisplayUtils {
|
|||
|
||||
private final boolean current;
|
||||
@NonNull
|
||||
Resources resources;
|
||||
Context context;
|
||||
@ColorInt
|
||||
private final int mainColor;
|
||||
@ColorInt
|
||||
private final int textColor;
|
||||
|
||||
SearchSpan(@NonNull Resources resources, @ColorInt int mainColor, @ColorInt int textColor, boolean current) {
|
||||
this.resources = resources;
|
||||
SearchSpan(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor, boolean current) {
|
||||
this.context = context;
|
||||
this.mainColor = mainColor;
|
||||
this.textColor = textColor;
|
||||
this.current = current;
|
||||
|
@ -91,8 +90,8 @@ public class DisplayUtils {
|
|||
|
||||
@Override
|
||||
public void updateDrawState(TextPaint tp) {
|
||||
tp.bgColor = current ? isColorDark(mainColor) ? mainColor : textColor : resources.getColor(R.color.bg_highlighted);
|
||||
tp.setColor(current ? isColorDark(mainColor) ? textColor : mainColor : contrastRatioIsSufficient(mainColor, resources.getColor(R.color.bg_highlighted)) ? mainColor : Color.BLACK);
|
||||
tp.bgColor = current ? isColorDark(mainColor) ? mainColor : textColor : context.getResources().getColor(R.color.bg_highlighted);
|
||||
tp.setColor(current ? isColorDark(mainColor) ? textColor : mainColor : BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, mainColor));
|
||||
tp.setFakeBoldText(true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue