package br.com.codetec.saudesabor.utils;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.net.URISyntaxException;

public class UtilsActivity {
    private static final UtilsActivity ourInstance = new UtilsActivity();

    public static UtilsActivity getInstance() {
        return ourInstance;
    }


    public void startActivity(Context context, Class classDetination){
        Intent intent = new Intent(context,classDetination);
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public void shareTextUrl(View view, String text, String titulo) throws URISyntaxException {
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("text/plain");
        share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

//        share.putExtra(Intent.EXTRA_SUBJECT, "Izi App - Evento");
        share.putExtra(Intent.EXTRA_TEXT, text);

        view.getContext().startActivity(Intent.createChooser(share, titulo));
    }

    public void initRecyclerView(Context context, RecyclerView recyclerView){
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
//        recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
    }

    public void esconderTeclado(Context context, EditText edit ){
        ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
            edit.getWindowToken(), 0);
    }

}
