package com.ar.drawing.assistant.paint.ui_activity;

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

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

import com.ar.drawing.assistant.paint.ad.AdManager;
import com.ar.drawing.assistant.paint.ad.onActionListener;
import com.ar.drawing.assistant.paint.databinding.ActItemBinding;
import com.ar.drawing.assistant.paint.tooladapter.AdList;
import com.ar.drawing.assistant.paint.utils.Common;
import com.ar.drawing.assistant.paint.utils.ItemSpace;
import com.ar.drawing.assistant.paint.utils.MyApp;

import java.util.List;

public class ActList extends AppCompatActivity {

    private ActItemBinding preViewBinding;

    private String dirStr;


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

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

        AdManager.loadAllAd();
        AdManager.showTopOn(ActList.this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });

        onInitList();
        onInitClick();
    }

    private void onInitList() {

        List<String> list = Common.fileExistsInAssets(this, dirStr);
        ItemSpace itemSpace = new ItemSpace(10, 10, 5);
        AdList adList = new AdList(this, list);
        preViewBinding.recyclerview.setAdapter(adList);
        preViewBinding.recyclerview.addItemDecoration(itemSpace);
        preViewBinding.recyclerview.setLayoutManager(new GridLayoutManager(this, 2));
    }

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

                AdManager.showTopOn(ActList.this, new onActionListener() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
    }




}