88
99import static it .niedermann .owncloud .notes .shared .util .NoteUtil .getFontSizeFromPreferences ;
1010
11+ import android .annotation .SuppressLint ;
1112import android .content .Context ;
1213import android .text .TextUtils ;
1314import android .view .LayoutInflater ;
15+ import android .view .View ;
1416import android .view .ViewGroup ;
17+ import android .widget .ImageView ;
1518
1619import androidx .annotation .ColorInt ;
1720import androidx .annotation .IntRange ;
2326import androidx .recyclerview .selection .SelectionTracker ;
2427import androidx .recyclerview .widget .RecyclerView ;
2528
29+ import com .nextcloud .android .common .ui .theme .utils .ColorRole ;
30+
2631import java .util .ArrayList ;
2732import java .util .List ;
2833
2934import it .niedermann .owncloud .notes .R ;
3035import it .niedermann .owncloud .notes .branding .Branded ;
36+ import it .niedermann .owncloud .notes .branding .BrandingUtil ;
3137import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridBinding ;
3238import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemGridOnlyTitleBinding ;
3339import it .niedermann .owncloud .notes .databinding .ItemNotesListNoteItemWithExcerptBinding ;
@@ -66,6 +72,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
6672 @ Nullable
6773 private Integer swipedPosition ;
6874
75+ private boolean isMultiSelect = false ;
76+
6977 public <T extends Context & NoteClickListener > ItemAdapter (@ NonNull T context , boolean gridView ) {
7078 this .noteClickListener = context ;
7179 this .gridView = gridView ;
@@ -104,13 +112,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
104112 if (gridView ) {
105113 switch (viewType ) {
106114 case TYPE_SECTION -> {
107- return new SectionViewHolder (ItemNotesListSectionItemBinding .inflate (inflater ));
115+ ItemNotesListSectionItemBinding binding = ItemNotesListSectionItemBinding .inflate (inflater );
116+ BrandingUtil .of (color , parent .getContext ()).platform .colorTextView (binding .sectionTitle );
117+ return new SectionViewHolder (binding );
108118 }
109119 case TYPE_NOTE_ONLY_TITLE -> {
110- return new NoteViewGridHolderOnlyTitle (ItemNotesListNoteItemGridOnlyTitleBinding .inflate (inflater , parent , false ), noteClickListener , monospace , fontSize );
120+ ItemNotesListNoteItemGridOnlyTitleBinding binding = ItemNotesListNoteItemGridOnlyTitleBinding .inflate (inflater , parent , false );
121+ BrandingUtil .of (color , parent .getContext ()).notes .themeCard (binding .card );
122+ return new NoteViewGridHolderOnlyTitle (binding , noteClickListener , monospace , fontSize );
111123 }
112124 case TYPE_NOTE_WITH_EXCERPT , TYPE_NOTE_WITHOUT_EXCERPT -> {
113- return new NoteViewGridHolder (ItemNotesListNoteItemGridBinding .inflate (inflater , parent , false ), noteClickListener , monospace , fontSize );
125+ ItemNotesListNoteItemGridBinding binding = ItemNotesListNoteItemGridBinding .inflate (inflater , parent , false );
126+ BrandingUtil .of (color , parent .getContext ()).notes .themeCard (binding .card );
127+ return new NoteViewGridHolder (binding , noteClickListener , monospace , fontSize );
114128 }
115129 default -> {
116130 throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -119,13 +133,19 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
119133 } else {
120134 switch (viewType ) {
121135 case TYPE_SECTION -> {
122- return new SectionViewHolder (ItemNotesListSectionItemBinding .inflate (inflater ));
136+ ItemNotesListSectionItemBinding binding = ItemNotesListSectionItemBinding .inflate (inflater );
137+ BrandingUtil .of (color , parent .getContext ()).platform .colorTextView (binding .sectionTitle );
138+ return new SectionViewHolder (binding );
123139 }
124140 case TYPE_NOTE_WITH_EXCERPT -> {
125- return new NoteViewHolderWithExcerpt (ItemNotesListNoteItemWithExcerptBinding .inflate (inflater , parent , false ), noteClickListener );
141+ ItemNotesListNoteItemWithExcerptBinding binding = ItemNotesListNoteItemWithExcerptBinding .inflate (inflater , parent , false );
142+ BrandingUtil .of (color , parent .getContext ()).notes .themeBackgroundItemView (binding .noteSwipeable );
143+ return new NoteViewHolderWithExcerpt (binding , noteClickListener );
126144 }
127145 case TYPE_NOTE_ONLY_TITLE , TYPE_NOTE_WITHOUT_EXCERPT -> {
128- return new NoteViewHolderWithoutExcerpt (ItemNotesListNoteItemWithoutExcerptBinding .inflate (inflater , parent , false ), noteClickListener );
146+ ItemNotesListNoteItemWithoutExcerptBinding binding = ItemNotesListNoteItemWithoutExcerptBinding .inflate (inflater , parent , false );
147+ BrandingUtil .of (color , parent .getContext ()).notes .themeBackgroundItemView (binding .noteSwipeable );
148+ return new NoteViewHolderWithoutExcerpt (binding , noteClickListener );
129149 }
130150 default -> {
131151 throw new IllegalArgumentException ("Not supported viewType: " + viewType );
@@ -149,17 +169,38 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
149169 switch (getItemViewType (position )) {
150170 case TYPE_SECTION ->
151171 ((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 );
172+ case TYPE_NOTE_WITH_EXCERPT , TYPE_NOTE_WITHOUT_EXCERPT , TYPE_NOTE_ONLY_TITLE -> {
173+ holder .itemView .findViewById (R .id .custom_checkbox ).setVisibility (tracker != null && tracker .hasSelection () ? View .VISIBLE : View .GONE );
174+ if (isSelected ) {
175+ holder .itemView .setBackgroundColor (ContextCompat .getColor (holder .itemView .getContext (), R .color .bg_highlighted ));
176+ ((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 ));
177+ } else {
178+ holder .itemView .setBackgroundColor (holder .itemView .getContext ().getColor (com .nextcloud .android .common .ui .R .color .bg_default ));
179+ ((ImageView ) holder .itemView .findViewById (R .id .custom_checkbox )).setImageResource (R .drawable .ic_checkbox_blank_outline );
180+ }
181+ holder .itemView .findViewById (R .id .custom_checkbox ).setVisibility (isMultiSelect ? View .VISIBLE : View .GONE );
182+ ((NoteViewHolder ) holder ).bind (isSelected , (Note ) itemList .get (position ), showCategory , color , searchQuery );
183+ }
156184 }
157185 }
158186
159187 public void setTracker (SelectionTracker <Long > tracker ) {
160188 this .tracker = tracker ;
161189 }
162190
191+ @ SuppressLint ("NotifyDataSetChanged" )
192+ public void setMultiSelect (boolean bool ) {
193+ if (isMultiSelect != bool ) {
194+ isMultiSelect = bool ;
195+ // endless loop incoming...
196+ //notifyDataSetChanged();
197+ }
198+ }
199+
200+ public boolean isMultiSelect () {
201+ return this .isMultiSelect ;
202+ }
203+
163204 public Item getItem (int notePosition ) {
164205 return itemList .get (notePosition );
165206 }
0 commit comments