Revert "Prevent multiple error dialogs shows up at the same time"

This reverts commit 7d2c4cdba3.
This commit is contained in:
世界 2024-10-25 22:28:38 +08:00
parent 45a1f5f0aa
commit 0de351375e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 4 additions and 28 deletions

View file

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

View file

@ -62,8 +62,8 @@ class QRScanActivity : AbstractActivity<ActivityQrScanBinding>() {
} else { } else {
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
finish() finish()
}
} }
}
private lateinit var imageAnalysis: ImageAnalysis private lateinit var imageAnalysis: ImageAnalysis
private lateinit var imageAnalyzer: ImageAnalysis.Analyzer private lateinit var imageAnalyzer: ImageAnalysis.Analyzer
@ -83,9 +83,6 @@ class QRScanActivity : AbstractActivity<ActivityQrScanBinding>() {
private lateinit var cameraPreview: Preview private lateinit var cameraPreview: Preview
private lateinit var camera: Camera private lateinit var camera: Camera
// prevent multiple error dialogs shows up at the same time
private var invalidRawDataErrorDialogShowing: Boolean = false
private fun startCamera() { private fun startCamera() {
val cameraProviderFuture = try { val cameraProviderFuture = try {
ProcessCameraProvider.getInstance(this) ProcessCameraProvider.getInstance(this)
@ -132,14 +129,8 @@ class QRScanActivity : AbstractActivity<ActivityQrScanBinding>() {
importRemoteProfileFromString(value) importRemoteProfileFromString(value)
return true return true
} catch (e: Exception) { } catch (e: Exception) {
if (invalidRawDataErrorDialogShowing) return false
invalidRawDataErrorDialogShowing = true
lifecycleScope.launch { lifecycleScope.launch {
errorDialogBuilder(e) { _, _ -> errorDialogBuilder(e).show()
invalidRawDataErrorDialogShowing = false
}.show()
} }
} }
return false return false