У меня есть корзину, и она уже хорошо работает в Firstfragmetn , я хочу чтобы эта же корзина работал в SecondFragmetn , но уже с товарами только их этого фрагмента что нужно изменить или добавить напиши весь небходимый код , который нужно добавить к моему :package com.example.myapp_2.Data.cart;

import com.example.myapp_2.Data.List_1.Product;

import java.util.ArrayList;
import java.util.List;

public class Cart {
    private static Cart instance;

    private List<CartItem> items;

    private Cart() {
        items = new ArrayList<>();
    }

    public static Cart getInstance() {
        if (instance == null) {
            instance = new Cart();
        }
        return instance;
    }

    public void addItem(Product product) {
        for (CartItem item : items) {
            if (item.getProduct().equals(product)) {
                item.setQuantity(item.getQuantity() + 1);
                return;
            }
        }
        items.add(new CartItem(product, 1));
    }

    public void updateItem(CartItem item, int newQuantity) {
        if (newQuantity <= 0) {
            removeItem(item);
        } else {
            item.setQuantity(newQuantity);
        }
    }

    public void removeItem(CartItem item) {
        items.remove(item);
    }

    public List<CartItem> getItems() {
        return items;
    }

    public void clear() {
        items.clear();
    }

    public double getTotalPrice() {
        double totalPrice = 0;
        for (CartItem item : items) {
            totalPrice += item.getTotalPrice();
        }
        return totalPrice;
    }
}
package com.example.myapp_2.Data.cart;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp_2.R;

import java.util.List;

public class CartAdapter extends RecyclerView.Adapter<CartItemViewHolder> {

    private List<CartItem> items;
    private OnCartItemListener listener;

    public CartAdapter(List<CartItem> items, OnCartItemListener listener) {
        this.items = items;
        this.listener = listener;
    }

    @Override
    public CartItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cart, parent, false);
        return new CartItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CartItemViewHolder holder, int position) {
        CartItem item = items.get(position);
        holder.bind(item, listener);
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
        notifyDataSetChanged();
    }
}package com.example.myapp_2.Data.cart;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp_2.R;

public class CartFragment extends Fragment {

    private TextView totalPriceTextView;
    private Button placeOrderButton;
    private RecyclerView recyclerView;

    private CartAdapter adapter;
    private Cart cart;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_cart, container, false);

// Инициализируем UI и получаем объект Cart из синглтона
        totalPriceTextView = view.findViewById(R.id.total_price_text_view);
        placeOrderButton = view.findViewById(R.id.place_order_button);
        recyclerView = view.findViewById(R.id.cart_recycler_view);

        cart = Cart.getInstance();

        adapter = new CartAdapter(cart.getItems(), new OnCartItemListener() {
            @Override
            public void onQuantityChanged(CartItem item, int newQuantity) {
                cart.updateItem(item, newQuantity);
                updateTotalPrice();
            }

            @Override
            public void onRemoveButtonClick(CartItem item) {
                cart.removeItem(item);
                adapter.setItems(cart.getItems());
                updateTotalPrice();
            }
        });

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        updateTotalPrice();

        placeOrderButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(getActivity(),"Опять работа???",Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }

    private void placeOrder() {
// Здесь должен быть код для оформления заказа
    }

    private void updateTotalPrice() {
        double totalPrice = cart.getTotalPrice();
        totalPriceTextView.setText(getString(R.string.cart_item_total_price, totalPrice));
    }
}package com.example.myapp_2.Data.cart;

import com.example.myapp_2.Data.List_1.Product;

public class CartItem {
    private Product product; // сам товар
    private int quantity; // количество

    public CartItem(Product product, int quantity) {
        this.product = product;
        this.quantity = quantity;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public double getTotalPrice() {
        return product.getPrice() * quantity;
    }
}

package com.example.myapp_2.Data.cart;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp_2.Data.List_1.Product;
import com.example.myapp_2.R;

public  class CartItemViewHolder extends RecyclerView.ViewHolder {

    private ImageView productImageView;
    private TextView productNameTextView;
    private TextView productPriceTextView;
    private TextView productTotalPriceTextView;
    private TextView productQuantityTextView;
    private Button decreaseButton;
    private Button increaseButton;
    private Button removeButton;
    private int quantity;

    public CartItemViewHolder(@NonNull View itemView) {
        super(itemView);

        productImageView = itemView.findViewById(R.id.cart_item_image_view);
        productNameTextView = itemView.findViewById(R.id.cart_item_name_text_view);
        productPriceTextView = itemView.findViewById(R.id.cart_item_price_text_view);
        productTotalPriceTextView = itemView.findViewById(R.id.cart_item_total_price_text_view);
        productQuantityTextView = itemView.findViewById(R.id.cart_item_quantity_text_view);
        decreaseButton = itemView.findViewById(R.id.cart_item_decrease_button);
        increaseButton = itemView.findViewById(R.id.cart_item_increase_button);
        removeButton = itemView.findViewById(R.id.cart_item_remove_button);
    }

    public void bind(CartItem item, OnCartItemListener listener) {
        Product product = item.getProduct();
        quantity = item.getQuantity();

        productImageView.setImageResource(product.getImageResource());
        productNameTextView.setText(product.getName());
        productPriceTextView.setText(itemView.getContext().getString(R.string.product_price, product.getPrice()));
        productTotalPriceTextView.setText(itemView.getContext().getString(R.string.cart_item_total_price, item.getTotalPrice()));
        productQuantityTextView.setText(String.valueOf(quantity));

        decreaseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                quantity -= 1;
                productQuantityTextView.setText(String.valueOf(quantity));
                listener.onQuantityChanged(item, quantity);
            }
        });

        increaseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                quantity += 1;
                productQuantityTextView.setText(String.valueOf(quantity));
                listener.onQuantityChanged(item, quantity);
            }
        });

        removeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onRemoveButtonClick(item);
            }
        });
    }
}
package com.example.myapp_2.Data.cart;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class ItemSpacingDecoration extends RecyclerView.ItemDecoration {

    private int mSpacing; // промежуток между элементами

    public ItemSpacingDecoration(int spacing) {
        this.mSpacing = spacing;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);

// Добавляем отступ снизу элемента
        outRect.bottom = mSpacing;
    }
}package com.example.myapp_2.Data.cart;

public interface OnCartItemListener {
    void onQuantityChanged(CartItem item, int newQuantity);//вызывается при изменении количества товара в корзине
    void onRemoveButtonClick(CartItem item);//вызывается при нажатии на кнопку удаления товара из корзины
}
package com.example.myapp_2.Data.cart;

import com.example.myapp_2.Data.List_1.Product;

public interface OnProductClickListener {
    void onAddToCartClick(Product product);
}
package com.example.myapp_2.Data.cart;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp_2.Data.List_1.Product;
import com.example.myapp_2.Data.List_1.ProductAdapter;
import com.example.myapp_2.R;

import java.util.List;

public class ProductsFragment extends Fragment {
    private List<Product> productList;
    private RecyclerView recyclerView;
    private ProductAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_products, container, false);
        adapter = new ProductAdapter(productList, new OnProductClickListener() {
            @Override
            public void onAddToCartClick(Product product) {
                addToCart(product);
            }
        });

// Здесь инициализируем список товаров и recyclerView

        adapter = new ProductAdapter(productList, new OnProductClickListener() {
            @Override
            public void onAddToCartClick(Product product) {
                addToCart(product);
            }
        }); // передаём метод добавления товара в корзину

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        return view;
    }

    private void addToCart(Product product) {
// метод добавления товара в корзину
        Cart cart = Cart.getInstance();
        cart.addItem(product);
    }
}