package com.zxhyis.tools.ui.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.fragment.app.DialogFragment
import com.zxhyis.tools.R
import com.zxhyis.tools.logic.ClickCallBack
import com.zxhyis.tools.logic.setOnClick

class FIleDialog:DialogFragment() {

    private lateinit var fileView: View

    private var clickCallBack: ClickCallBack? = null

    fun setCallBack(callBack: ClickCallBack) {
        clickCallBack = callBack
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        fileView = inflater.inflate(R.layout.dialog_create_file, container, false)
        return fileView
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val window = dialog?.window
        window?.setGravity(Gravity.CENTER)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val windowManager = activity?.windowManager
        val display = windowManager?.defaultDisplay
        val lp = dialog?.window!!.attributes
        lp.width = (display?.width!! * 0.73).toInt() //设置宽度
        dialog?.window!!.attributes = lp

        fileView.findViewById<AppCompatTextView>(R.id.tv_cancle).setOnClick {
            dialog?.dismiss()
        }

        fileView.findViewById<AppCompatTextView>(R.id.tv_establish).setOnClick {
            clickCallBack?.clickBack()
            dismiss()
        }


    }

}