Что нужно исправить чтобы базовая финальная стоимость package com.example.myapp_2.Data.cart;

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

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



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 List<OnCartChangedListener> listeners;

    private Cart() {
        items = new ArrayList<>();
        listeners = 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);
                notifyCartChanged();
                return;
            }
        }
        items.add(new CartItem(product, 1));
        notifyCartChanged();
    }

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

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

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

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

    public double getTotalPrice() {
        int totalPrice = 0;
        for (CartItem item : items) {
            totalPrice += item.getTotalPrice();
        }
        return totalPrice;
    }

    private void notifyCartChanged() {
        for (OnCartChangedListener listener : listeners) {
            listener.onCartChanged();
        }
    }

    public void addOnCartChangedListener(OnCartChangedListener listener) {
        listeners.add(listener);
    }

    public interface OnCartChangedListener {
        void onCartChanged();
    }



}
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();
    }
    public void clear() {
        items.clear();
        notifyDataSetChanged();
    }
}package com.example.myapp_2.Data.cart;

import android.Manifest;
import android.content.pm.PackageManager;
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.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp_2.R;

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 implements Cart.OnCartChangedListener {

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

    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);
        backButton = view.findViewById(R.id.back_button); // кнопка назад
        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();
        cart.addOnCartChangedListener(this);

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

            @Override
            public void onRemoveButtonClick(CartItem item) {
                cart.removeItem(item);
            }
        });

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

        updateTotalPrice();

        placeOrderButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Создание уведомления
                String orderPriceStr = getString(R.string.cart_item_total_price_2, cart.getTotalPrice());
                NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity(), "channel_id")
                        .setSmallIcon(R.drawable.baseline_fastfood_24)
                        .setContentTitle("Заказ оформлен")
                        .setContentText("Ваш заказ успешно оформлен"+ " "+ orderPriceStr+"!")
                        .setPriority(NotificationCompat.PRIORITY_DEFAULT);

                // Отображение уведомления (ТУТ КАКАЯ-ТО БОЙДА НА РОВЕРКУ РАЗРЕШЕНИЯ)
                NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
                if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }
                notificationManager.notify(1, builder.build());

                // Закрытие текущего экрана
                getActivity().onBackPressed();

                // Очистка списка заказов
                adapter.clear();
            }
        });
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().onBackPressed(); // вызов метода возврата на предыдущий экран
            }
        });

        return view;
    }

    private void updateTotalPrice() {
        double totalPrice = cart.getTotalPrice();

        if (getContext() != null) {
        totalPriceTextView.setText(getString(R.string.cart_item_total_price, totalPrice));
    }
    }

    @Override
    public void onCartChanged() {
        adapter.setItems(cart.getItems());
        updateTotalPrice();
    }
}
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);
    }
}
 была целочисленной :