package com.app.sounds.prank.party.act;

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

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

import com.app.sounds.prank.party.bean.Info;
import com.app.sounds.prank.party.bean.MyBean;
import com.app.sounds.prank.party.common.Utils;
import com.app.sounds.prank.party.common.ItemSpace;
import com.app.sounds.prank.party.databinding.InfoActivityBinding;
import com.app.sounds.prank.party.list.AdaInfo;
import com.app.sounds.prank.party.mylistener.ClickPrankListener;
import com.app.sounds.prank.party.top.AdManager;
import com.app.sounds.prank.party.top.onActionListener;

public class InfoActivity extends AppCompatActivity implements View.OnClickListener, ClickPrankListener {

    private InfoActivityBinding activityListBinding;
    private MyBean data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.setStatusBarTextColor(this,true);
        activityListBinding = InfoActivityBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (MyBean) getIntent().getSerializableExtra(Utils.KEY_LIST_DATA);
        colorIndex =  getIntent().getIntExtra(Utils.KEY_LIST_COLOR_POS,0);
        activityListBinding.categoryName.setText(data.getName());
        onList();
        activityListBinding.back.setOnClickListener(this);
        AdManager.loadAllAd();
        AdManager.showTopOn(InfoActivity.this, new onActionListener() {
            @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));
        AdaInfo adaInfo = new AdaInfo(this, data.getInfoList(),0,this);
        activityListBinding.listRecycler.setAdapter(adaInfo);
        adaInfo.setColorIndex(colorIndex);
    }

    @Override
    public void onClick(View v) {
        if(v.equals(activityListBinding.back)){
            AdManager.showTopOn(InfoActivity.this, new onActionListener() {
                @Override
                public void onAction() {
                    finish();
                }
            });

        }

    }

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