package com.ar.drawing.activity;

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

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

import com.ar.drawing.others.Utils;
import com.ar.drawing.MyDraw;
import com.ar.drawing.adapter.ListAdapter;
import com.ar.drawing.databinding.ActivityListBinding;

import java.util.List;

public class ListActivity extends AppCompatActivity {

    private ActivityListBinding preViewBinding;

    private String dirStr;


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

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



        onInitList();
        onInitClick();
    }

    private void onInitList() {

        List<String> list = Utils.fileExistsInAssets(this, dirStr);

        ListAdapter listAdapter = new ListAdapter(this, list);
        preViewBinding.recyclerview.setAdapter(listAdapter);
        preViewBinding.recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
    }

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




}