package com.prank.funny.pranks.pager;

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

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

import com.prank.funny.pranks.adapter.AdChild;
import com.prank.funny.pranks.bean.Info;
import com.prank.funny.pranks.bean.MyBean;
import com.prank.funny.pranks.databinding.LayoutInfoBinding;
import com.prank.funny.pranks.listener.PranksListener;
import com.prank.funny.pranks.max.MaxManager;
import com.prank.funny.pranks.max.onAdAfterAction;
import com.prank.funny.pranks.tools.Common;
import com.prank.funny.pranks.tools.ItemSpace;

public class ActivityClass extends AppCompatActivity implements View.OnClickListener, PranksListener {

    private LayoutInfoBinding activityListBinding;
    private MyBean data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Common.setStatusBarTextColor(this,true);
        activityListBinding = LayoutInfoBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (MyBean) getIntent().getSerializableExtra(Common.KEY_LIST_DATA);
        colorIndex =  getIntent().getIntExtra(Common.KEY_LIST_COLOR_POS,0);
        activityListBinding.categoryName.setText(data.getName());
        MaxManager.onLoadAd();
        onList();
        activityListBinding.back.setOnClickListener(this);
        MaxManager.startShowMaxAd(ActivityClass.this, new onAdAfterAction() {
            @Override
            public void onAction() {

            }
        });
    }

    private void onList() {
        ItemSpace itemHelper = new ItemSpace(10, 10, 0);
        activityListBinding.listRecycler.addItemDecoration(itemHelper);
        activityListBinding.listRecycler.setLayoutManager(new GridLayoutManager(this, 3));
        AdChild adChild = new AdChild(this, data.getInfoList(),0,this);
        activityListBinding.listRecycler.setAdapter(adChild);
        adChild.setColorIndex(colorIndex);
    }

    @Override
    public void onClick(View v) {
        if(v.equals(activityListBinding.back)){


            MaxManager.startShowMaxAd(ActivityClass.this, new onAdAfterAction() {
                @Override
                public void onAction() {
                    finish();
                }
            });

        }

    }

    @Override
    public void onClickSoundsListener(Info data) {
        Intent intent = new Intent(this, ActivityPlayPranks.class);
        intent.putExtra(Common.KEY_PLAY_DATA, data);
        intent.putExtra(Common.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}