diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index ebeee23..97bc024 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -85,7 +85,6 @@ public class MedicamentListActivity extends AppCompatActivity { private List medicaments; - private View mRecyclerView; private SimpleItemRecyclerViewAdapter mAdapter; public int getCount() { @@ -96,6 +95,36 @@ public class MedicamentListActivity extends AppCompatActivity { return medicaments.get(position); } + public void constructMedsList() + { + Medicament currentMedicament; + dbHelper = new DBHelper(getApplicationContext()); + + if (!(medicaments == null)) { + if (!medicaments.isEmpty()) { + medicaments.clear(); + } + } + medicaments = dbHelper.getAllDrugs(); + + Collections.sort(medicaments, new Comparator() { + @Override + public int compare(Medicament lhs, Medicament rhs) { + return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); + } + }); + + for (int position = 0 ; position < this.getCount() ; position++ ) { + currentMedicament = this.getItem(position); + currentMedicament.newStock(currentMedicament.getStock()); + dbHelper.updateDrug(currentMedicament); + } + + View mRecyclerView = findViewById(R.id.medicament_list); + assert mRecyclerView != null; + setupRecyclerView((RecyclerView) mRecyclerView); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -160,23 +189,8 @@ public class MedicamentListActivity extends AppCompatActivity { } } - /* if (medicaments == null) { - medicaments = dbHelper.getAllDrugs(); - - Collections.sort(medicaments, new Comparator() { - @Override - public int compare(Medicament lhs, Medicament rhs) { - return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); - } - }); - } -*/ constructMedsList(); - 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 // large-screen layouts (res/values-w900dp). @@ -307,7 +321,6 @@ public class MedicamentListActivity extends AppCompatActivity { // nothing to do to just dismiss dialog } }); - } } else if (resultCode == RESULT_CANCELED) { // Handle cancel @@ -315,8 +328,7 @@ public class MedicamentListActivity extends AppCompatActivity { } } else if (requestCode == 1){ Toast.makeText(context, "back from detail", Toast.LENGTH_SHORT).show(); - // TODO : Si requestCode=1 -> Sauvegarde du medoc dans la base et - // TODO : raffraichissement de la base.[Call updateDrug(medicament)] + constructMedsList(); } } @@ -444,32 +456,7 @@ public class MedicamentListActivity extends AppCompatActivity { }); } - protected void constructMedsList() - { - Medicament currentMedicament; - dbHelper = new DBHelper(this); - if (!medicaments.isEmpty()) { - medicaments.clear(); - } - - medicaments = dbHelper.getAllDrugs(); - - Collections.sort(medicaments, new Comparator() { - @Override - public int compare(Medicament lhs, Medicament rhs) { - return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); - } - }); - - for (int position = 0 ; position < this. getCount() ; position++ ) { - currentMedicament = this.getItem(position); - currentMedicament.newStock(currentMedicament.getStock()); - dbHelper.updateDrug(currentMedicament); - } - - - } @Override public int getItemCount() { return mValues.size();