Skip to content

Commit

Permalink
Merge pull request #22 from AdamG95/fix-the-bugs
Browse files Browse the repository at this point in the history
Fix the bugs
  • Loading branch information
AdamGuidarini authored Nov 17, 2022
2 parents 7aecaaa + 4f5a8a2 commit 21f8b55
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.switchmaterial.SwitchMaterial;
Expand All @@ -32,6 +30,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Objects;

import projects.medicationtracker.Helpers.DBHelper;
Expand All @@ -58,9 +57,7 @@ public class AddEditFormFragment extends Fragment
private Medication medication;
private View rootView;

private RadioGroup patientGroup;
private RadioButton meButton;
private RadioButton otherButton;
private TextInputLayout patientNameInputLayout;
private MaterialAutoCompleteTextView patientNameInput;

Expand All @@ -75,7 +72,6 @@ public class AddEditFormFragment extends Fragment
private EditText dosageUnitsInput;

private TextInputLayout frequencyDropdownLayout;
private MaterialAutoCompleteTextView frequencyDropDown;
private TextInputLayout numberOfTimersPerDayLayout;
private EditText dailyMedTime;
private EditText dailyMedStartDate;
Expand All @@ -92,8 +88,6 @@ public class AddEditFormFragment extends Fragment
private int selectedFrequencyTypeIndex = -1;
private ArrayList<String> timeUnits;

private MaterialButton saveButton;

public AddEditFormFragment() { }

