package com.ar.sketch.paint.drawing.act;

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

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

import com.ar.sketch.paint.drawing.ad.MaxManager;
import com.ar.sketch.paint.drawing.ad.onAdAfterAction;
import com.ar.sketch.paint.drawing.adapter.RecyclerList;
import com.ar.sketch.paint.drawing.databinding.PageItemBinding;
import com.ar.sketch.paint.drawing.tool.ItemDec;
import com.ar.sketch.paint.drawing.tool.MyArApp;
import com.ar.sketch.paint.drawing.tool.Utils;

import java.util.List;

public class PageList extends AppCompatActivity {

    private PageItemBinding preViewBinding;

    private String dirStr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MaxManager.onLoadAd();
        preViewBinding = PageItemBinding.inflate(getLayoutInflater());
        setContentView(preViewBinding.getRoot());
        Utils.setStatusBarTextColor(this, true);
        dirStr = getIntent().getStringExtra(MyArApp.Key_ViewDir);
        preViewBinding.categoryName.setText(dirStr.substring(dirStr.lastIndexOf("_") + 1));

        MaxManager.startShowMaxAd(PageList.this, new onAdAfterAction() {
            @Override
            public void onAction() {

            }
        });

        onInitList();
        onInitClick();
    }

    private void onInitList() {

        List<String> list = Utils.fileExistsInAssets(this, dirStr);
        ItemDec itemDec = new ItemDec(10, 10, 5);
        RecyclerList recyclerList = new RecyclerList(this, list);
        preViewBinding.recyclerview.setAdapter(recyclerList);
        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) {

                MaxManager.startShowMaxAd(PageList.this, new onAdAfterAction() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
    }




}