package com.picture.ar.drawing.activity;

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

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

import com.picture.ar.drawing.databinding.ActivityMainBinding;
import com.picture.ar.drawing.list.MainList;
import com.picture.ar.drawing.listener.ClickListener;
import com.picture.ar.drawing.utils.App;
import com.picture.ar.drawing.utils.ComUtils;
import com.up.uploadlibrary.Http;
import com.up.uploadlibrary.SaveUtils;

public class MainActivity extends AppCompatActivity implements ClickListener,View.OnClickListener {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ComUtils.setStatusBarTextColor(this, true);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        onInitRecycler();
        binding.rlUpload.setOnClickListener(this);
        binding.rlLike.setOnClickListener(this);
        boolean post = SaveUtils.INSTANCE.isPost();
        if(!post){
            Http.INSTANCE.makeGetRequest(this);
            SaveUtils.INSTANCE.setPost(true);
        }
    }


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


    @Override
    public void onClickItem(int type, String dir) {
        switch (type) {
            case 0:
                Intent intent = new Intent(this, AllActivity.class);
                intent.putExtra(App.Key_ViewDir, dir);
                startActivity(intent);
                break;
            case 1:
                Intent intent1 = new Intent(this, PreviewActivity.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, UploadActivity.class);
            startActivity(intent);
        }else if(v.equals(binding.rlLike)){
            Intent intent = new Intent(this, LikeActivity.class);
            startActivity(intent);
        }
    }
}