88
99import static it .niedermann .owncloud .notes .shared .util .NoteUtil .getFontSizeFromPreferences ;
1010
11+ import android .annotation .SuppressLint ;
1112import android .content .Context ;
13+ import android .os .Handler ;
14+ import android .os .Looper ;
1215import android .text .TextUtils ;
1316import android .view .LayoutInflater ;
17+ import android .view .View ;
1418import android .view .ViewGroup ;
19+ import android .widget .ImageView ;
1520
1621import androidx .annotation .ColorInt ;
1722import androidx .annotation .IntRange ;
2328import androidx .recyclerview .selection .SelectionTracker ;
2429import androidx .recyclerview .widget .RecyclerView ;
2530
31+ import com .nextcloud .android .common .ui .theme .utils .ColorRole ;
32+
2633import java .util .ArrayList ;
2734import java .util .List ;
2835
2936import it .niedermann .owncloud .notes .R ;
3037import it .niedermann .owncloud .notes .branding .Branded ;
38+ import it .niedermann .owncloud .notes .branding .BrandingUtil ;
3139import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridBinding ;
3240import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridOnlyTitleBinding ;
3341import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemWithExcerptBinding ;
@@ -66,6 +74,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
6674 @ Nullable
6775 private Integer swipedPosition ;
6876
77+ private boolean isMultiSelect = false ;
78+
6979 public <T extends Context & NoteClickListener > ItemAdapter (@ NonNull T context , boolean gridView ) {
7080 this .noteClickListener = context ;
7181 this .gridView = gridView ;
@@ -104,13 +114,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
104114 if (gridView ) {
105115 switch (viewType ) {
106116 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 );
108120 }
109121 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 );
111125 }
112126 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 );
114130 }
115131 default -> {
116132 throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -119,13 +135,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
119135 } else {
120136 switch (viewType ) {
121137 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 );
123141 }
124142 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 );
126146 }
127147 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 );
129151 }
130152 default -> {
131153 throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -149,17 +171,37 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
149171 switch (getItemViewType (position )) {
150172 case TYPE_SECTION ->
151173 ((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+ }
156186 }
157187 }
158188
159189 public void setTracker (SelectionTracker <Long > tracker ) {
160190 this .tracker = tracker ;
161191 }
162192
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+
163205 public Item getItem (int notePosition ) {
164206 return itemList .get (notePosition );
165207 }
0 commit comments