RefundInfoDialog.kt 1.95 KB
package com.miya.fastcashier.ui.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import com.fastcashier.lib_common.util.StringPriceFormatUtils
import com.fastcashier.lib_common.util.clickWithTrigger
import com.miya.fastcashier.R
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse

/**
 * 退款信息弹窗
 */
class RefundInfoDialog(context: Context) : Dialog(context) {

    private lateinit var ivClose: ImageView
    private lateinit var tvRefund: TextView
    private lateinit var tvPrice: TextView

    private lateinit var payServiceResponse: PayServiceResponse

    init {
        initWindow()
        initConfig()
        initView()
    }

    private fun initConfig() {
        setCancelable(false)
    }

    private fun initView() {
        setContentView(R.layout.dialog_refund_info)
        ivClose = findViewById(R.id.ivClose)
        ivClose.clickWithTrigger {
            dismiss()
        }
        tvRefund = findViewById(R.id.tvRefund)
        tvPrice = findViewById(R.id.tvPrice)
    }

    fun setData(payServiceResponse: PayServiceResponse, action: (PayServiceResponse) -> Unit) {
        this.payServiceResponse = payServiceResponse
        tvPrice.text =
            "¥${StringPriceFormatUtils.transStringPriceToDecimalString(payServiceResponse.tradPrice)}"
        tvRefund.clickWithTrigger {
            action.invoke(payServiceResponse)
        }
    }

    private fun initWindow() {
        val win = this.window
        win!!.decorView.setPadding(0, 0, 0, 0)
        val lp = win.attributes
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT
        lp.gravity = Gravity.BOTTOM
        lp.windowAnimations = R.style.BottomInAndOutStyle
        win.attributes = lp
        win.setBackgroundDrawableResource(R.color.transparent)
    }
}