package com.ez.ertcmeeting.utils.permission

import android.app.Activity
import android.content.DialogInterface
import com.ez.ertc.meeting.R
import com.ez.ertc.meeting.utils.AndroidUtil
import com.ez.ertc.meeting.utils.permission.RomUtils
import com.ez.ertc.meeting.widget.EZDialog

/**
 *
 *
 * @author xiezuoyuan
 * @time 2022/2/24 15:47
 */
class PermissionDialog {
    companion object {
        fun requestCamera(activity:Activity?,callback: Callback){
            requestCamera(activity, callback,null)
        }
        fun requestCamera(activity:Activity?, callback: Callback, onNegativeListener: DialogInterface.OnClickListener?){
            activity?.let {
                EZDialog.Builder(activity)
                    .setTitle(activity.getString(
                        R.string.ys_permission_camera_title_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setMessage(activity.getString(R.string.ys_permission_camera_msg_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setNegativeButton(activity.getString(R.string.ezm_disagree),onNegativeListener)
                    .setPositiveButton(activity.getString(R.string.ezm_ok)){
                            _, _ ->
                        callback.onConfirm()
                    }
                    .setCancelable(false)
                    .create()
                    .show()
            }
        }
        fun requestCameraSets(activity:Activity?){
            requestCameraSets(activity,null)
        }
        fun requestCameraSets(activity:Activity?,onNegativeListener: DialogInterface.OnClickListener?){
            activity?.let {
                EZDialog.Builder(activity)
                    .setTitle(R.string.ys_permission_camera_sets_title)
                    .setMessage(activity.getString(R.string.ys_permission_camera_sets_msg_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setNegativeButton(activity.getString(R.string.ezm_disagree),onNegativeListener)
                    .setPositiveButton(activity.getString(R.string.ezm_go_set)){
                            dialog, which ->
                        onNegativeListener?.onClick(dialog,which)
                        RomUtils.toPermissionSetting(activity)
                    }
                    .setCancelable(false)
                    .create()
                    .show()
            }
        }
        fun requestMicrophone(activity:Activity?,callback: Callback){
            activity?.let {
                EZDialog.Builder(activity)
                    .setTitle(activity.getString(R.string.ys_permission_microphone_title_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setMessage(activity.getString(R.string.ys_permission_microphone_msg_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setNegativeButton(activity.getString(R.string.ezm_disagree),null)
                    .setPositiveButton(activity.getString(R.string.ezm_ok)){
                            _, _ ->
                        callback.onConfirm()
                    }
                    .setCancelable(false)
                    .create()
                    .show()
            }
        }
        fun requestMicrophoneSets(activity:Activity?){
            activity?.let {
                EZDialog.Builder(activity)
                    .setTitle(R.string.ys_permission_microphone_sets_title)
                    .setMessage(activity.getString(R.string.ys_permission_microphone_sets_msg_format,
                        AndroidUtil.getAppName(activity)
                    ))
                    .setNegativeButton(activity.getString(R.string.ezm_cancel),null)
                    .setPositiveButton(activity.getString(R.string.ezm_go_set)){
                            _, _ ->
                        RomUtils.toPermissionSetting(activity)
                    }
                    .setCancelable(false)
                    .create()
                    .show()
            }
        }
    }

    interface Callback {
        fun onConfirm()
    }
}