package com.paint.ar.drawing.activity;

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

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

import com.paint.ar.drawing.MyApp;
import com.paint.ar.drawing.adapter.AllAdapter;
import com.paint.ar.drawing.databinding.ActivityAllBinding;
import com.paint.ar.drawing.helper.Utils;
import com.paint.ar.drawing.topon.AdManager;
import com.paint.ar.drawing.topon.onActionListener;

import java.util.List;

public class AllActivity extends AppCompatActivity {

    private ActivityAllBinding preViewBinding;

    private String dirStr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AdManager.loadAllAd();
        preViewBinding = ActivityAllBinding.inflate(getLayoutInflater());
        setContentView(preViewBinding.getRoot());
        Utils.setStatusBarTextColor(this, true);
        dirStr = getIntent().getStringExtra(MyApp.Key_ViewDir);
        preViewBinding.categoryName.setText(dirStr.substring(dirStr.lastIndexOf("_") + 1));



        onInitList();
        onInitClick();
    }

    private void onInitList() {

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

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

    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();
                    }
                });

            }
        });
    }
}