package com.phone.wall.paper.view;

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

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

import com.ad.toponlibrary.AdManager;
import com.ad.toponlibrary.onActionListener;
import com.phone.wall.paper.adapter.AllAda;
import com.phone.wall.paper.data.DataBean;
import com.phone.wall.paper.databinding.UiAllListBinding;
import com.phone.wall.paper.listener.OnClick;
import com.phone.wall.paper.tools.ListSpace;
import com.phone.wall.paper.tools.RoomManager;
import com.phone.wall.paper.tools.Utils;

import java.util.List;

public class AllList extends AppCompatActivity implements OnClick {
    private UiAllListBinding vb;

    private String categoryName;
    public static final String key_index = "index";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = UiAllListBinding.inflate(getLayoutInflater());
        setContentView(vb.getRoot());
        Utils.initFull(this, false);
        categoryName = getIntent().getStringExtra(key_index);
        vb.name.setText(categoryName);
        initList();
        AdManager.loadAllAd();
        vb.imageviewBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AdManager.showTopOn(AllList.this, new onActionListener() {
                    @Override
                    public void onAction() {
                           finish();
                    }
                });
            }
        });
    }

    private void initList() {
        List<DataBean> data = RoomManager.queryCategoryAll(categoryName);
        ListSpace listSpace = new ListSpace(10, 10, 0);
//        StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        vb.list.addItemDecoration(listSpace);
        vb.list.setLayoutManager(gridLayoutManager);
        int height = Utils.dp2Px(180);
        AllAda allAda = new AllAda(this, height);
        allAda.setDataInfo(data);
        allAda.setInfoWallpaperListener(this);
        vb.list.setAdapter(allAda);

    }

    @Override
    public void onItemClickAction(DataBean info) {
        Intent intent = new Intent(this, SetWall.class);
        intent.putExtra(Utils.key_info, info);
        startActivity(intent);
    }
}