package com.ar.drawing.ui;

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

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

import com.ar.drawing.MyDraw;
import com.ar.drawing.ad.AdManager;
import com.ar.drawing.ad.onActionListener;
import com.ar.drawing.adapter.ListAdapter;
import com.ar.drawing.databinding.ActivityItemBinding;
import com.ar.drawing.others.MyUtils;

import java.util.List;

public class ItemActivity extends AppCompatActivity {

    private ActivityItemBinding preViewBinding;

    private String dirStr;


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

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

            }
        });

        onInitList();
        onInitClick();
    }

    private void onInitList() {

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

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

    private void onInitClick() {
        preViewBinding.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AdManager.showTopOn(ItemActivity.this, new onActionListener() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
    }




}