mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-17 18:41:37 +01:00
Create de constructMedsList in order to have a single endpoint to grab and sort the meds database
This commit is contained in:
parent
193508ddbb
commit
08159f6332
1 changed files with 31 additions and 44 deletions
|
@ -85,7 +85,6 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
|
||||
private List<Medicament> 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<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);
|
||||
}
|
||||
|
||||
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<Medicament>() {
|
||||
@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<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();
|
||||
|
|
Loading…
Reference in a new issue