package com.ar.sketch.drawing.activity;

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

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

import com.ar.sketch.drawing.MyApp;
import com.ar.sketch.drawing.ad.AdManager;
import com.ar.sketch.drawing.ad.onActionListener;
import com.ar.sketch.drawing.myadapter.AdapterList;
import com.ar.sketch.drawing.databinding.ActivityItemBinding;
import com.ar.sketch.drawing.utils.MyUtils;

import java.util.List;

public class ActivityList extends AppCompatActivity {

    private ActivityItemBinding preViewBinding;

    private String dirStr;


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

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


        onInitList();
        onInitClick();
        AdManager.showTopOn(ActivityList.this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });
    }

    private void onInitList() {

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

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

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

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

            }
        });
    }




}