package com.free.life.wallpaper.ui;

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

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

import com.free.life.wallpaper.MyWallpaper;
import com.free.life.wallpaper.recycler.AdapterThumb;
import com.free.life.wallpaper.databinding.ActivityClassBinding;
import com.free.life.wallpaper.bean.Category;
import com.free.life.wallpaper.bean.Data;
import com.free.life.wallpaper.mylistener.ItemClickListener;
import com.free.life.wallpaper.utils.CommonUtils;
import com.free.life.wallpaper.utils.RecyclerSpace;

import java.util.List;

public class ClassActivity extends AppCompatActivity implements ItemClickListener {
    private ActivityClassBinding vb;
    private Category category;
    public static final String key_index = "index";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityClassBinding.inflate(getLayoutInflater());
        setContentView(vb.getRoot());
        CommonUtils.initFull(this, false);
        int intExtra = getIntent().getIntExtra(key_index, 0);
        List<Category> data = MyWallpaper.getData();
        if (intExtra < data.size()) {
            category = data.get(intExtra);
            vb.name.setText(category.getClassName());
        }
        Log.d(MyWallpaper.TAG, "----------setDataInfo  mIndex=" + intExtra);
        initList();
        vb.imageviewBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initList() {
        RecyclerSpace recyclerSpace = new RecyclerSpace(10, 10, 0);
//        StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        vb.list.addItemDecoration(recyclerSpace);
        vb.list.setLayoutManager(gridLayoutManager);
        int height = CommonUtils.dp2Px(180);
        AdapterThumb adapterThumb = new AdapterThumb(this, height);
        adapterThumb.setDataInfo(category.getDataList());
        adapterThumb.setInfoWallpaperListener(this);
        vb.list.setAdapter(adapterThumb);

    }

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