Demande ajout du médicament aprèes scan

This commit is contained in:
Jacques Foucry 2016-06-19 18:42:27 +02:00
parent 451b80f64b
commit d394f93821

View file

@ -59,6 +59,8 @@ public class MedicamentListActivity extends AppCompatActivity {
private SimpleCursorAdapter drugAdapter;
private List<Medicament> medicaments;
private View mRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -74,20 +76,6 @@ public class MedicamentListActivity extends AppCompatActivity {
toolbar.setTitle(getTitle());
}
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
*//* Snackbar.make(view, "Will be used to add a drug to the list", Snackbar.LENGTH_LONG)
.setAction("Action", null).show(); *//*
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "CODE_128");
//intent.putExtra("SCAN_FORMATS", "EAN_13,DATA_MATRIX");
startActivityForResult(intent, 0);
}
});*/
if (DEMO) {
if (dbHelper.getCount() == 0) {
@ -137,9 +125,10 @@ public class MedicamentListActivity extends AppCompatActivity {
}
});
}
View recyclerView = findViewById(R.id.medicament_list);
assert recyclerView != null;
setupRecyclerView((RecyclerView) recyclerView);
mRecyclerView = findViewById(R.id.medicament_list);
assert mRecyclerView != null;
setupRecyclerView((RecyclerView) mRecyclerView);
if (findViewById(R.id.medicament_detail_container) != null) {
// The detail container view will be present only in the
@ -186,24 +175,39 @@ public class MedicamentListActivity extends AppCompatActivity {
Log.i(Constants.TAG, "Format:" + format);
Log.i(Constants.TAG, "Content:" + contents);
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(context.getString(R.string.app_name));
// Handle successful scan
if (format.equals("CODE_128")) { //CODE_128
cip13 = contents;
} else
{
cip13 = contents.substring(4,17);
} else {
cip13 = contents.substring(4, 17);
}
dbMedoc.openDatabase();
Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
dbMedoc.close();
if (scannedMedoc != null) {
Toast.makeText(context, "Medicament found in database", Toast.LENGTH_LONG).show();
} else
{
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(context.getString(R.string.app_name));
String msg = scannedMedoc.getNom() + " " + getString(R.string.msgFound);
dlg.setMessage(msg);
dlg.setNegativeButton(context.getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Nothing to do in case of cancel
}
});
dlg.setPositiveButton(context.getString(R.string.button_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Add Medicament to DB then try to show it
dbHelper.addDrug(scannedMedoc);
}
});
dlg.show();
} else {
dlg.setMessage(context.getString(R.string.msgNotFound));
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override