Skip to content

Commit

Permalink
Merge pull request #40 from RUGSoftEng/rriesebos
Browse files Browse the repository at this point in the history
Rriesebos
  • Loading branch information
RoelBrandenburg authored Apr 29, 2018
2 parents 557487a + 7051c8d commit 241e0c5
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 36 deletions.
Binary file modified TuberculosisApp/.idea/caches/build_file_checksums.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ public View getView(int position, View view, @NonNull ViewGroup parent) {
if (eventDays.get(date) != null) {
// Mark this day for event
pillIndicator.setImageResource(R.drawable.ic_medication);
if (month < today.getMonth() || (month == today.getMonth() && day < today.getDate())) {
if (month < today.getMonth() || (month == today.getMonth() && day <= today.getDate())) {
// Set green check mark here
//TODO: takenOverlay.setImageResource(R.drawable.ic_check);
textDayNumber.setTextColor(view.getResources().getColor(android.R.color.holo_green_dark));
takenOverlay.setImageResource(R.drawable.ic_check);
//textDayNumber.setTextColor(view.getResources().getColor(android.R.color.holo_green_dark));
for (Medication medication : eventDays.get(date)) {
if (!medication.getTaken()) {
// Not taken, add red cross
//TODO: takenOverlay.setImageResource(R.drawable.ic_cross);
textDayNumber.setTextColor(view.getResources().getColor(android.R.color.holo_red_dark));
if (day < today.getDate()) {
takenOverlay.setImageResource(R.drawable.ic_cross);
takenOverlay.setAlpha((float)0.75);
} else {
takenOverlay.setImageResource(0);
}
//textDayNumber.setTextColor(view.getResources().getColor(android.R.color.holo_red_dark));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void onItemClick(AdapterView<?> view, View cell, int position, long id) {
ArrayList<Medication> medicationList = mEvents.get(clickedItem);
if (mEvents != null && medicationList != null) {
ViewDayFragment viewDayFragment = new ViewDayFragment();
viewDayFragment.setCalendarView(CalendarView.this);
viewDayFragment.setDate(clickedItem);
viewDayFragment.setMedicationList(medicationList);
viewDayFragment.show(mActivity.getFragmentManager(), "ViewDayFragment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ private void initializeMedication() {
events = new HashMap<>();
ArrayList<Medication> medicationList = new ArrayList<>();
ArrayList<Medication> medicationList2 = new ArrayList<>();
ArrayList<Medication> medicationList3 = new ArrayList<>();
Time time1 = new Time(8, 0);
Time time2 = new Time(16, 30);

medicationList.add(new Medication("Rifampicin", time1, 1, true));
medicationList.add(new Medication("Isoniazid", time1, 2, false));
medicationList.add(new Medication("Pyrazinamide", time1, 1, false));
medicationList.add(new Medication("Ethambutol", time2, 2, false));

medicationList2.add(new Medication("Rifampicin", time1, 1, true));
medicationList2.add(new Medication("Isoniazid", time1, 2, false));
medicationList2.add(new Medication("Pyrazinamide", time1, 1, false));
medicationList2.add(new Medication("Ethambutol", time2, 2, false));

medicationList3.add(new Medication("Rifampicin", time1, 1, true));
medicationList3.add(new Medication("Ethambutol", time2, 2, false));


Calendar cal = new GregorianCalendar(2018, 3, 9);
events.put(new Date(cal.getTimeInMillis()), medicationList);
cal.set(2018, 4, 1);
events.put(new Date(cal.getTimeInMillis()), medicationList);
cal.set(2018, 3, 22);
events.put(new Date(cal.getTimeInMillis()), medicationList);

cal.set(2018, 3, 21);
events.put(new Date(cal.getTimeInMillis()), medicationList2);
cal.set(2018, 2, 14);
events.put(new Date(cal.getTimeInMillis()), medicationList2);
cal.set(2018, 2, 15);
cal.set(2018, 3, 28);
events.put(new Date(cal.getTimeInMillis()), medicationList2);
cal.set(2018, 2, 23);
events.put(new Date(cal.getTimeInMillis()), medicationList3);
cal.set(2018, 3, 31);
events.put(new Date(cal.getTimeInMillis()), medicationList3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.view.ViewGroup;
import android.view.ViewManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

Expand All @@ -20,11 +19,11 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;

public class ViewDayFragment extends DialogFragment {

private CalendarView calendarView;
private Date date;
private ArrayList<Medication> medicationList;
private MedicationListAdapter adapter;
Expand Down Expand Up @@ -70,6 +69,10 @@ public void onClick(View v) {
return view;
}

public void setCalendarView(CalendarView calendarView) {
this.calendarView = calendarView;
}

public void setDate(Date date) {
this.date = date;
}
Expand All @@ -80,11 +83,11 @@ public void setMedicationList(ArrayList<Medication> medicationList) {

private void saveNewMedicineStates() {
// Set medicine taken states to respective checkbox states
HashMap<Medication, CheckBox> takenCheckBoxes = adapter.getTakenCheckBoxes();
for (Medication medication : medicationList) {
medication.setTaken(takenCheckBoxes.get(medication).isChecked());
medication.setTaken(adapter.isChecked(medication));
// TODO: Add API call to update taken state in database
}
calendarView.updateCalendar();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public void setTaken(boolean taken) {
isTaken = taken;
}

@Override
public String toString() {
return "Name: " + name + ", Time: " + time.toString() + ", Dose: " + dose + ", isTaken: " + isTaken;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.rugged.tuberculosisapp.R;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class MedicationListAdapter extends ArrayAdapter<Medication> {
public class MedicationListAdapter extends ArrayAdapter<Medication> implements CompoundButton.OnCheckedChangeListener {

private Context mContext;
private int mResourceId;
private final List<Medication> mMedication;
private Date date;
private HashMap<Medication, CheckBox> takenCheckBoxes;
public SparseBooleanArray mCheckedStates;

// User has x days to change the taken state of medicines before it is locked
private static final int DAYS_UNTIL_CHECKBOX_IS_LOCKED = 1;
Expand All @@ -41,7 +42,7 @@ public MedicationListAdapter(Context context, int resourceId, List<Medication> m
this.mResourceId = resourceId;
this.mMedication = medication;
this.date = date;
this.takenCheckBoxes = new HashMap<>();
this.mCheckedStates = new SparseBooleanArray();
}


Expand Down Expand Up @@ -88,10 +89,10 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
medicationName.setTextColor(mContext.getResources().getColor(android.R.color.holo_red_dark));
}

// Update checkbox state and link it to the medication
// TODO: maybe override equals method in medication, shouldn't be necessary though
// Attach listener, update checkbox state
takenCheckBox.setOnCheckedChangeListener(this);
takenCheckBox.setTag(position);
takenCheckBox.setChecked(isTaken);
takenCheckBoxes.put(medication, takenCheckBox);
}

// Lock checkbox after a certain amount of days or if date is in the future
Expand All @@ -107,8 +108,13 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
return convertView;
}

public HashMap<Medication, CheckBox> getTakenCheckBoxes() {
return takenCheckBoxes;
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mCheckedStates.put((Integer)compoundButton.getTag(), b);
}

public boolean isChecked(Medication medication) {
return mCheckedStates.get(getPosition(medication));
}

public Boolean checkBoxesAreLocked(Date date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public Time(int hour, int minute) {
public String toString() {
return hour + ":" + (minute > 9 ? minute : "0" + minute);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:id="@+id/textDayNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:text="12"
android:textAppearance="@android:style/TextAppearance.Medium" />

<ImageView
Expand All @@ -32,9 +32,10 @@

<ImageView
android:id="@+id/takenOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="28dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true" />
android:adjustViewBounds="true"
android:alpha=".90" />

</FrameLayout>
2 changes: 1 addition & 1 deletion TuberculosisApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 241e0c5

Please sign in to comment.