change create List behavior

This commit is contained in:
Jacques Foucry 2020-05-05 22:06:26 +02:00
parent 7bf9acaaf1
commit cdbaf79823

View file

@ -160,7 +160,7 @@ public class MedicamentListActivity extends AppCompatActivity {
}
}
if (medicaments == null) {
/* if (medicaments == null) {
medicaments = dbHelper.getAllDrugs();
Collections.sort(medicaments, new Comparator<Medicament>() {
@ -170,6 +170,8 @@ public class MedicamentListActivity extends AppCompatActivity {
}
});
}
*/
constructMedsList();
mRecyclerView = findViewById(R.id.medicament_list);
assert mRecyclerView != null;
@ -227,15 +229,6 @@ public class MedicamentListActivity extends AppCompatActivity {
*/
public void newStockCalculation() {
Medicament currentMedicament;
dbHelper = new DBHelper(this);
for (int position = 0 ; position < this. getCount() ; position++ ) {
currentMedicament = this.getItem(position);
currentMedicament.newStock(currentMedicament.getStock());
dbHelper.updateDrug(currentMedicament);
}
// TODO: si un des médicaments est en rouge, on déclanche une notification visuelle pour dans 5 secondes
Calendar calendar = Calendar.getInstance();
@ -451,6 +444,32 @@ 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<Medicament>() {
@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();