package com.cheng.bole.ui.dialog

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.example.base.extensions.onClick
import com.cheng.bole.R
import com.cheng.bole.databinding.PopAboutTipBinding
import com.cheng.bole.ui.activity.PublicActivity
import com.cheng.bole.ui.fragment.guide.GuideFragment
import com.cheng.bole.ui.fragment.mine.about.AppConfigFragment

object PopupDialog {

    fun showAboutTip(context: Context,v:View){
        val view = LayoutInflater.from(context).inflate(R.layout.pop_about_tip,null,false)
        val binding = PopAboutTipBinding.bind(view)

        binding.tvTip1.onClick {
            PublicActivity.start(context, AppConfigFragment::class.java)
        }

        binding.tvTip2.onClick {
            PublicActivity.start(context, GuideFragment::class.java)
        }

        val popWindow = PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true)
        popWindow.isClippingEnabled = false
        popWindow.isFocusable = true
        popWindow.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

        val location = IntArray(2)
        v.getLocationOnScreen(location)
        val y: Int = location[1] + v.height
        val height = context.resources.displayMetrics.heightPixels - y
        popWindow.showAsDropDown(v, 0, 0)
    }
}