Change iteraror to a for loop

This commit is contained in:
jacques 2022-06-26 11:56:06 +02:00
parent ea3a4ae374
commit 54d5abb541

View file

@ -51,9 +51,9 @@ import net.foucry.pilldroid.models.Medicine;
import net.foucry.pilldroid.models.Prescription;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
/**
@ -280,19 +280,28 @@ public class DrugListActivity extends AppCompatActivity {
}
public void constructDrugsList() {
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
prescriptionList = prescriptionsDAO.getAllMedics();
ListIterator<Prescription> listIterator = prescriptionList.listIterator();
Prescription currentPrescription;
while (listIterator.hasNext()) {
currentPrescription = listIterator.next();
// Sorting list by dateEndOfStock
prescriptionList.sort(new Comparator<>() {
@Override
public int compare(Prescription lhs, Prescription rhs) {
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
else
return (int) (lhs.getStock() - rhs.getStock());
}
});
// Move Prescription with take==0 to the end of the list
for (int i=0 ; i < prescriptionList.size(); i++ ){
currentPrescription = prescriptionList.get(i);
if (currentPrescription.getTake() == 0) {
prescriptionList.remove(currentPrescription);
prescriptionList.add(prescriptionList.size()-1, currentPrescription);
prescriptionList.add(prescriptionList.size(), currentPrescription);
}
}
@ -492,6 +501,7 @@ public class DrugListActivity extends AppCompatActivity {
}
@Override
@SuppressWarnings("deprecation")
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getBindingAdapterPosition();
@ -510,8 +520,6 @@ public class DrugListActivity extends AppCompatActivity {
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
}
Snackbar.make(recyclerView, prescription.getName(),
Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() {
@Override
@ -627,7 +635,6 @@ public class DrugListActivity extends AppCompatActivity {
holder.mContentView.setText(mValues.get(position).getName());
holder.mEndOfStock.setText(dateEndOfStock);
// Test to change background programmatically
if (mValues.get(position).getTake() == 0) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
@ -672,7 +679,6 @@ public class DrugListActivity extends AppCompatActivity {
}
});
}
}
@Override