package com.house.wallpapers.myactivity;

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.house.wallpapers.adapter.OnItemclick;
import com.house.wallpapers.databinding.ActivityMyListBinding;
import com.house.wallpapers.mybean.Data;
import com.house.wallpapers.myitem.Itemlist;
import com.house.wallpapers.mytool.Comutils;
import com.house.wallpapers.mytool.Itemhelper;
import com.house.wallpapers.mytool.ObectManager;

import java.util.List;

public class MyListActivity extends AppCompatActivity implements OnItemclick {
    private ActivityMyListBinding vb;

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityMyListBinding.inflate(getLayoutInflater());
        setContentView(vb.getRoot());
        Comutils.initFull(this, false);
        categoryName = getIntent().getStringExtra(key_index);
        vb.name.setText(categoryName);
        AdManager.loadAllAd();
        AdManager.showTopOn(this, () -> {});
        initList();
        vb.imageviewBack.setOnClickListener(v -> finish());
    }

    private void initList() {
        List<Data> data = ObectManager.queryCategoryAll(categoryName);
        Itemhelper itemHelper = new Itemhelper(10, 10, 0);
//        StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        vb.list.addItemDecoration(itemHelper);
        vb.list.setLayoutManager(gridLayoutManager);
        int height = Comutils.dp2Px(180);
        Itemlist itemList = new Itemlist(this, height,false);
        itemList.setDataInfo(data);
        itemList.setInfoWallpaperListener(this);
        vb.list.setAdapter(itemList);

    }

    @Override
    public void onItemClickAction(Data info) {
        Intent intent = new Intent(this, MyWallpaperActivity.class);
        intent.putExtra(Comutils.key_info, info);
        startActivity(intent);
    }
}