/**
Expand Down Expand Up @@ -171,9 +165,9 @@ private void setPatientCard()
{
ArrayAdapter<String> patientNamesAdapter;
ArrayList<String> patientNames;
patientGroup = rootView.findViewById(R.id.patientRadioGroup);
RadioGroup patientGroup = rootView.findViewById(R.id.patientRadioGroup);
meButton = rootView.findViewById(R.id.patientIsMe);
otherButton = rootView.findViewById(R.id.patientIsNotMe);
RadioButton otherButton = rootView.findViewById(R.id.patientIsNotMe);
patientNameInput = rootView.findViewById(R.id.patientNameInput);
patientNameInputLayout = rootView.findViewById(R.id.patientNameInputLayout);

Expand Down Expand Up @@ -280,7 +274,15 @@ public void afterTextChanged(Editable editable)
aliasInput.setText(medication.getAlias());
}

dosageAmountInput.setText(String.valueOf(medication.getMedDosage()));
if (medication.getMedDosage() == (int) medication.getMedDosage())
{
dosageAmountInput.setText(String.format(Locale.getDefault(), "%d", (int) medication.getMedDosage()));
}
else
{
dosageAmountInput.setText(String.valueOf(medication.getMedDosage()));
}

dosageUnitsInput.setText(medication.getMedDosageUnits());
}
}
Expand All @@ -290,14 +292,14 @@ public void afterTextChanged(Editable editable)
*/
private void setFrequencyCard()
{
RelativeLayout dailyLayout = rootView.findViewById(R.id.dailyMedFrequency);
LinearLayout dailyLayout = rootView.findViewById(R.id.dailyMedFrequency);
LinearLayout multiplePerDay = rootView.findViewById(R.id.multiplePerDayFrequency);
LinearLayout custom = rootView.findViewById(R.id.customFrequencyLayout);
ArrayAdapter<String> frequencyOptions;
ArrayList<String> options = new ArrayList<>();

frequencyDropdownLayout = rootView.findViewById(R.id.frequencyDropdownLayout);
frequencyDropDown = rootView.findViewById(R.id.frequencyOptionsDropdown);
MaterialAutoCompleteTextView frequencyDropDown = rootView.findViewById(R.id.frequencyOptionsDropdown);

frequencyDropDown.setShowSoftInputOnFocus(false);

Expand Down Expand Up @@ -691,12 +693,9 @@ else if (freq % 60 == 0)
*/
private void setSaveButton()
{
saveButton = rootView.findViewById(R.id.saveButton);
MaterialButton saveButton = rootView.findViewById(R.id.saveButton);

saveButton.setOnClickListener((view ->
{
saveMedication();
}));
saveButton.setOnClickListener((view -> saveMedication()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Locale;

import kotlin.Triple;
import projects.medicationtracker.Helpers.DBHelper;
import projects.medicationtracker.Helpers.TextViewUtils;
import projects.medicationtracker.Helpers.TimeFormatting;
Expand All @@ -31,7 +33,6 @@
*/
public class MedicationScheduleFragment extends Fragment
{

// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
public static final String MEDICATIONS = "medications";
public static final String DAY_OF_WEEK = "dayOfWeek";
Expand Down Expand Up @@ -139,12 +140,23 @@ private void createSchedule(View rootView)
{
CheckBox thisMedication = new CheckBox(rootView.getContext());
long medId = medication.getMedId();
Pair<Long, LocalDateTime> tag;
// Pair<Long, LocalDateTime> tag;
Triple<Medication, Long, LocalDateTime> tag;

// Set Checkbox label
String medName = medication.getMedName();
String dosage =
medication.getMedDosage() + " " + medication.getMedDosageUnits();
String dosage;
if (medication.getMedDosage() == (int) medication.getMedDosage())
{
dosage = String.format(Locale.getDefault(), "%d", (int) medication.getMedDosage());
}
else
{
dosage = String.valueOf(medication.getMedDosage());
}

dosage += " " + medication.getMedDosageUnits();

String dosageTime =
TimeFormatting.formatTimeForUser(time.getHour(), time.getMinute());

Expand All @@ -155,7 +167,8 @@ private void createSchedule(View rootView)
// if it is, get the DoseId
long rowid = db.getDoseId(medId, TimeFormatting.localDateTimeToString(time));

tag = Pair.create(rowid, time);
// tag = Pair.create(rowid, time);
tag = new Triple<>(medication, rowid, time);

thisMedication.setTag(tag);

Expand All @@ -164,9 +177,9 @@ private void createSchedule(View rootView)

thisMedication.setOnCheckedChangeListener((compoundButton, b) ->
{
Pair<Long, LocalDateTime> tvTag =
(Pair<Long, LocalDateTime>) thisMedication.getTag();
final Long doseId = tvTag.first;
Triple<Medication, Long, LocalDateTime> tvTag =
(Triple<Medication, Long, LocalDateTime>) thisMedication.getTag();
final Long doseId = tvTag.getSecond();
int timeBeforeDose = db.getTimeBeforeDose();

if (
Expand Down Expand Up @@ -194,8 +207,8 @@ private void createSchedule(View rootView)
else
{
long id = db.addToMedicationTracker(
medication,
tvTag.second
tvTag.getFirst(),
tvTag.getThird()
);

db.updateDoseStatus(
Expand Down Expand Up @@ -239,25 +252,24 @@ private void sortMedicationCheckBoxes(LinearLayoutCompat parentLayout)
CheckBox child1 = (CheckBox) parentLayout.getChildAt(j);
CheckBox child2 = (CheckBox) parentLayout.getChildAt(j + 1);

Pair<Long, LocalDateTime> child1Pair = (Pair<Long, LocalDateTime>) child1.getTag();
Pair<Long, LocalDateTime> child2Pair = (Pair<Long, LocalDateTime>) child2.getTag();
Triple<Medication, Long, LocalDateTime> child1Pair = (Triple<Medication, Long, LocalDateTime>) child1.getTag();
Triple<Medication, Long, LocalDateTime> child2Pair = (Triple<Medication, Long, LocalDateTime>) child2.getTag();

LocalDateTime child1Time = child1Pair.second;
LocalDateTime child2Time = child2Pair.second;
LocalDateTime child1Time = child1Pair.getThird();
LocalDateTime child2Time = child2Pair.getThird();

if (child1Time != null && child1Time.isAfter(child2Time))
{
CheckBox temp = new CheckBox(parentLayout.getContext());
temp.setText(child1.getText());
temp.setTag(child1.getTag());
temp.setChecked(child1.isChecked());

child1.setText(child2.getText());
child1.setTag(child2.getTag());
child1.setTag(child1.getTag());
child1.setChecked(child2.isChecked());

child2.setText(temp.getText());
child2.setTag(temp.getTag());
child2.setTag(child2.getTag());
child2.setChecked(temp.isChecked());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Locale;

import projects.medicationtracker.EditMedication;
import projects.medicationtracker.Helpers.DBHelper;
Expand Down Expand Up @@ -79,6 +80,7 @@ private void insertMedicationData(long medId, View v)
Medication medication = db.getMedication(medId);
LocalTime[] times = db.getMedicationTimes(medId);
LocalDateTime[] dateTimes = new LocalDateTime[times.length];
String dosageVal;

name = v.findViewById(R.id.myMedCardMedicationName);
dosage = v.findViewById(R.id.myMedCardDosage);
Expand All @@ -95,8 +97,17 @@ private void insertMedicationData(long medId, View v)

medication.setTimes(dateTimes);

if (medication.getMedDosage() == (int) medication.getMedDosage())
{
dosageVal = String.format(Locale.getDefault(), "%d", (int) medication.getMedDosage());
}
else
{
dosageVal = String.valueOf(medication.getMedDosage());
}

name.setText("Medication name: " + medication.getMedName());
dosage.setText("Dosage: " + medication.getMedDosage() + " " + medication.getMedDosageUnits());
dosage.setText("Dosage: " + dosageVal + " " + medication.getMedDosageUnits());

StringBuilder freqLabel;

Expand Down
Loading

0 comments on commit 21f8b55

Please sign in to comment.