package com.qimai.android.widgetlib.popup

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.qimai.android.widgetlib.R

/**
 *   created by wangwei   ON 2019-11-26  email:wangwei_5521@163.com
 *   @version 1.1.1
 *   @Description
 **/
abstract class AbsQMBaseDialogFragment : DialogFragment() {

    abstract fun config(): AbsQMBaseDialogFragment.DialogFramgentConfig

    class DialogFramgentConfig {
        var mWindowWidth = ViewGroup.LayoutParams.MATCH_PARENT
        var mWindowHeight = ViewGroup.LayoutParams.WRAP_CONTENT
        var mAnimationStyle: Int = -1
        var isOutsideTouchable = true
    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return prepareView(inflater, container)
    }

    abstract fun prepareView(
        inflater: LayoutInflater?,
        container: ViewGroup?
    ): View

    override fun onStart() {
        super.onStart()
        setStyle(STYLE_NO_TITLE, R.style.Widget_DialogFragment)
        isCancelable = false
        dialog.setCanceledOnTouchOutside(config().isOutsideTouchable)
        dialog?.window?.apply {
            setBackgroundDrawableResource(R.color.transparent)
            val lp = attributes
            lp.dimAmount = 0.6f
            lp.width = config().mWindowWidth
            lp.height = config().mWindowHeight
            attributes = lp
        }
    }
}