package com.ym.modulecommon.utils

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.ym.admodule.R
import com.ym.modulecommon.AppliContext
import com.ym.modulecommon.base.BaseDialog

/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/10/21
 */
object PermissionDialog :BaseDialog(){
    fun showPermission(activity: Activity, title:String, quitListener: View.OnClickListener, settingListener: View.OnClickListener) {
        if (activity == null) {
            return
        }
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_permissisns,
            activity!!,
            mDialog,
            0,
            Gravity.CENTER
        )
        var appName = ""
        try {
            val packageManager = activity.getPackageManager();
            appName = packageManager?.getApplicationLabel(activity?.getApplicationInfo()).toString()
        } catch (e :Throwable ) {

        }
        mDialogView.findViewById<TextView>(R.id.tv_info).text = appName + "缺少必要权限：\n\n${title}\n请点击\"设置\"-\"权限\"-打开所需权限。\n最后点击两次后退按钮，即可返回。"

        mDialogView.findViewById<TextView>(R.id.btn_permission_quit).setOnClickListener {
            quitListener.onClick(it)
        }

        mDialogView.findViewById<TextView>(R.id.btn_permission_setting).setOnClickListener {
            settingListener.onClick(it)
            mDialog?.dismiss()
        }

        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        mDialog?.show()
    }

}