package cn.muchinfo.rma.view.base.home.registration

import android.content.Context
import android.view.View
import android.widget.PopupWindow
import android.widget.TextView
import cn.muchinfo.rma.R
import com.qmuiteam.qmui.skin.QMUISkinHelper
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.util.QMUIResHelper
import com.qmuiteam.qmui.widget.popup.QMUIPopup
import com.qmuiteam.qmui.widget.popup.QMUIPopups


fun showPopups(context: Context, textString: String, v: View) {

    val textView = TextView(context)
    textView.setLineSpacing(
        QMUIDisplayHelper.dp2px(
            context,
            4
        ).toFloat(), 1.0f
    )
    val padding = QMUIDisplayHelper.dp2px(context, 20)
    textView.setPadding(padding, padding, padding, padding)
    textView.setText(textString)
    textView.setTextColor(
        QMUIResHelper.getAttrColor(context, R.attr.app_skin_common_title_text_color)
    )
    val builder = QMUISkinValueBuilder.acquire()
    builder.textColor(R.attr.app_skin_common_title_text_color)
    QMUISkinHelper.setSkinValue(textView, builder)
    builder.release()
    QMUIPopups.popup(context, QMUIDisplayHelper.dp2px(context, 200))
        .preferredDirection(QMUIPopup.DIRECTION_TOP)
        .view(textView)
        .edgeProtection(QMUIDisplayHelper.dp2px(context, 20))
        .offsetX(QMUIDisplayHelper.dp2px(context, 20))
        .offsetYIfBottom(QMUIDisplayHelper.dp2px(context, 5))
        .shadow(true)
        .arrow(true)
        .animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
        .onDismiss(PopupWindow.OnDismissListener {

        })
        .show(v)
}