@@ -89,28 +89,13 @@ protected void bindFavorite(@NonNull ImageView noteFavorite, boolean isFavorite)
8989 noteFavorite .setOnClickListener (view -> noteClickListener .onNoteFavoriteClick (getLayoutPosition (), view ));
9090 }
9191
92- protected void bindSearchableContent (@ NonNull Context context , @ NonNull TextView textView , @ Nullable CharSequence searchQuery , @ NonNull String content , int mainColor ) {
93- CharSequence processedContent = content ;
94- if (!TextUtils .isEmpty (searchQuery )) {
95- final var util = BrandingUtil .of (mainColor , context );
96- @ ColorInt final int searchForeground = util .notes .getOnPrimaryContainer (context );
97- @ ColorInt final int searchBackground = ContextCompat .getColor (context , R .color .bg_highlighted );
98-
99- // The Pattern.quote method will add \Q to the very beginning of the string and \E to the end of the string
100- // It implies that the string between \Q and \E is a literal string and thus the reserved keyword in such string will be ignored.
101- // See https://stackoverflow.com/questions/15409296/what-is-the-use-of-pattern-quote-method
102- final Pattern pattern = Pattern .compile ("(" + Pattern .quote (searchQuery .toString ()) + ")" , Pattern .CASE_INSENSITIVE );
103- SpannableString spannableString = new SpannableString (content );
104- Matcher matcher = pattern .matcher (spannableString );
105-
106- while (matcher .find ()) {
107- spannableString .setSpan (new ForegroundColorSpan (searchForeground ), matcher .start (), matcher .end (), 0 );
108- spannableString .setSpan (new BackgroundColorSpan (searchBackground ), matcher .start (), matcher .end (), 0 );
109- }
92+ protected void bindSearchableContent (@ NonNull Context context , @ NonNull TextView textView , @ Nullable CharSequence searchQuery , @ NonNull String content , int color ) {
93+ textView .setText (content );
11094
111- processedContent = spannableString ;
95+ if (!TextUtils .isEmpty (searchQuery )) {
96+ final var util = BrandingUtil .of (color , context );
97+ util .platform .highlightText (textView , content , searchQuery .toString ());
11298 }
113- textView .setText (processedContent );
11499 }
115100
116101 public abstract void showSwipe (boolean left );
0 commit comments