package com.trace.drawing.people.page;

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

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

import com.trace.drawing.people.callbacl.OnClickCallback;
import com.trace.drawing.people.databinding.PageMainBinding;
import com.trace.drawing.people.item.MainItem;
import com.trace.drawing.people.tools.App;
import com.trace.drawing.people.tools.Common;
import com.trace.drawing.people.up.Http;
import com.trace.drawing.people.up.SaveUtils;

public class MainPage extends AppCompatActivity implements OnClickCallback,View.OnClickListener {

    private PageMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Common.setStatusBarTextColor(this, true);
        binding = PageMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        onInitRecycler();
        binding.rlUpload.setOnClickListener(this);
        binding.rlLike.setOnClickListener(this);

        boolean post = SaveUtils.INSTANCE.isPost();
        if(!post){
            Http.INSTANCE.makeGetRequest(MainPage.this);
            SaveUtils.INSTANCE.setPost(true);
        }
    }


    private void onInitRecycler() {
        MainItem mainItem = new MainItem(this);
        mainItem.setListener(this);
        binding.recyclerview.setAdapter(mainItem);
        binding.recyclerview.setLayoutManager(new GridLayoutManager(this, 1));
    }


    @Override
    public void onClickItem(int type, String dir) {
        switch (type) {
            case 0:
                Intent intent = new Intent(this, ViewAllPage.class);
                intent.putExtra(App.Key_ViewDir, dir);
                startActivity(intent);
                break;
            case 1:
                Intent intent1 = new Intent(this, PreviewPage.class);
                intent1.putExtra(App.Key_Camera, dir);
                startActivity(intent1);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        if(v.equals(binding.rlUpload)){
            Intent intent = new Intent(this, UploadPage.class);
            startActivity(intent);
        }else if(v.equals(binding.rlLike)){
            Intent intent = new Intent(this, CollectionPage.class);
            startActivity(intent);
        }
    }
}