mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Change iteraror to a for loop
This commit is contained in:
parent
ea3a4ae374
commit
54d5abb541
1 changed files with 17 additions and 11 deletions
|
@ -51,9 +51,9 @@ import net.foucry.pilldroid.models.Medicine;
|
||||||
import net.foucry.pilldroid.models.Prescription;
|
import net.foucry.pilldroid.models.Prescription;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -280,19 +280,28 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void constructDrugsList() {
|
public void constructDrugsList() {
|
||||||
|
|
||||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||||
prescriptionList = prescriptionsDAO.getAllMedics();
|
prescriptionList = prescriptionsDAO.getAllMedics();
|
||||||
|
|
||||||
ListIterator<Prescription> listIterator = prescriptionList.listIterator();
|
|
||||||
Prescription currentPrescription;
|
Prescription currentPrescription;
|
||||||
|
|
||||||
while (listIterator.hasNext()) {
|
// Sorting list by dateEndOfStock
|
||||||
currentPrescription = listIterator.next();
|
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) {
|
if (currentPrescription.getTake() == 0) {
|
||||||
prescriptionList.remove(currentPrescription);
|
prescriptionList.remove(currentPrescription);
|
||||||
prescriptionList.add(prescriptionList.size()-1, currentPrescription);
|
prescriptionList.add(prescriptionList.size(), currentPrescription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,6 +501,7 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||||
int position = viewHolder.getBindingAdapterPosition();
|
int position = viewHolder.getBindingAdapterPosition();
|
||||||
|
|
||||||
|
@ -510,8 +520,6 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Snackbar.make(recyclerView, prescription.getName(),
|
Snackbar.make(recyclerView, prescription.getName(),
|
||||||
Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() {
|
Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -581,7 +589,7 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
* SimpleItemRecyclerViewAdapter
|
* SimpleItemRecyclerViewAdapter
|
||||||
*/
|
*/
|
||||||
public class RecyclerViewAdapter extends
|
public class RecyclerViewAdapter extends
|
||||||
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
|
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final List<Prescription> mValues;
|
private final List<Prescription> mValues;
|
||||||
|
|
||||||
|
@ -627,7 +635,6 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
holder.mContentView.setText(mValues.get(position).getName());
|
holder.mContentView.setText(mValues.get(position).getName());
|
||||||
holder.mEndOfStock.setText(dateEndOfStock);
|
holder.mEndOfStock.setText(dateEndOfStock);
|
||||||
|
|
||||||
|
|
||||||
// Test to change background programmatically
|
// Test to change background programmatically
|
||||||
if (mValues.get(position).getTake() == 0) {
|
if (mValues.get(position).getTake() == 0) {
|
||||||
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
|
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
|
||||||
|
@ -672,7 +679,6 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue