package com.apps.chillscreen.uiView;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import com.ad.toponlibrary.AdManager;
import com.ad.toponlibrary.onActionListener;
import com.apps.chillscreen.adapter.GirdAdapter;
import com.apps.chillscreen.bean.Picture;
import com.apps.chillscreen.databinding.ActivityGenerBinding;
import com.apps.chillscreen.listener.CardClickListener;
import com.apps.chillscreen.tool.PictureManager;

import java.util.List;

public class GeneraActivity extends AppCompatActivity implements CardClickListener {
    ActivityGenerBinding binding;
    static String name="name";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivityGenerBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        AdManager.loadAllAd();
        init();

        AdManager.showTopOn(this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });
    }
    private void init(){
        name = getIntent().getStringExtra(name);
        List<Picture> pictures = PictureManager.queryEachGenera(name);
        GirdAdapter adapter=new GirdAdapter();
        adapter.setPictureList(pictures);
        adapter.setClickListener(this);
        GridLayoutManager gridLayoutManager=new GridLayoutManager(this,3);
        binding.list.setLayoutManager(gridLayoutManager);
        binding.list.setAdapter(adapter);
        binding.name.setText(name);
        binding.imageBack.setOnClickListener(v -> finish());
    }

    @Override
    public void onDetailClick(Picture picture) {
        Intent intent=new Intent(this, ExtendedInfoActivity.class);
        intent.putExtra(ExtendedInfoActivity.pictureKey,picture);
        startActivity(intent);
    }
}