package com.sketch.art.trace.activity;

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

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

import com.sketch.art.trace.adapter.AdapterAll;
import com.sketch.art.trace.databinding.ActivityViewAllLayoutBinding;
import com.sketch.art.trace.tools.App;
import com.sketch.art.trace.tools.ComManager;
import com.sketch.art.trace.tools.ItemDec;

import java.util.List;

public class CategoryAllActivity extends AppCompatActivity {

    private ActivityViewAllLayoutBinding preViewBinding;

    private String dirStr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        preViewBinding = ActivityViewAllLayoutBinding.inflate(getLayoutInflater());
        setContentView(preViewBinding.getRoot());
        ComManager.setStatusBarTextColor(this, true);
        dirStr = getIntent().getStringExtra(App.Key_ViewDir);
        preViewBinding.categoryName.setText(dirStr.substring(dirStr.lastIndexOf("_") + 1));



        onInitList();
        onInitClick();
    }

    private void onInitList() {

        List<String> list = ComManager.fileExistsInAssets(this, dirStr);
        ItemDec itemDec = new ItemDec(10, 10, 5);
        AdapterAll adapterAll = new AdapterAll(this, list);
        preViewBinding.recyclerview.setAdapter(adapterAll);
        preViewBinding.recyclerview.addItemDecoration(itemDec);
        preViewBinding.recyclerview.setLayoutManager(new GridLayoutManager(this, 2));
    }

    private void onInitClick() {
        preViewBinding.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}