Skip to content

Commit

Permalink
refactor: use helper methods to process scan result
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgerardojacinto committed Nov 17, 2023
1 parent ccc1ea3 commit ecc9fea
Showing 1 changed file with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ import com.outsystems.plugins.barcode.controller.helper.OSBARCZXingHelper
import com.outsystems.plugins.barcode.model.OSBARCError
import com.outsystems.plugins.barcode.model.OSBARCScanParameters
import com.outsystems.plugins.barcode.view.ui.theme.BarcodeScannerTheme
import com.outsystems.plugins.barcode.R
import com.outsystems.plugins.barcode.view.ui.theme.CustomGray
import com.outsystems.plugins.barcode.R

/**
* This class is responsible for implementing the UI of the scanning screen using Jetpack Compose.
Expand Down Expand Up @@ -184,20 +184,10 @@ class OSBARCScannerActivity : ComponentActivity() {
OSBARCMLKitHelper()
),
{ result ->
// we only want to process the scan result if scanning is active
if (scanning) {
val resultIntent = Intent()
resultIntent.putExtra(SCAN_RESULT, result)
setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent)
finish()
}
processReadSuccess(result)
},
{
// we only want to process the scan result if scanning is active
if (scanning) {
setResult(it.code)
finish()
}
processReadError(it)
}
)
)
Expand Down Expand Up @@ -309,4 +299,22 @@ class OSBARCScannerActivity : ComponentActivity() {
) == PackageManager.PERMISSION_GRANTED
}

private fun processReadSuccess(result: String) {
// we only want to process the scan result if scanning is active
if (scanning) {
val resultIntent = Intent()
resultIntent.putExtra(SCAN_RESULT, result)
setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent)
finish()
}
}

private fun processReadError(error: OSBARCError) {
// we only want to process the scan result if scanning is active
if (scanning) {
setResult(error.code)
finish()
}
}

}

0 comments on commit ecc9fea

Please sign in to comment.