package com.yidianling.ydlcommon.custom.dialog

import android.app.DialogFragment
import android.os.Bundle
import android.view.*
import android.view.ViewGroup

/**
 * @author yuanWai
 * @描述:底部弹出弹窗
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/2/20
 */
abstract class BottomDialog : DialogFragment{

    constructor() : super(){}

//    override fun onActivityCreated(savedInstanceState: Bundle?) {
//        super.onActivityCreated(savedInstanceState)
//        dialog.window.attributes.windowAnimations = R.style.BottomDialogAnimation
//    }

//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialog)
//    }

    override fun onStart() {
        super.onStart()
        //设置 dialog 的宽高
        dialog.window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        //设置 dialog 的背景为 null
        dialog.window.setBackgroundDrawable(null)
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        //去除标题栏
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)

        val window = dialog.window
        val lp = window.attributes
        lp.gravity = Gravity.BOTTOM //底部
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
//        lp.windowAnimations = R.style.BottomDialogAnimation
        window.attributes = lp

        return createView(inflater, container)
    }

    //重写此方法，设置布局文件
    protected abstract fun createView(inflater: LayoutInflater?, container: ViewGroup?): View

}