feat(theming): Remove NotesViewThemeUtils#getOnPrimaryContainer in favor of AndroidViewThemeUtils#highlightText

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2023-02-16 13:08:07 +01:00
parent 990a5b5a80
commit 2558acd4bf
2 changed files with 5 additions and 29 deletions

View file

@ -41,15 +41,6 @@ public class NotesViewThemeUtils extends ViewThemeUtilsBase {
super(schemes);
}
/**
* Use {@link ColorRole#ON_PRIMARY_CONTAINER}
*/
@Deprecated(forRemoval = true)
@ColorInt
public int getOnPrimaryContainer(@NonNull Context context) {
return withScheme(context, Scheme::getOnPrimaryContainer);
}
/**
* The Notes app uses custom navigation view items because they have several features which are
* not covered by {@link NavigationItem}.

View file

@ -89,28 +89,13 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
noteFavorite.setOnClickListener(view -> noteClickListener.onNoteFavoriteClick(getLayoutPosition(), view));
}
protected void bindSearchableContent(@NonNull Context context, @NonNull TextView textView, @Nullable CharSequence searchQuery, @NonNull String content, int mainColor) {
CharSequence processedContent = content;
protected void bindSearchableContent(@NonNull Context context, @NonNull TextView textView, @Nullable CharSequence searchQuery, @NonNull String content, int color) {
textView.setText(content);
if (!TextUtils.isEmpty(searchQuery)) {
final var util = BrandingUtil.of(mainColor, context);
@ColorInt final int searchForeground = util.notes.getOnPrimaryContainer(context);
@ColorInt final int searchBackground = ContextCompat.getColor(context, R.color.bg_highlighted);
// The Pattern.quote method will add \Q to the very beginning of the string and \E to the end of the string
// It implies that the string between \Q and \E is a literal string and thus the reserved keyword in such string will be ignored.
// See https://stackoverflow.com/questions/15409296/what-is-the-use-of-pattern-quote-method
final Pattern pattern = Pattern.compile("(" + Pattern.quote(searchQuery.toString()) + ")", Pattern.CASE_INSENSITIVE);
SpannableString spannableString = new SpannableString(content);
Matcher matcher = pattern.matcher(spannableString);
while (matcher.find()) {
spannableString.setSpan(new ForegroundColorSpan(searchForeground), matcher.start(), matcher.end(), 0);
spannableString.setSpan(new BackgroundColorSpan(searchBackground), matcher.start(), matcher.end(), 0);
final var util = BrandingUtil.of(color, context);
util.platform.highlightText(textView, content, searchQuery.toString());
}
processedContent = spannableString;
}
textView.setText(processedContent);
}
public abstract void showSwipe(boolean left);