package com.study.sketch.learning.activity;

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

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

import com.ad.maxlibrary.MaxManager;
import com.ad.maxlibrary.onAdAfterAction;
import com.study.sketch.learning.SketchingApp;
import com.study.sketch.learning.databinding.ActivityAllInfoBinding;
import com.study.sketch.learning.item.AdapterAllInfo;
import com.study.sketch.learning.item.SpacingItemDecoration;
import com.study.sketch.learning.manager.Common;

import java.util.List;

public class ActivityAllInfo extends AppCompatActivity {

    private ActivityAllInfoBinding preViewBinding;

    private String dirStr;


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

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

        MaxManager.onLoadAd();

        onInitList();
        onInitClick();
        MaxManager.startShowMaxAd(this, new onAdAfterAction() {
            @Override
            public void onAction() {

            }
        });
    }

    private void onInitList() {

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

        AdapterAllInfo adapterAllInfo = new AdapterAllInfo(this, list);
        preViewBinding.recyclerview.setAdapter(adapterAllInfo);
        SpacingItemDecoration spacingItemDecoration = new SpacingItemDecoration(5, true);
        preViewBinding.recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
        preViewBinding.recyclerview.addItemDecoration(spacingItemDecoration);
    }

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




}