package com.trace.drawing.people.page;

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

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

import com.trace.drawing.people.databinding.PageViewAllBinding;
import com.trace.drawing.people.item.ViewAllItem;
import com.trace.drawing.people.max.MaxManager;
import com.trace.drawing.people.max.onAdAfterAction;
import com.trace.drawing.people.tools.App;
import com.trace.drawing.people.tools.Common;
import com.trace.drawing.people.tools.ItemSpace;

import java.util.List;

public class ViewAllPage extends AppCompatActivity {

    private PageViewAllBinding preViewBinding;

    private String dirStr;


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

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

        MaxManager.onLoadAd();

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

            }
        });
    }

    private void onInitList() {

        List<String> list = Common.fileExistsInAssets(this, dirStr);
        ItemSpace itemSpace = new ItemSpace(10, 10, 5);
        ViewAllItem viewAllItem = new ViewAllItem(this, list);
        preViewBinding.recyclerview.setAdapter(viewAllItem);
        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) {
                MaxManager.startShowMaxAd(ViewAllPage.this, new onAdAfterAction() {
                    @Override
                    public void onAction() {
                             finish();
                    }
                });
            }
        });
    }
}