Notification d'ajout d'un médicament à la liste

This commit is contained in:
Jacques Foucry 2016-06-20 23:03:24 +02:00
parent 1db5b70667
commit 4b6ec80c52

View file

@ -60,6 +60,7 @@ public class MedicamentListActivity extends AppCompatActivity {
private List<Medicament> medicaments;
private View mRecyclerView;
private SimpleItemRecyclerViewAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -203,7 +204,9 @@ public class MedicamentListActivity extends AppCompatActivity {
@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();
@ -226,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> {
@ -238,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())