package com.example.fruitparty;


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.fruitparty.R;
import com.example.fruitparty.Category;
import com.example.fruitparty.Product;

import java.util.Objects;

public class SetDetailFragment extends Fragment {
    private View view;
    private ImageView imageView;
    private TextView nameText, priceText;

    @SuppressLint("SetTextI18n")
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.detail_content, container, false);
        if (view != null) {
            init();
        }
        Category categoryActivity = (Category) getActivity();
        categoryActivity.setOnChangeListener(product -> {
            imageView.setBackgroundResource(product.getImageUrlId());
            nameText.setText(product.getProductName());
            priceText.setText(product.getCharacterStory());
        });
   /*     Objects.requireNonNull(categoryActivity).setOnChangeListener(product -> {
            Log.i("sss", "onCreateView: " + product.getProductName());
            imageView.setBackgroundResource(product.getImageUrlId());
            nameText.setText(product.getProductName());
            priceText.setText(product.getProductPrice().toString());
        });

    */
        return view;
    }

    /**
     * 内容组件初始化
     */
    private void init() {
        imageView = view.findViewById(R.id.produce_image);
        nameText = view.findViewById(R.id.produce_name);
        priceText = view.findViewById(R.id.produce_price);
    }

}
