|
|
@@ -59,18 +59,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
*/
|
|
|
var onCancelListener: DialogInterface.OnCancelListener? = null
|
|
|
|
|
|
- /**
|
|
|
- * 顶部图片
|
|
|
- */
|
|
|
- private var headerIconUri: Uri? = null
|
|
|
-
|
|
|
- /**
|
|
|
- * 标题颜色
|
|
|
- */
|
|
|
- private var titleColor: Int = 0
|
|
|
-
|
|
|
- var customMessageView: View? = null
|
|
|
-
|
|
|
private val binding by viewBinding(LayoutCommonDialogBinding::bind)
|
|
|
|
|
|
private var isDismissAfterClick = true
|
|
|
@@ -125,29 +113,29 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
val showDefaultConfirm = arguments?.getBoolean(KEY_SHOW_DEFAULT_CONFIRM)
|
|
|
if (confirmText.isNullOrEmpty()) {
|
|
|
if (showDefaultConfirm == false) {
|
|
|
- binding.tvConfirm.visibility = View.GONE
|
|
|
+ binding.btnConfirm.visibility = View.GONE
|
|
|
}
|
|
|
} else {
|
|
|
- binding.tvConfirm.text = confirmText
|
|
|
+ binding.btnConfirm.text = confirmText
|
|
|
}
|
|
|
val positiveCountDownMS = arguments?.getLong(KEY_POSITIVE_COUNTDOWN_MS) ?: 0
|
|
|
val isClickableWhenCountDown =
|
|
|
arguments?.getBoolean(KEY_IS_CLICKABLE_WHEN_COUNTDOWN, false) ?: false
|
|
|
- if (binding.tvConfirm.isVisible && positiveCountDownMS > 0L) {
|
|
|
- binding.tvConfirm.isEnabled = isClickableWhenCountDown
|
|
|
+ if (binding.btnConfirm.isVisible && positiveCountDownMS > 0L) {
|
|
|
+ binding.btnConfirm.isEnabled = isClickableWhenCountDown
|
|
|
positiveCountDownTimer?.cancel()
|
|
|
positiveCountDownTimer = object : CountDownTimer(positiveCountDownMS, 1000L) {
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
override fun onTick(millisUntilFinished: Long) {
|
|
|
- binding.tvConfirm.text = "${millisUntilFinished / 1000}s"
|
|
|
+ binding.btnConfirm.text = "${millisUntilFinished / 1000}s"
|
|
|
countDownTimerFormat?.let {
|
|
|
- binding.tvConfirm.text = it.invoke(millisUntilFinished)
|
|
|
+ binding.btnConfirm.text = it.invoke(millisUntilFinished)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onFinish() {
|
|
|
- binding.tvConfirm.isEnabled = true
|
|
|
- binding.tvConfirm.text = when (confirmText.isNullOrEmpty()) {
|
|
|
+ binding.btnConfirm.isEnabled = true
|
|
|
+ binding.btnConfirm.text = when (confirmText.isNullOrEmpty()) {
|
|
|
true -> getCompatString(R.string.commonui_confirm)
|
|
|
else -> confirmText
|
|
|
}
|
|
|
@@ -162,21 +150,15 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
val showDefaultCancel = arguments?.getBoolean(KEY_SHOW_DEFAULT_CANCEL)
|
|
|
if (cancelText.isNullOrEmpty()) {
|
|
|
if (showDefaultCancel == true) {
|
|
|
- binding.tvCancel.visibility = View.VISIBLE
|
|
|
+ binding.btnCancel.visibility = View.VISIBLE
|
|
|
}
|
|
|
} else {
|
|
|
- binding.tvCancel.text = cancelText
|
|
|
- binding.tvCancel.visibility = View.VISIBLE
|
|
|
+ binding.btnCancel.text = cancelText
|
|
|
+ binding.btnCancel.visibility = View.VISIBLE
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private fun initHeader() {
|
|
|
- //头图
|
|
|
- headerIconUri = arguments?.getParcelable(KEY_HEADER_ICON_URI)
|
|
|
- if (headerIconUri != null) {
|
|
|
- binding.headerIv.visibility = View.VISIBLE
|
|
|
- binding.headerIv.setImageURI(headerIconUri, true)
|
|
|
- }
|
|
|
//顶部关闭按钮
|
|
|
val showTopCloseBtn = arguments?.getBoolean(KEY_SHOW_TOP_CLOSE_BTN) ?: false
|
|
|
if (showTopCloseBtn) {
|
|
|
@@ -190,34 +172,9 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
}
|
|
|
|
|
|
private fun initTitleMessageView() {
|
|
|
- // 顶部背景图
|
|
|
- val topBgRes = arguments?.getInt(KEY_TOP_BG_RES) ?: 0
|
|
|
- if (topBgRes != 0) {
|
|
|
- binding.ivTopBg.visibility = View.VISIBLE
|
|
|
- binding.ivTopBg.setImageResource(topBgRes)
|
|
|
- } else {
|
|
|
- binding.ivTopBg.visibility = View.GONE
|
|
|
- }
|
|
|
-
|
|
|
- //标题上面的图片
|
|
|
- val topImageUri: Uri? = arguments?.getParcelable(KEY_TOP_IMG_URI)
|
|
|
- val topImageWidth = arguments?.getInt(KEY_TOP_IMG_WIDTH) ?: 0
|
|
|
- val topImageHeight = arguments?.getInt(KEY_TOP_IMG_HEIGHT) ?: 0
|
|
|
- if (topImageUri != null) {
|
|
|
- binding.ivTop.visibility = View.VISIBLE
|
|
|
- val lp = binding.ivTop.layoutParams
|
|
|
- lp.width = topImageWidth
|
|
|
- lp.height = topImageHeight
|
|
|
- binding.ivTop.layoutParams = lp
|
|
|
- binding.ivTop.setImageURI(topImageUri, true)
|
|
|
- } else {
|
|
|
- binding.ivTop.visibility = View.GONE
|
|
|
- }
|
|
|
-
|
|
|
val title = arguments?.getCharSequence(KEY_TITLE)
|
|
|
val msg = arguments?.getCharSequence(KEY_MESSAGE)
|
|
|
val msgGravity = arguments?.getInt(KEY_MESSAGE_GRAVITY)
|
|
|
- titleColor = arguments?.getInt(KEY_TITLE_COLOR) ?: 0
|
|
|
//若标题为空,内容展示在标题的位置上
|
|
|
if (title.isNullOrEmpty()) {
|
|
|
binding.tvMessage.visibility = View.GONE
|
|
|
@@ -226,23 +183,17 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
binding.tvTitle.text = title
|
|
|
initMessageView(binding.tvMessage, msg, msgGravity)
|
|
|
}
|
|
|
-
|
|
|
- //自定义messageView
|
|
|
- if (customMessageView != null) {
|
|
|
- binding.flSubBlock.visibility = View.VISIBLE
|
|
|
- binding.flSubBlock.addView(customMessageView)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private fun initEvent() {
|
|
|
- binding.tvConfirm.setOnClickListener {
|
|
|
+ binding.btnConfirm.setOnClickListener {
|
|
|
onPositive?.invoke()
|
|
|
if (isDismissAfterClick) {
|
|
|
dismissAllowingStateLoss()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- binding.tvCancel.setOnClickListener {
|
|
|
+ binding.btnCancel.setOnClickListener {
|
|
|
onNegative?.invoke()
|
|
|
if (isDismissAfterClick) {
|
|
|
dismissAllowingStateLoss()
|
|
|
@@ -287,12 +238,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
private const val KEY_SHOW_DEFAULT_CANCEL = "show_default_cancel"
|
|
|
private const val KEY_SHOW_DEFAULT_CONFIRM = "show_default_confirm"
|
|
|
private const val KEY_IS_DISMISS_AFTER_CLICK = "is_dismiss_after_click"
|
|
|
- private const val KEY_HEADER_ICON_URI = "header_icon_uri"
|
|
|
- private const val KEY_TITLE_COLOR = "title_color"
|
|
|
- private const val KEY_TOP_BG_RES = "top_bg_res"
|
|
|
- private const val KEY_TOP_IMG_URI = "top_img_uri"
|
|
|
- private const val KEY_TOP_IMG_WIDTH = "top_img_width"
|
|
|
- private const val KEY_TOP_IMG_HEIGHT = "top_img_height"
|
|
|
private const val KEY_SHOW_TOP_CLOSE_BTN = "key_show_top_close_btn"
|
|
|
private const val KEY_POSITIVE_COUNTDOWN_MS = "positive_countdown_ms"
|
|
|
private const val KEY_IS_CLICKABLE_WHEN_COUNTDOWN =
|
|
|
@@ -300,7 +245,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
|
|
|
@JvmStatic
|
|
|
fun newInstance(
|
|
|
- headerIconUri: Uri? = null,
|
|
|
title: CharSequence? = null,
|
|
|
message: CharSequence? = null,
|
|
|
messageGravity: Int = Gravity.CENTER,
|
|
|
@@ -318,12 +262,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
canceledOnTouchOutside: Boolean,
|
|
|
onCancelListener: DialogInterface.OnCancelListener? = null,
|
|
|
isDismissAfterClick: Boolean = true,
|
|
|
- titleColor: Int = 0,
|
|
|
- customMessageView: View? = null,
|
|
|
- topBgRes: Int = 0,
|
|
|
- topImageUri: Uri? = null,
|
|
|
- topImageWidth: Int,
|
|
|
- topImageHeight: Int,
|
|
|
showTopCloseBtn: Boolean,
|
|
|
positiveCountDownMS: Long = 0,
|
|
|
isClickableWhenCountDown: Boolean = false,
|
|
|
@@ -340,12 +278,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
bundle.putBoolean(KEY_SHOW_DEFAULT_CONFIRM, showDefaultConfirm)
|
|
|
bundle.putBoolean(KEY_SHOW_DEFAULT_CANCEL, showDefaultCancel)
|
|
|
bundle.putBoolean(KEY_IS_DISMISS_AFTER_CLICK, isDismissAfterClick)
|
|
|
- bundle.putParcelable(KEY_HEADER_ICON_URI, headerIconUri)
|
|
|
- bundle.putInt(KEY_TITLE_COLOR, titleColor)
|
|
|
- bundle.putInt(KEY_TOP_BG_RES, topBgRes)
|
|
|
- bundle.putParcelable(KEY_TOP_IMG_URI, topImageUri)
|
|
|
- bundle.putInt(KEY_TOP_IMG_WIDTH, topImageWidth)
|
|
|
- bundle.putInt(KEY_TOP_IMG_HEIGHT, topImageHeight)
|
|
|
bundle.putBoolean(KEY_SHOW_TOP_CLOSE_BTN, showTopCloseBtn)
|
|
|
bundle.putLong(KEY_POSITIVE_COUNTDOWN_MS, positiveCountDownMS)
|
|
|
bundle.putBoolean(KEY_IS_CLICKABLE_WHEN_COUNTDOWN, isClickableWhenCountDown)
|
|
|
@@ -358,14 +290,12 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
dialog.onCancelListener = onCancelListener
|
|
|
dialog.mCancelable = cancelable
|
|
|
dialog.mCanceledOnTouchOutside = canceledOnTouchOutside
|
|
|
- dialog.customMessageView = customMessageView
|
|
|
dialog.arguments = bundle
|
|
|
return dialog
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class Builder {
|
|
|
- private var headerIconUri: Uri? = null
|
|
|
private var title: CharSequence? = null
|
|
|
private var message: CharSequence? = null
|
|
|
private var messageGravity: Int = Gravity.CENTER
|
|
|
@@ -383,13 +313,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
private var canceledOnTouchOutside: Boolean = false
|
|
|
private var onCancelListener: DialogInterface.OnCancelListener? = null
|
|
|
private var isDismissAfterClick: Boolean = true
|
|
|
-
|
|
|
- private var titleColor: Int = 0
|
|
|
- private var topImageUri: Uri? = null
|
|
|
- private var customMessageView: View? = null
|
|
|
- private var topBgRes: Int = 0
|
|
|
- private var topImageWidth: Int = 0
|
|
|
- private var topImageHeight: Int = 0
|
|
|
private var showTopCloseBtn: Boolean = false
|
|
|
private var positiveCountDownMS: Long = 0
|
|
|
private var isClickableWhenCountDown: Boolean = false //倒计时期间能否点击按钮
|
|
|
@@ -401,45 +324,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
- fun topBgResource(resourceId: Int): Builder {
|
|
|
- topBgRes = resourceId
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun customMessageView(view: View): Builder {
|
|
|
- customMessageView = view
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun topImageResource(resourceId: Int): Builder {
|
|
|
- topImageUri = UriUtil.getUriForResourceId(resourceId)
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun topImageResource(resourceId: Int, width: Int, height: Int): Builder {
|
|
|
- topImageUri = UriUtil.getUriForResourceId(resourceId)
|
|
|
- topImageWidth = width
|
|
|
- topImageHeight = height
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun topImageUrl(url: String, width: Int, height: Int): Builder {
|
|
|
- topImageUri = UriUtil.parseUriOrNull(url)
|
|
|
- topImageWidth = width
|
|
|
- topImageHeight = height
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun headerIconResource(resourceId: Int): Builder {
|
|
|
- headerIconUri = UriUtil.getUriForResourceId(resourceId)
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- fun headerIconUrl(url: String): Builder {
|
|
|
- headerIconUri = UriUtil.parseUriOrNull(url)
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
fun title(title: CharSequence): Builder {
|
|
|
this.title = title
|
|
|
return this
|
|
|
@@ -495,11 +379,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
- fun titleColor(@ColorRes color: Int): Builder {
|
|
|
- this.titleColor = color
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
fun messageGravity(gravity: Int): Builder {
|
|
|
this.messageGravity = gravity
|
|
|
return this
|
|
|
@@ -527,7 +406,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
|
|
|
fun build(): CommonDialog {
|
|
|
return newInstance(
|
|
|
- headerIconUri,
|
|
|
title,
|
|
|
message,
|
|
|
messageGravity,
|
|
|
@@ -542,12 +420,6 @@ open class CommonDialog : BaseDialogFragment(R.layout.layout_common_dialog) {
|
|
|
canceledOnTouchOutside,
|
|
|
onCancelListener,
|
|
|
isDismissAfterClick,
|
|
|
- titleColor,
|
|
|
- customMessageView,
|
|
|
- topBgRes,
|
|
|
- topImageUri,
|
|
|
- topImageWidth,
|
|
|
- topImageHeight,
|
|
|
showTopCloseBtn,
|
|
|
positiveCountDownMS,
|
|
|
isClickableWhenCountDown,
|