1
1
package ml .docilealligator .infinityforreddit .adapters ;
2
2
3
- import android .graphics . drawable . Drawable ;
3
+ import android .content . res . ColorStateList ;
4
4
import android .view .LayoutInflater ;
5
5
import android .view .ViewGroup ;
6
6
9
9
10
10
import java .util .List ;
11
11
12
- import ml .docilealligator .infinityforreddit .R ;
13
12
import ml .docilealligator .infinityforreddit .activities .BaseActivity ;
14
13
import ml .docilealligator .infinityforreddit .customtheme .CustomThemeWrapper ;
15
14
import ml .docilealligator .infinityforreddit .databinding .ItemRecentSearchQueryBinding ;
16
15
import ml .docilealligator .infinityforreddit .recentsearchquery .RecentSearchQuery ;
17
- import ml .docilealligator .infinityforreddit .utils .Utils ;
18
16
19
17
public class SearchActivityRecyclerViewAdapter extends RecyclerView .Adapter <RecyclerView .ViewHolder > {
20
18
private final BaseActivity activity ;
21
19
private List <RecentSearchQuery > recentSearchQueries ;
20
+ private final int filledCardViewBackgroundColor ;
22
21
private final int primaryTextColor ;
23
- private final Drawable historyIcon ;
24
- private final Drawable deleteIcon ;
22
+ private final int secondaryTextColor ;
25
23
private final ItemOnClickListener itemOnClickListener ;
26
24
27
25
public interface ItemOnClickListener {
@@ -32,9 +30,9 @@ public interface ItemOnClickListener {
32
30
public SearchActivityRecyclerViewAdapter (BaseActivity activity , CustomThemeWrapper customThemeWrapper ,
33
31
ItemOnClickListener itemOnClickListener ) {
34
32
this .activity = activity ;
33
+ this .filledCardViewBackgroundColor = customThemeWrapper .getFilledCardViewBackgroundColor ();
35
34
this .primaryTextColor = customThemeWrapper .getPrimaryTextColor ();
36
- this .historyIcon = Utils .getTintedDrawable (activity , R .drawable .ic_history_24dp , customThemeWrapper .getPrimaryIconColor ());
37
- this .deleteIcon = Utils .getTintedDrawable (activity , R .drawable .ic_delete_24dp , customThemeWrapper .getPrimaryIconColor ());
35
+ this .secondaryTextColor = customThemeWrapper .getSecondaryTextColor ();
38
36
this .itemOnClickListener = itemOnClickListener ;
39
37
}
40
38
@@ -49,6 +47,10 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
49
47
if (holder instanceof RecentSearchQueryViewHolder ) {
50
48
if (recentSearchQueries != null && !recentSearchQueries .isEmpty () && position < recentSearchQueries .size ()) {
51
49
((RecentSearchQueryViewHolder ) holder ).binding .recentSearchQueryTextViewItemRecentSearchQuery .setText (recentSearchQueries .get (position ).getSearchQuery ());
50
+ holder .itemView .postDelayed (() -> {
51
+ ((RecentSearchQueryViewHolder ) holder ).binding .recentSearchQueryTextViewItemRecentSearchQuery .setSelected (true );
52
+ ((RecentSearchQueryViewHolder ) holder ).binding .recentSearchQueryWhereTextViewItemRecentSearchQuery .setSelected (true );
53
+ }, 1000 );
52
54
}
53
55
}
54
56
}
@@ -58,6 +60,15 @@ public int getItemCount() {
58
60
return recentSearchQueries == null ? 0 : recentSearchQueries .size ();
59
61
}
60
62
63
+ @ Override
64
+ public void onViewRecycled (@ NonNull RecyclerView .ViewHolder holder ) {
65
+ super .onViewRecycled (holder );
66
+ if (holder instanceof RecentSearchQueryViewHolder ) {
67
+ ((RecentSearchQueryViewHolder ) holder ).binding .recentSearchQueryTextViewItemRecentSearchQuery .setSelected (false );
68
+ ((RecentSearchQueryViewHolder ) holder ).binding .recentSearchQueryWhereTextViewItemRecentSearchQuery .setSelected (false );
69
+ }
70
+ }
71
+
61
72
public void setRecentSearchQueries (List <RecentSearchQuery > recentSearchQueries ) {
62
73
this .recentSearchQueries = recentSearchQueries ;
63
74
notifyDataSetChanged ();
@@ -70,9 +81,10 @@ public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding
70
81
super (binding .getRoot ());
71
82
this .binding = binding ;
72
83
84
+ itemView .setBackgroundTintList (ColorStateList .valueOf (filledCardViewBackgroundColor ));
85
+
73
86
binding .recentSearchQueryTextViewItemRecentSearchQuery .setTextColor (primaryTextColor );
74
- binding .recentSearchQueryTextViewItemRecentSearchQuery .setCompoundDrawablesWithIntrinsicBounds (historyIcon , null , null , null );
75
- binding .deleteButtonItemRecentSearchQuery .setIcon (deleteIcon );
87
+ binding .recentSearchQueryWhereTextViewItemRecentSearchQuery .setTextColor (secondaryTextColor );
76
88
77
89
if (activity .typeface != null ) {
78
90
binding .recentSearchQueryTextViewItemRecentSearchQuery .setTypeface (activity .typeface );
@@ -84,8 +96,9 @@ public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding
84
96
}
85
97
});
86
98
87
- binding . deleteButtonItemRecentSearchQuery . setOnClickListener (view -> {
99
+ itemView . setOnLongClickListener (view -> {
88
100
itemOnClickListener .onDelete (recentSearchQueries .get (getBindingAdapterPosition ()));
101
+ return true ;
89
102
});
90
103
}
91
104
}
0 commit comments