package com.picture.ar.drawing.activity;

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

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

import com.ad.toponlibrary.AdManager;
import com.ad.toponlibrary.onActionListener;
import com.picture.ar.drawing.databinding.ActivityViewAllBinding;
import com.picture.ar.drawing.list.ViewAllList;
import com.picture.ar.drawing.utils.App;
import com.picture.ar.drawing.utils.ComUtils;
import com.picture.ar.drawing.utils.ItemSpace;

import java.util.List;

public class AllActivity extends AppCompatActivity {

    private ActivityViewAllBinding preViewBinding;

    private String dirStr;


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

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


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

            }
        });
        onInitList();
        onInitClick();
    }

    private void onInitList() {

        List<String> list = ComUtils.fileExistsInAssets(this, dirStr);
        ItemSpace itemSpace = new ItemSpace(10, 10, 5);
        ViewAllList viewAllList = new ViewAllList(this, list);
        preViewBinding.recyclerview.setAdapter(viewAllList);
        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(AllActivity.this, new onActionListener() {
                    @Override
                    public void onAction() {
                         finish();
                    }
                });
            }
        });
    }
}