diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index cd6e59d..8bd1cb7 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -59,6 +59,7 @@ public class DrugListActivity extends AppCompatActivity { private ActivityResultLauncher mBarcodeScannerLauncher; + /** * Start tutorial */ @@ -177,10 +178,25 @@ public class DrugListActivity extends AppCompatActivity { } } - mBarcodeScannerLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),result -> { +/* mBarcodeScannerLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),result -> { Intent intent = result.getData(); Log.d(TAG, "intent == " + intent); startActivity(intent); + });*/ + mBarcodeScannerLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { + Intent intent = result.getData(); + BarcodeValues barcodeValues = Utils.parseSetBarcodeActivtyResult(Utils.BARCODE_SCAN, result.getResultCode(), intent, this); + + if (!barcodeValues.isEmpty()) { + Intent newIntent = new Intent(getApplicationContext(), DrugListActivity.class); + Bundle newBundle = new Bundle(); + + newBundle.putString("BarcodeFormat", barcodeValues.format()); + newBundle.putString("BarcodeContent", barcodeValues.content()); + + newIntent.putExtras(newBundle); + startActivity(newIntent); + } }); constructDrugsList();