93 lines
3.3 KiB
Kotlin
93 lines
3.3 KiB
Kotlin
package com.gh.common.util
|
|
|
|
import android.app.Dialog
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.Window
|
|
import android.widget.TextView
|
|
import com.gh.common.dialog.TrackableDialog
|
|
import com.gh.common.util.DialogUtils.checkDialogContext
|
|
import com.gh.gamecenter.R
|
|
|
|
object DialogHelper {
|
|
|
|
/**
|
|
* Material Design 风格弹窗
|
|
*
|
|
* @param context
|
|
* @param title 标题
|
|
* @param content 内容
|
|
* @param positiveText 确认按钮文本
|
|
* @param negativeText 取消按钮文本
|
|
* @param positiveClickCallback 确认按钮监听
|
|
* @param negativeClickCallback 取消按钮监听
|
|
* @param trackMtaEvent 是否记录出现、关闭弹窗MTA事件
|
|
* @param mtaEvent MTA 的事件名
|
|
* @param mtaKey MTA 的事件 Key
|
|
*/
|
|
fun showDialog(context: Context,
|
|
title: String,
|
|
content: CharSequence,
|
|
positiveText: String,
|
|
negativeText: String,
|
|
positiveClickCallback: (() -> Unit)? = null,
|
|
negativeClickCallback: (() -> Unit)? = null,
|
|
trackMtaEvent: Boolean = false,
|
|
mtaEvent: String = "",
|
|
mtaKey: String = ""): Dialog {
|
|
val solidContext = checkDialogContext(context)
|
|
|
|
val dialog = if (trackMtaEvent) {
|
|
TrackableDialog(solidContext, R.style.GhAlertDialog, mtaEvent, mtaKey)
|
|
} else {
|
|
Dialog(solidContext, R.style.GhAlertDialog)
|
|
}
|
|
|
|
val contentView = LayoutInflater.from(solidContext).inflate(R.layout.dialog_alert, null)
|
|
val contentTv = contentView.findViewById<TextView>(R.id.dialog_content)
|
|
val titleTv = contentView.findViewById<TextView>(R.id.dialog_title)
|
|
val negativeTv = contentView.findViewById<TextView>(R.id.dialog_negative)
|
|
val positiveTv = contentView.findViewById<TextView>(R.id.dialog_positive)
|
|
contentTv.text = content
|
|
titleTv.text = title
|
|
negativeTv.text = negativeText
|
|
positiveTv.text = positiveText
|
|
|
|
negativeTv.setOnClickListener {
|
|
if (trackMtaEvent) MtaHelper.onEvent(mtaEvent, mtaKey, "点击" + negativeText)
|
|
|
|
negativeClickCallback?.invoke()
|
|
dialog.dismiss()
|
|
}
|
|
|
|
positiveTv.setOnClickListener {
|
|
if (trackMtaEvent) MtaHelper.onEvent(mtaEvent, mtaKey, "点击$positiveText")
|
|
|
|
positiveClickCallback?.invoke()
|
|
dialog.dismiss()
|
|
}
|
|
|
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
|
dialog.setContentView(contentView)
|
|
dialog.show()
|
|
return dialog
|
|
}
|
|
|
|
/**
|
|
* For legacy java invocation
|
|
*/
|
|
@JvmStatic
|
|
fun showDialog(context: Context,
|
|
title: String,
|
|
content: CharSequence,
|
|
positiveText: String,
|
|
negativeText: String,
|
|
positiveClickCallback: EmptyCallback,
|
|
negativeClickCallback: EmptyCallback,
|
|
trackMtaEvent: Boolean = false,
|
|
mtaEvent: String = "",
|
|
mtaKey: String = ""): Dialog {
|
|
return showDialog(context, title, content, positiveText, negativeText, { positiveClickCallback.onCallback() }, { negativeClickCallback.onCallback() }, trackMtaEvent, mtaEvent, mtaKey)
|
|
}
|
|
|
|
} |