Created
August 11, 2015 15:37
-
-
Save rclements/313581d8e98b6b37a78a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class PrescriptionAdapter extends ArrayAdapter<Prescription> { | |
PrescriptionAdapter(Prescription[] prescriptions) { | |
super(PrescriptionActivity.this, R.layout.prescription_list_row, R.id.prescription_name, prescriptions); | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
convertView = super.getView(position, convertView, parent); | |
final Prescription prescription = getItem(position); | |
TextView prescriptionName = (TextView)convertView.findViewById(R.id.prescription_name); | |
prescriptionName.setText(prescription.name); | |
TextView prescriptionDosage = (TextView)convertView.findViewById(R.id.prescription_dosage_measurement); | |
prescriptionDosage.setText(prescription.dosageMeasurement); | |
TextView prescriptionDescription = (TextView)convertView.findViewById(R.id.prescription_description); | |
if(prescription.isOtc.equals("true")) { | |
prescriptionDescription.setText(prescription.dosage + " OTC Dispensed"); | |
} else { | |
prescriptionDescription.setText(prescription.description); | |
} | |
TextView prescriptionDoses = (TextView)convertView.findViewById(R.id.prescription_doses); | |
Log.d(TAG, "remaining doses: " + prescription.getRemainingDoses()); | |
prescriptionDoses.setText("" + prescription.getRemainingDoses()); | |
final DatabaseHelper db = new DatabaseHelper(PrescriptionActivity.this); | |
Log.v(TAG, "Prescription ID: " + prescription._id); | |
Log.v(TAG, "Outside Flag Button: " + R.id.flag_button); | |
Log.v(TAG, "Flag present? " + db.prescriptionHasFlag(prescription._id)); | |
if(db.prescriptionHasFlag(prescription._id)) { | |
Log.v(TAG, "FLAG Prescription ID: " + prescription._id); | |
Log.v(TAG, "Inside Flag Button: " + R.id.flag_button); | |
ImageView flagImage = (ImageView)convertView.findViewById(R.id.flag_button); | |
final int yellow = Color.YELLOW; | |
flagImage.setBackgroundColor(yellow); | |
} | |
final Button acceptButton = (Button) convertView.findViewById(R.id.accept_button); | |
final Button rejectButton = (Button) convertView.findViewById(R.id.reject_button); | |
final int gray = Color.GRAY; | |
final int green = Color.GREEN; | |
final int red = Color.RED; | |
rejectButton.setBackgroundColor(gray); | |
acceptButton.setBackgroundColor(gray); | |
if(prescription.accepted.equals("true")) { | |
acceptButton.setSelected(true); | |
rejectButton.setSelected(false); | |
acceptButton.setBackgroundColor(green); | |
} else { | |
acceptButton.setSelected(false); | |
rejectButton.setSelected(true); | |
rejectButton.setBackgroundColor(red); | |
} | |
acceptButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
acceptButton.setSelected(!acceptButton.isSelected()); | |
prescription.accepted = "true"; | |
db.updatePrescription(prescription); | |
if (acceptButton.isSelected()) { | |
if (rejectButton.isSelected()) { | |
rejectButton.setSelected(false); | |
} | |
v.setBackgroundColor(green); | |
rejectButton.setBackgroundColor(gray); | |
} else { | |
v.setBackgroundColor(gray); | |
} | |
} | |
}); | |
rejectButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
rejectButton.setSelected(!rejectButton.isSelected()); | |
prescription.accepted = "false"; | |
db.updatePrescription(prescription); | |
if (rejectButton.isSelected()) { | |
if (acceptButton.isSelected()) { | |
acceptButton.setSelected(false); | |
} | |
v.setBackgroundColor(red); | |
acceptButton.setBackgroundColor(gray); | |
} else { | |
v.setBackgroundColor(gray); | |
} | |
} | |
}); | |
return convertView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment