package com.drawing.drawsketch.upload

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment

import com.drawing.drawsketch.databinding.DialogSelectImageBinding

class DialogSelect(private var listener: (type:Int)->Unit)  : DialogFragment() {

   private lateinit var binding: DialogSelectImageBinding
   companion object{
       val TYPE_CAMERA = 0

       val TYPE_GAllERY = 1
   }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DialogSelectImageBinding.inflate(layoutInflater)
        binding.llCamera.setOnClickListener {
            dismiss()
            listener(TYPE_CAMERA)
        }
        binding.llGallery.setOnClickListener {
            dismiss()
            listener(TYPE_GAllERY)
        }
        return binding.root
    }

    override fun onStart() {
        super.onStart()
        dialog?.window?.apply {
//            val width = (resources.displayMetrics.widthPixels * 0.85).toInt()
            setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
            setBackgroundDrawableResource(android.R.color.transparent) // 去除默认背景
            setGravity(Gravity.CENTER)
        }
    }

}