mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-17 18:41:37 +01:00
Fin de la fonctionnalité
Merge branch 'feature/addMedicament' into develop
This commit is contained in:
commit
49a3583264
3 changed files with 46 additions and 27 deletions
|
@ -33,4 +33,5 @@ dependencies {
|
|||
compile 'com.android.support:support-v4:23.3.0'
|
||||
compile 'com.android.support:recyclerview-v7:23.3.0'
|
||||
compile 'com.android.support:design:23.3.0'
|
||||
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
private SimpleCursorAdapter drugAdapter;
|
||||
private List<Medicament> medicaments;
|
||||
|
||||
private View mRecyclerView;
|
||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -74,20 +77,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 +126,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 +176,41 @@ 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
|
||||
{
|
||||
} 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
|
||||
scannedMedoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(scannedMedoc);
|
||||
mAdapter.addItem(medicaments.size()-1,scannedMedoc);
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
} else {
|
||||
dlg.setMessage(context.getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -222,9 +229,13 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
|
||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
||||
recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(medicaments));
|
||||
mAdapter = (SimpleItemRecyclerViewAdapter) new SimpleItemRecyclerViewAdapter(medicaments);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleItemRecyclerViewAdapter
|
||||
*/
|
||||
public class SimpleItemRecyclerViewAdapter
|
||||
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
|
@ -234,6 +245,12 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
mValues = items;
|
||||
}
|
||||
|
||||
public void addItem(int position, Medicament scannedMedoc) {
|
||||
mValues.add(scannedMedoc);
|
||||
notifyDataSetChanged();
|
||||
dbHelper.addDrug(scannedMedoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
|
|
|
@ -126,6 +126,7 @@
|
|||
<string name="sbc_name">Google Book Search</string>
|
||||
<string name="wifi_changing_network">Requesting connection to network\u2026</string>
|
||||
<string name="msgNotFound">Médicament introuvable dans la base de données</string>
|
||||
<string name="msgFound">trouvé dans la base de données</string>
|
||||
<string name="about">À propos</string>
|
||||
<string name="help">Aide</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue