package com.visagetechnologies.lightConditions;
import androidx.core.app.ActivityCompat;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;

public class PermissionActivity extends Activity {

    private static final String[] PERMS={
            CAMERA,
            WRITE_EXTERNAL_STORAGE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_permission);

        ActivityCompat.requestPermissions(this, PERMS, 0);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String[] permissions,
                                           int[] grantResults) {

        boolean allowed = true;
        for(int i = 0; i < permissions.length; i++)
        {
            if(grantResults[i] == PackageManager.PERMISSION_DENIED)
            {
                allowed = false;
                break;
            }
        }

        if(allowed)
        {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        }

    }
}
