/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.util;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;

/**
 * PermissionUtil
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 21.]   [최초 작성]
 * @since 2018. 9. 21.
 */
public class PermissionUtil {

  public static void requestPermissions(Activity activity, @NonNull String[] permissions, @NonNull int requestCode) {
    ActivityCompat.requestPermissions(activity, permissions, requestCode);
  }

  public static void requestPermission(Activity activity, String permission, @NonNull int requestCode) {
    if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(), permission) != PackageManager.PERMISSION_GRANTED) {
      if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
        // 1 회 거부 후 다시 요청
        ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode);
      }
      else {
        // 처음 퍼미션 요청
        ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode);
      }
    }
  }
}
