package com.example.prettywallpapers.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

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

import com.example.prettywallpapers.R;
import com.example.prettywallpapers.base.MySpace;
import com.example.prettywallpapers.list.PrettyCategory;
import com.example.prettywallpapers.myvalue.MyValues;
import com.example.prettywallpapers.prettyadapter.InfoAdapter;
import com.example.prettywallpapers.prettyadapter.SeeAllInFoAdapter;
import com.example.prettywallpapers.toponad.AdManager;

import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class PrettyCategoryListActivity extends AppCompatActivity {

    private TextView category_name;
    private RecyclerView recycle_name;
    private ImageView imageView_back;
    private PrettyCategory prettyCategoryall;
    private LinearLayout category_name_main;
    private List<PrettyCategory> prettyCategories;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pretty_category_list);
        //category_name = findViewById(R.id.category_name_main);
        category_name = findViewById(R.id.category_name);
        category_name.setTypeface(Typeface.createFromAsset(getAssets(),"myfront.ttf"));
        imageView_back = findViewById(R.id.image_back);
        imageView_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //showad(true);
                finish();
            }
        });
        recycle_name =findViewById(R.id.name_list_recycle);
        gotoGetData();
        setNameRecycleView();
    }

    private void showad(boolean b) {
        AdManager.showAD(PrettyCategoryListActivity.this, new Function1<Integer, Unit>() {
            @Override
            public Unit invoke(Integer integer) {
                if (integer == AdManager.type_no_cache || integer == AdManager.type_show_close || integer == AdManager.type_show_fail) {
                    if (b)
                        finish();
                }
                return null;
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        //showad(false);
    }

    private void gotoGetData() {
        Intent intent = getIntent();
        prettyCategoryall = (PrettyCategory)intent.getSerializableExtra(MyValues.PREETY_NAME);
        assert prettyCategoryall != null;
        category_name.setText(prettyCategoryall.getName());
    }

    private void setNameRecycleView() {
        MySpace mySpace = new MySpace(1,20,1);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this,2);
        recycle_name.setLayoutManager(gridLayoutManager);
        recycle_name.addItemDecoration(mySpace);
        SeeAllInFoAdapter seeAllInFoAdapter = new SeeAllInFoAdapter(prettyCategoryall.getList(),this);
        recycle_name.setAdapter(seeAllInFoAdapter);
    }
}