上海工程测量
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

50 lines
1.5 KiB

package com.project.survey.widget
import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.widget.TextView
import com.project.survey.R
import com.project.survey.extend.isVisibleOrGone
class LoadingDialog @JvmOverloads constructor(context: Context) :
Dialog(context, R.style.loading_dialog) {
inner class Builder(val context: Context) {
private var message = ""
private var isCancelable = false
private var isCancelOutside = false
fun setMessage(message: String): Builder = apply {
this.message = message
}
/**
* 设置是否可以按返回键取消
*/
fun setCancelable(isCancelable: Boolean): Builder = apply {
this.isCancelable = isCancelable
}
/**
* 设置是否可以取消
*/
fun setCancelOutside(isCancelOutside: Boolean): Builder = apply {
this.isCancelOutside = isCancelOutside
}
fun create(): LoadingDialog {
val view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null, false)
view.findViewById<TextView>(R.id.tvLoadingTips).run {
isVisibleOrGone(message.isNotBlank())
text = message
}
return LoadingDialog(context).apply {
setContentView(view)
setCancelable(isCancelable)
setCanceledOnTouchOutside(isCancelOutside)
}
}
}
}