package com.example.wallpapermagazine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

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

import com.example.wallpapermagazine.action.InfoListWallPaperListener;
import com.example.wallpapermagazine.action.onActionListener;
import com.example.wallpapermagazine.recylcle.CataItemAdapter;

public class CataItemActivity extends AppCompatActivity implements InfoListWallPaperListener{

    private RecyclerView recyclerView;
    private ImageView imageView;
    private TextView textView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_cata_item);
        inint();
        int position=getIntent().getIntExtra("position",2);
        recyclerView=findViewById(R.id.recycler_cata_item);
        textView=findViewById(R.id.cataitemname);
        imageView=findViewById(R.id.back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showMax(new onActionListener() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
        textView.setText(WallPaperSelect.getCataName().get(position).getName());
        setRecyclerviewWallpaper(position);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        showMax(new onActionListener() {
            @Override
            public void onAction() {
            }
        });
    }

    private void setRecyclerviewWallpaper(int position) {

        Recycle_view recycle_View = new Recycle_view(10, 10, 15);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.addItemDecoration(recycle_View);
        CataItemAdapter cataItemAdapter = new  CataItemAdapter(WallPaperSelect.getCataName(),position ,this);
        cataItemAdapter.setInfoWallPaperListener((InfoListWallPaperListener) this);
        recyclerView.setAdapter(cataItemAdapter);
    }


    private void inint() {
        Window window = getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        findViewById(R.id.recycler_cata_item).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    }
    private void showMax(onActionListener listener) {
        if (listener != null)
            listener.onAction();

        // TODO: 2024/9/23
    }

    @Override
    public void onItemClickAction(int nameop, int recop) {
        Intent intent = new Intent(getBaseContext(), ViewActivity.class);
        intent.putExtra("naop",nameop);
        intent.putExtra("dataop",recop);
        startActivity(intent);
    }
}
