8
8
9
9
import static it .niedermann .owncloud .notes .shared .util .NoteUtil .getFontSizeFromPreferences ;
10
10
11
+ import android .annotation .SuppressLint ;
11
12
import android .content .Context ;
13
+ import android .os .Handler ;
14
+ import android .os .Looper ;
12
15
import android .text .TextUtils ;
13
16
import android .view .LayoutInflater ;
17
+ import android .view .View ;
14
18
import android .view .ViewGroup ;
19
+ import android .widget .ImageView ;
15
20
16
21
import androidx .annotation .ColorInt ;
17
22
import androidx .annotation .IntRange ;
23
28
import androidx .recyclerview .selection .SelectionTracker ;
24
29
import androidx .recyclerview .widget .RecyclerView ;
25
30
31
+ import com .nextcloud .android .common .ui .theme .utils .ColorRole ;
32
+
26
33
import java .util .ArrayList ;
27
34
import java .util .List ;
28
35
29
36
import it .niedermann .owncloud .notes .R ;
30
37
import it .niedermann .owncloud .notes .branding .Branded ;
38
+ import it .niedermann .owncloud .notes .branding .BrandingUtil ;
31
39
import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridBinding ;
32
40
import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridOnlyTitleBinding ;
33
41
import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemWithExcerptBinding ;
@@ -66,6 +74,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
66
74
@ Nullable
67
75
private Integer swipedPosition ;
68
76
77
+ private boolean isMultiSelect = false ;
78
+
69
79
public <T extends Context & NoteClickListener > ItemAdapter (@ NonNull T context , boolean gridView ) {
70
80
this .noteClickListener = context ;
71
81
this .gridView = gridView ;
@@ -104,13 +114,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
104
114
if (gridView ) {
105
115
switch (viewType ) {
106
116
case TYPE_SECTION -> {
107
- return new SectionViewHolder (ItemNotesListSectionItemBinding .inflate (inflater ));
117
+ ItemNotesListSectionItemBinding binding = ItemNotesListSectionItemBinding .inflate (inflater );
118
+ BrandingUtil .of (color , parent .getContext ()).platform .colorTextView (binding .sectionTitle );
119
+ return new SectionViewHolder (binding );
108
120
}
109
121
case TYPE_NOTE_ONLY_TITLE -> {
110
- return new NoteViewGridHolderOnlyTitle (ItemNotesListNoteItemGridOnlyTitleBinding .inflate (inflater , parent , false ), noteClickListener , monospace , fontSize );
122
+ ItemNotesListNoteItemGridOnlyTitleBinding binding = ItemNotesListNoteItemGridOnlyTitleBinding .inflate (inflater , parent , false );
123
+ BrandingUtil .of (color , parent .getContext ()).notes .themeCard (binding .card );
124
+ return new NoteViewGridHolderOnlyTitle (binding , noteClickListener , monospace , fontSize );
111
125
}
112
126
case TYPE_NOTE_WITH_EXCERPT , TYPE_NOTE_WITHOUT_EXCERPT -> {
113
- return new NoteViewGridHolder (ItemNotesListNoteItemGridBinding .inflate (inflater , parent , false ), noteClickListener , monospace , fontSize );
127
+ ItemNotesListNoteItemGridBinding binding = ItemNotesListNoteItemGridBinding .inflate (inflater , parent , false );
128
+ BrandingUtil .of (color , parent .getContext ()).notes .themeCard (binding .card );
129
+ return new NoteViewGridHolder (binding , noteClickListener , monospace , fontSize );
114
130
}
115
131
default -> {
116
132
throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -119,13 +135,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
119
135
} else {
120
136
switch (viewType ) {
121
137
case TYPE_SECTION -> {
122
- return new SectionViewHolder (ItemNotesListSectionItemBinding .inflate (inflater ));
138
+ ItemNotesListSectionItemBinding binding = ItemNotesListSectionItemBinding .inflate (inflater );
139
+ BrandingUtil .of (color , parent .getContext ()).platform .colorTextView (binding .sectionTitle );
140
+ return new SectionViewHolder (binding );
123
141
}
124
142
case TYPE_NOTE_WITH_EXCERPT -> {
125
- return new NoteViewHolderWithExcerpt (ItemNotesListNoteItemWithExcerptBinding .inflate (inflater , parent , false ), noteClickListener );
143
+ ItemNotesListNoteItemWithExcerptBinding binding = ItemNotesListNoteItemWithExcerptBinding .inflate (inflater , parent , false );
144
+ BrandingUtil .of (color , parent .getContext ()).notes .themeBackgroundItemView (binding .noteSwipeable );
145
+ return new NoteViewHolderWithExcerpt (binding , noteClickListener );
126
146
}
127
147
case TYPE_NOTE_ONLY_TITLE , TYPE_NOTE_WITHOUT_EXCERPT -> {
128
- return new NoteViewHolderWithoutExcerpt (ItemNotesListNoteItemWithoutExcerptBinding .inflate (inflater , parent , false ), noteClickListener );
148
+ ItemNotesListNoteItemWithoutExcerptBinding binding = ItemNotesListNoteItemWithoutExcerptBinding .inflate (inflater , parent , false );
149
+ BrandingUtil .of (color , parent .getContext ()).notes .themeBackgroundItemView (binding .noteSwipeable );
150
+ return new NoteViewHolderWithoutExcerpt (binding , noteClickListener );
129
151
}
130
152
default -> {
131
153
throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -149,17 +171,37 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
149
171
switch (getItemViewType (position )) {
150
172
case TYPE_SECTION ->
151
173
((SectionViewHolder ) holder ).bind ((SectionItem ) itemList .get (position ));
152
- case TYPE_NOTE_WITH_EXCERPT ,
153
- TYPE_NOTE_WITHOUT_EXCERPT ,
154
- TYPE_NOTE_ONLY_TITLE ->
155
- ((NoteViewHolder ) holder ).bind (isSelected , (Note ) itemList .get (position ), showCategory , color , searchQuery );
174
+ case TYPE_NOTE_WITH_EXCERPT , TYPE_NOTE_WITHOUT_EXCERPT , TYPE_NOTE_ONLY_TITLE -> {
175
+ holder .itemView .findViewById (R .id .custom_checkbox ).setVisibility (tracker != null && tracker .hasSelection () ? View .VISIBLE : View .GONE );
176
+ if (isSelected ) {
177
+ holder .itemView .setBackgroundColor (ContextCompat .getColor (holder .itemView .getContext (), R .color .bg_highlighted ));
178
+ ((ImageView ) holder .itemView .findViewById (R .id .custom_checkbox )).setImageDrawable (BrandingUtil .getInstance (holder .itemView .getContext ()).platform .tintDrawable (holder .itemView .getContext (), R .drawable .ic_checkbox_marked , ColorRole .PRIMARY ));
179
+ } else {
180
+ holder .itemView .setBackgroundColor (holder .itemView .getContext ().getColor (com .nextcloud .android .common .ui .R .color .bg_default ));
181
+ ((ImageView ) holder .itemView .findViewById (R .id .custom_checkbox )).setImageResource (R .drawable .ic_checkbox_blank_outline );
182
+ }
183
+ holder .itemView .findViewById (R .id .custom_checkbox ).setVisibility (isMultiSelect ? View .VISIBLE : View .GONE );
184
+ ((NoteViewHolder ) holder ).bind (isSelected , (Note ) itemList .get (position ), showCategory , color , searchQuery );
185
+ }
156
186
}
157
187
}
158
188
159
189
public void setTracker (SelectionTracker <Long > tracker ) {
160
190
this .tracker = tracker ;
161
191
}
162
192
193
+ @ SuppressLint ("NotifyDataSetChanged" )
194
+ public void setMultiSelect (boolean bool ) {
195
+ if (isMultiSelect != bool ) {
196
+ isMultiSelect = bool ;
197
+ new Handler (Looper .getMainLooper ()).post (this ::notifyDataSetChanged );
198
+ }
199
+ }
200
+
201
+ public boolean isMultiSelect () {
202
+ return this .isMultiSelect ;
203
+ }
204
+
163
205
public Item getItem (int notePosition ) {
164
206
return itemList .get (notePosition );
165
207
}
0 commit comments