package com.lc.myapplication.security.mysoundstwo.activity;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

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

import com.lc.myapplication.security.mysoundstwo.R;
import com.lc.myapplication.security.mysoundstwo.adapter.CategoryListAdapter;
import com.lc.myapplication.security.mysoundstwo.list.SoundsList;
import com.lc.myapplication.security.mysoundstwo.value.MySpace;
import com.lc.myapplication.security.mysoundstwo.value.MyValue;

public class CategoryActivity extends AppCompatActivity {

    private RelativeLayout mian_category;
    private SoundsList list;
    private TextView category_name;
    private ImageView category_back;
    private RecyclerView category_recycle;
    private String bgcolor;
    private int bg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);
        gotoFindview();
        onMyclick();
        setbackground();
        gotogetData();
        setRecycle();
    }

    private void gotoFindview() {
        mian_category = findViewById(R.id.main_category);
        category_name = findViewById(R.id.category_name);
        category_name.setTypeface(Typeface.createFromAsset(getAssets(),"myfront1.ttf"));
        category_recycle = findViewById(R.id.category_recycle);
        category_back = findViewById(R.id.category_back);
    }
    private void setbackground() {
        Window window = getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        mian_category.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    }
    private void onMyclick() {
        category_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    private void gotogetData() {
        Intent intent = getIntent();
        list = (SoundsList) intent.getSerializableExtra(MyValue.CATEGORY);
        assert list != null;
        category_name.setText(list.getCategoryName());
        bgcolor = intent.getStringExtra(MyValue.COLOR);
        bg = Integer.parseInt(bgcolor);
    }
    private void setRecycle() {
        MySpace mySpace = new MySpace(1,20,1);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this,3);
        category_recycle.setLayoutManager(gridLayoutManager);
        category_recycle.addItemDecoration(mySpace);
        CategoryListAdapter categoryListAdapter = new CategoryListAdapter(CategoryActivity.this,list.getList(),bg);
        category_recycle.setAdapter(categoryListAdapter);
    }
}