Prevent multiple error dialogs shows up at the same time

This commit is contained in:
邓超
2024-09-15 12:46:22 +08:00
committed by GitHub
parent e43ad4860f
commit 7d2c4cdba3
2 changed files with 28 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package io.nekohasekai.sfa.ktx
import android.content.Context
import android.content.DialogInterface
import androidx.annotation.StringRes
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.nekohasekai.sfa.R
@@ -13,12 +14,26 @@ fun Context.errorDialogBuilder(@StringRes messageId: Int): MaterialAlertDialogBu
}
fun Context.errorDialogBuilder(message: String): MaterialAlertDialogBuilder {
return errorDialogBuilder(message, null)
}
fun Context.errorDialogBuilder(
message: String,
listener: DialogInterface.OnClickListener?
): MaterialAlertDialogBuilder {
return MaterialAlertDialogBuilder(this)
.setTitle(R.string.error_title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.setPositiveButton(android.R.string.ok, listener)
}
fun Context.errorDialogBuilder(exception: Throwable): MaterialAlertDialogBuilder {
return errorDialogBuilder(exception.localizedMessage ?: exception.toString())
return errorDialogBuilder(exception, null)
}
fun Context.errorDialogBuilder(
exception: Throwable,
listener: DialogInterface.OnClickListener?
): MaterialAlertDialogBuilder {
return errorDialogBuilder(exception.localizedMessage ?: exception.toString(), listener)
}