package com.example.orangesale_02;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.orangesale_02.R;
import com.example.orangesale_02.CategoryActivity;

import java.util.Objects;

public class SetDetailFragment extends Fragment {
    private View view;

    private ImageView imageView;
    private ImageView imageView2;
    private TextView nameText, priceText,contentText;
    private TextView nameText2, priceText2,contentText2;

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


        if (view != null) {
            init();
        }
        CategoryActivity categoryActivity = (CategoryActivity) getActivity();
        Objects.requireNonNull(categoryActivity).setOnChangeListener(product -> {
            Log.i("sss", "onCreateView: " + product.getProductName());
            imageView.setBackgroundResource(product.getImageUrlId());
            nameText.setText(product.getProductName());
            priceText.setText(product.getProductPrice().toString());
            contentText.setText(product.getProductContent());
            imageView2.setBackgroundResource(product.getImageUrlId());
            nameText2.setText(product.getProductName());
            priceText2.setText(product.getProductPrice().toString());
            contentText2.setText(product.getProductContent());
        });
        return view;

    }

    /**
     * 内容组件初始化
     */
    private void init() {
        imageView = view.findViewById(R.id.category_product_image);
        nameText = view.findViewById(R.id.category_product_name);
        priceText = view.findViewById(R.id.category_product_price);
        contentText = view.findViewById(R.id.category_product_content);
        imageView2 = view.findViewById(R.id.category_product_image1);
        nameText2 = view.findViewById(R.id.category_product_name1);
        priceText2 = view.findViewById(R.id.category_product_price1);
        contentText2 = view.findViewById(R.id.category_product_content1);
    }

}
