package com.duben.microtribe.ui.widgets

import android.app.Dialog
import android.content.Context
import android.os.Build
import android.view.Gravity
import android.view.KeyEvent
import android.view.WindowManager
import android.widget.TextView
import com.duben.microtribe.R

class PermessionDialog(
    private val context: Context,
    private val listener: DialogListener
) : Dialog(
    context, R.style.dialog
) {
    private val lp: WindowManager.LayoutParams
    private val tv_dialog_per_left: TextView
    private val tv_dialog_per_right: TextView
    private val tv_dialog_permession_title: TextView

    init {
        setContentView(R.layout.dialog_permession)
        // 设置window属性
        lp = window!!.attributes
        lp.gravity = Gravity.CENTER
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.windowAnimations = R.style.DialogAnimBottom
        window!!.attributes = lp

        // 设置外部不可关闭
        setCancelable(false)
        setCanceledOnTouchOutside(false)
        setOnKeyListener { dialogInterface, i, keyEvent ->
            if (i == KeyEvent.KEYCODE_BACK) {
                true
            } else false
        }

        tv_dialog_per_left = findViewById<TextView>(R.id.tv_dialog_per_left) as TextView
        tv_dialog_per_right = findViewById<TextView>(R.id.tv_dialog_per_right) as TextView
        tv_dialog_permession_title = findViewById<TextView>(R.id.tv_dialog_permession_title) as TextView
        tv_dialog_per_left.setOnClickListener(listener)
        tv_dialog_per_right.setOnClickListener(listener)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            tv_dialog_permession_title.text="需授权存储空间权限及所有文件权限"
        }
    }

}