Skip to content

Commit

Permalink
fix: do not access binding if cancelled
Browse files Browse the repository at this point in the history
Closes OPENFOODFACTS-ANDROID-3XY
  • Loading branch information
VaiTon committed Jul 27, 2021
1 parent be6c816 commit 185b559
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -210,6 +210,7 @@ class ContinuousScanActivity : BaseActivity(), IProductView {
val productState = try {
client.getProductStateFull(barcode, userAgent = Utils.HEADER_USER_AGENT_SCAN)
} catch (err: Exception) {
if (!isActive) return@launch
// A network error happened
if (err is IOException) {
hideAllViews()
Expand All @@ -222,10 +223,10 @@ class ContinuousScanActivity : BaseActivity(), IProductView {
binding.quickViewProgress.visibility = View.GONE
binding.quickViewProgressText.visibility = View.GONE

Toast.makeText(this@ContinuousScanActivity, R.string.txtConnectionError, Toast.LENGTH_LONG).run {
setGravity(CENTER, 0, 0)
show()
}
Toast.makeText(this@ContinuousScanActivity, R.string.txtConnectionError, Toast.LENGTH_LONG)
.apply { setGravity(CENTER, 0, 0) }
.show()

Log.w(LOG_TAG, err.message, err)
}
return@launch
Expand Down

0 comments on commit 185b559

Please sign in to comment.