Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2558acd4 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

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


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

Signed-off-by: default avatarStefan Niedermann <info@niedermann.it>
parent 990a5b5a
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -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}.
+5 −20
Original line number Diff line number Diff line
@@ -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;
        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);
            }
    protected void bindSearchableContent(@NonNull Context context, @NonNull TextView textView, @Nullable CharSequence searchQuery, @NonNull String content, int color) {
        textView.setText(content);

            processedContent = spannableString;
        if (!TextUtils.isEmpty(searchQuery)) {
            final var util = BrandingUtil.of(color, context);
            util.platform.highlightText(textView, content, searchQuery.toString());
        }
        textView.setText(processedContent);
    }

    public abstract void showSwipe(boolean left);