@@ -39,30 +39,34 @@ public FolderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTy
3939
4040 @ Override
4141 public void onBindViewHolder (@ NonNull FolderViewHolder holder , int position ) {
42+ Folder folder = list .get (position );
4243
43- holder .binding .tvName .setText (list .get (position ).getName ());
44- if (list .get (position ).getId () != 1 ) {
45- int count = RoomDB .getInstance (context ).mainDAO ().getNotesCount (list .get (position ).getId ());
46- holder .binding .tvCount .setText (String .valueOf (count ));
47- } else {
48- int count = RoomDB .getInstance (context ).mainDAO ().getNotesCount ();
49- holder .binding .tvCount .setText (String .valueOf (count ));
50- }
51- if (list .get (position ).isSelected ()) {
44+ holder .binding .tvName .setText (folder .getName ()); // Change here
45+ int count = folder .getId () != 1 ?
46+ RoomDB .getInstance (context ).mainDAO ().getNotesCount (folder .getId ()) :
47+ RoomDB .getInstance (context ).mainDAO ().getNotesCount ();
48+ holder .binding .tvCount .setText (String .valueOf (count ));
49+
50+ if (folder .isSelected ()) {
5251 holder .binding .ivCurrentIcon .setVisibility (View .VISIBLE );
5352 holder .binding .tvName .setTextColor (ContextCompat .getColor (context , R .color .white ));
5453 holder .binding .tvCount .setTextColor (ContextCompat .getColor (context , R .color .white ));
5554 holder .binding .card .setStrokeWidth (1 );
56-
5755 } else {
5856 holder .binding .tvName .setTextColor (ContextCompat .getColor (context , R .color .grey1 ));
5957 holder .binding .tvCount .setTextColor (ContextCompat .getColor (context , R .color .grey1 ));
6058 holder .binding .ivCurrentIcon .setVisibility (View .INVISIBLE );
6159 holder .binding .card .setStrokeWidth (0 );
62-
6360 }
6461
65- holder .binding .card .setOnClickListener (v -> listener .onClick (list .get (position )));
62+ holder .binding .card .setOnClickListener (v -> listener .onClick (folder ));
63+
64+ // Handle delete button click
65+ holder .binding .deletebutton .setOnClickListener (v -> {
66+ RoomDB .getInstance (context ).mainDAO ().deleteFolder (folder );
67+ list .remove (position );
68+ notifyItemRemoved (position );
69+ });
6670 }
6771
6872 public void setList (List <Folder > list ) {
@@ -83,11 +87,8 @@ class FolderViewHolder extends RecyclerView.ViewHolder {
8387
8488 RvItemFolderBinding binding ;
8589
86- public FolderViewHolder (@ NonNull RvItemFolderBinding binding ) {
90+ public FolderViewHolder (@ NonNull RvItemFolderBinding binding ) { // Change here
8791 super (binding .getRoot ());
88-
8992 this .binding = binding ;
90-
91-
9293 }
9394}
0 commit comments