package com.snap.wall.activity;

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

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

import com.snap.wall.adapter.OnItemclick;
import com.snap.wall.databinding.ActivityTabBinding;
import com.snap.wall.bean.Information;
import com.snap.wall.myitem.ItemTab;
import com.snap.wall.mytool.Comutils;
import com.snap.wall.mytool.Itemhelper;
import com.snap.wall.mytool.ObectManager;

import java.util.List;

public class TabActivity extends AppCompatActivity implements OnItemclick {
    private ActivityTabBinding vb;

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

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

    private void initList() {
        List<Information> 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);
        ItemTab itemList = new ItemTab(this, height,false);
        itemList.setDataInfo(data);
        itemList.setInfoWallpaperListener(this);
        vb.list.setAdapter(itemList);

    }

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