From ab37374ee93580430d99143687d97e0be594c1c6 Mon Sep 17 00:00:00 2001 From: Adam Guidarini <45023561+AdamG95@users.noreply.github.com> Date: Sun, 13 Nov 2022 16:40:31 -0600 Subject: [PATCH 1/5] Fixed add/edit med ivew sizes on non-pixels --- .../Fragments/AddEditFormFragment.java | 7 +- .../res/layout/fragment_add_edit_form.xml | 365 +++++++++++------- 2 files changed, 222 insertions(+), 150 deletions(-) diff --git a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java index 90b3452f..59f8943e 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java @@ -290,7 +290,7 @@ 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 frequencyOptions; @@ -693,10 +693,7 @@ private void setSaveButton() { saveButton = rootView.findViewById(R.id.saveButton); - saveButton.setOnClickListener((view -> - { - saveMedication(); - })); + saveButton.setOnClickListener((view -> saveMedication())); } /** diff --git a/app/src/main/res/layout/fragment_add_edit_form.xml b/app/src/main/res/layout/fragment_add_edit_form.xml index 3b507b49..feff7fa9 100644 --- a/app/src/main/res/layout/fragment_add_edit_form.xml +++ b/app/src/main/res/layout/fragment_add_edit_form.xml @@ -133,43 +133,59 @@ android:hint="@string/alias_for_medication"/> - - + - - + android:layout_marginBottom="15dp" + android:layout_alignParentStart="true" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> - + + + - - - + + + + + + + + + @@ -209,48 +225,63 @@ android:inputType="none"/> - - - - - + + - + android:layout_alignParentStart="true" + android:layout_marginBottom="15dp" + android:hint="@string/start_date" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> - + + + + + android:layout_marginStart="5dp" + android:layout_weight="1"> - - - + android:layout_alignParentEnd="true" + android:hint="@string/taken_at" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> + + + + + + - - + - - - - + android:layout_alignParentStart="true" + android:hint="@string/start_date" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> + + + + + + - - - + + + + + + - - + android:layout_marginEnd="5dp" + android:layout_weight="1"> - - - - + + + + + + + android:layout_marginStart="5dp" + android:layout_weight="1"> - - - + android:layout_alignParentEnd="true" + android:hint="@string/taken_at" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> - + + + + + + - + android:layout_marginEnd="5dp" + android:layout_weight="1"> - - - - + + + + + + + android:layout_marginStart="5dp" + android:layout_weight="1"> - - - + android:layout_alignParentEnd="true" + android:hint="@string/unit_of_time" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"> + + + + + From 881063592539f027ec67724e52626926dab97c75 Mon Sep 17 00:00:00 2001 From: Adam Guidarini <45023561+AdamG95@users.noreply.github.com> Date: Sun, 13 Nov 2022 16:46:30 -0600 Subject: [PATCH 2/5] Update AddEditFormFragment.java --- .../Fragments/AddEditFormFragment.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java index 59f8943e..caf0215b 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java @@ -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; @@ -58,9 +56,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; @@ -75,7 +71,6 @@ public class AddEditFormFragment extends Fragment private EditText dosageUnitsInput; private TextInputLayout frequencyDropdownLayout; - private MaterialAutoCompleteTextView frequencyDropDown; private TextInputLayout numberOfTimersPerDayLayout; private EditText dailyMedTime; private EditText dailyMedStartDate; @@ -92,8 +87,6 @@ public class AddEditFormFragment extends Fragment private int selectedFrequencyTypeIndex = -1; private ArrayList timeUnits; - private MaterialButton saveButton; - public AddEditFormFragment() { } /** @@ -171,9 +164,9 @@ private void setPatientCard() { ArrayAdapter patientNamesAdapter; ArrayList 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); @@ -297,7 +290,7 @@ private void setFrequencyCard() ArrayList 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); @@ -691,7 +684,7 @@ 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())); } From 409d7861f0e11953b76627cb07fbb89455745e75 Mon Sep 17 00:00:00 2001 From: Adam Guidarini <45023561+AdamG95@users.noreply.github.com> Date: Sun, 13 Nov 2022 17:48:50 -0600 Subject: [PATCH 3/5] Float dosage formatting fixed --- .../Fragments/AddEditFormFragment.java | 11 ++++++++++- .../Fragments/MedicationScheduleFragment.java | 15 +++++++++++++-- .../Fragments/MyMedicationsFragment.java | 13 ++++++++++++- .../medicationtracker/Helpers/DBHelper.java | 2 +- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java index caf0215b..bd3f21ae 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/AddEditFormFragment.java @@ -30,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; @@ -273,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()); } } diff --git a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java index 38aa633e..c6476d09 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java @@ -17,6 +17,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Locale; import projects.medicationtracker.Helpers.DBHelper; import projects.medicationtracker.Helpers.TextViewUtils; @@ -143,8 +144,18 @@ private void createSchedule(View rootView) // 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 += medication.getMedDosage(); + } + + dosage += " " + medication.getMedDosageUnits(); + String dosageTime = TimeFormatting.formatTimeForUser(time.getHour(), time.getMinute()); diff --git a/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java index e313a226..a7c22d5b 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java @@ -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; @@ -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); @@ -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; diff --git a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java index 6d46509e..62632845 100644 --- a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java +++ b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java @@ -438,7 +438,7 @@ public Medication getMedication(long id) cursor.getColumnIndex(START_DATE))); long medId = Long.parseLong(cursor.getString(cursor.getColumnIndex(MED_ID))); long frequency = Long.parseLong(cursor.getString(cursor.getColumnIndex(MED_FREQUENCY))); - int dosage = Integer.parseInt(cursor.getString(cursor.getColumnIndex(MED_DOSAGE))); + float dosage = Float.parseFloat(cursor.getString(cursor.getColumnIndex(MED_DOSAGE))); String alias = cursor.getString(cursor.getColumnIndex(ALIAS)); LocalDateTime[] times = new LocalDateTime[0]; From 9496121b2f5f9c08d00f958ccacf353f258aad21 Mon Sep 17 00:00:00 2001 From: Adam Guidarini <45023561+AdamG95@users.noreply.github.com> Date: Tue, 15 Nov 2022 22:35:56 -0600 Subject: [PATCH 4/5] Fixed sorting bug --- .../Fragments/MedicationScheduleFragment.java | 37 ++++---- .../medicationtracker/Helpers/DBHelper.java | 90 ++++++++----------- .../Receivers/EventReceiver.java | 2 - 3 files changed, 58 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java index c6476d09..c7e4160d 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java @@ -19,6 +19,7 @@ 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; @@ -32,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"; @@ -140,18 +140,19 @@ private void createSchedule(View rootView) { CheckBox thisMedication = new CheckBox(rootView.getContext()); long medId = medication.getMedId(); - Pair tag; +// Pair tag; + Triple tag; // Set Checkbox label String medName = medication.getMedName(); - String dosage = ""; + String dosage; if (medication.getMedDosage() == (int) medication.getMedDosage()) { - dosage += String.format(Locale.getDefault(), "%d", (int) medication.getMedDosage()); + dosage = String.format(Locale.getDefault(), "%d", (int) medication.getMedDosage()); } else { - dosage += medication.getMedDosage(); + dosage = String.valueOf(medication.getMedDosage()); } dosage += " " + medication.getMedDosageUnits(); @@ -166,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); @@ -175,9 +177,9 @@ private void createSchedule(View rootView) thisMedication.setOnCheckedChangeListener((compoundButton, b) -> { - Pair tvTag = - (Pair) thisMedication.getTag(); - final Long doseId = tvTag.first; + Triple tvTag = + (Triple) thisMedication.getTag(); + final Long doseId = tvTag.getSecond(); int timeBeforeDose = db.getTimeBeforeDose(); if ( @@ -205,8 +207,8 @@ private void createSchedule(View rootView) else { long id = db.addToMedicationTracker( - medication, - tvTag.second + tvTag.getFirst(), + tvTag.getThird() ); db.updateDoseStatus( @@ -250,25 +252,24 @@ private void sortMedicationCheckBoxes(LinearLayoutCompat parentLayout) CheckBox child1 = (CheckBox) parentLayout.getChildAt(j); CheckBox child2 = (CheckBox) parentLayout.getChildAt(j + 1); - Pair child1Pair = (Pair) child1.getTag(); - Pair child2Pair = (Pair) child2.getTag(); + Triple child1Pair = (Triple) child1.getTag(); + Triple child2Pair = (Triple) 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()); } } diff --git a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java index 62632845..fa0fe492 100644 --- a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java +++ b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java @@ -219,7 +219,6 @@ public long addDoseTime(long medId, String drugTime) * Creates an ArrayList of all patients * @return ArrayList of all patients, except **************************************************************************/ - @SuppressLint("Range") public ArrayList getPatients() { SQLiteDatabase db = this.getReadableDatabase(); @@ -233,7 +232,7 @@ public ArrayList getPatients() while (!result.isAfterLast()) { - patients.add(result.getString(result.getColumnIndex(PATIENT_NAME))); + patients.add(result.getString(result.getColumnIndexOrThrow(PATIENT_NAME))); result.moveToNext(); } @@ -247,7 +246,6 @@ public ArrayList getPatients() * @param patient The name of the patient whose Medications are sought * @return An ArrayList of all Medications for given patient */ - @SuppressLint("Range") public ArrayList getMedicationsForPatient(String patient) { SQLiteDatabase db = this.getReadableDatabase(); @@ -260,13 +258,13 @@ public ArrayList getMedicationsForPatient(String patient) while (!cursor.isAfterLast()) { - int medId = Integer.parseInt(cursor.getString(cursor.getColumnIndex(MED_ID))); - int dosage = Integer.parseInt(cursor.getString(cursor.getColumnIndex(MED_DOSAGE))); - int freq = Integer.parseInt(cursor.getString(cursor.getColumnIndex(MED_FREQUENCY))); - String medName = cursor.getString(cursor.getColumnIndex(MED_NAME)); - String units = cursor.getString(cursor.getColumnIndex(MED_UNITS)); - String startDateStr = cursor.getString(cursor.getColumnIndex(START_DATE)); - String alias = cursor.getString(cursor.getColumnIndex(ALIAS)); + int medId = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MED_ID))); + int dosage = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MED_DOSAGE))); + int freq = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MED_FREQUENCY))); + String medName = cursor.getString(cursor.getColumnIndexOrThrow(MED_NAME)); + String units = cursor.getString(cursor.getColumnIndexOrThrow(MED_UNITS)); + String startDateStr = cursor.getString(cursor.getColumnIndexOrThrow(START_DATE)); + String alias = cursor.getString(cursor.getColumnIndexOrThrow(ALIAS)); LocalDateTime startDate = TimeFormatting.stringToLocalDateTime(startDateStr); @@ -290,7 +288,7 @@ public ArrayList getMedicationsForPatient(String patient) for (int i = 0; i < count; i++) { - LocalTime lt = LocalTime.parse(cursor1.getString(cursor1.getColumnIndex(DRUG_TIME))); + LocalTime lt = LocalTime.parse(cursor1.getString(cursor1.getColumnIndexOrThrow(DRUG_TIME))); timesArr.add(LocalDateTime.of(LocalDate.MIN, lt)); @@ -337,7 +335,6 @@ public long numberOfRows() * Create ArrayList of all Medications in MedicationTable * @return All Medications in MedicationTable **************************************************************************/ - @SuppressLint("Range") public ArrayList getMedications() { SQLiteDatabase db = this.getReadableDatabase(); @@ -351,14 +348,14 @@ public ArrayList getMedications() // Iterates through cursors to create instances of Medication object while (!meds.isAfterLast()) { - int medId = Integer.parseInt(meds.getString(meds.getColumnIndex(MED_ID))); - float dosage = Float.parseFloat(meds.getString(meds.getColumnIndex(MED_DOSAGE))); - int frequency = Integer.parseInt(meds.getString(meds.getColumnIndex(MED_FREQUENCY))); - String medName = meds.getString(meds.getColumnIndex(MED_NAME)); - String patient = meds.getString(meds.getColumnIndex(PATIENT_NAME)); - String units = meds.getString(meds.getColumnIndex(MED_UNITS)); - String date1 = meds.getString(meds.getColumnIndex(START_DATE)); - String alias = meds.getString(meds.getColumnIndex(ALIAS)); + int medId = Integer.parseInt(meds.getString(meds.getColumnIndexOrThrow(MED_ID))); + float dosage = Float.parseFloat(meds.getString(meds.getColumnIndexOrThrow(MED_DOSAGE))); + int frequency = Integer.parseInt(meds.getString(meds.getColumnIndexOrThrow(MED_FREQUENCY))); + String medName = meds.getString(meds.getColumnIndexOrThrow(MED_NAME)); + String patient = meds.getString(meds.getColumnIndexOrThrow(PATIENT_NAME)); + String units = meds.getString(meds.getColumnIndexOrThrow(MED_UNITS)); + String date1 = meds.getString(meds.getColumnIndexOrThrow(START_DATE)); + String alias = meds.getString(meds.getColumnIndexOrThrow(ALIAS)); LocalDateTime startDate = TimeFormatting.stringToLocalDateTime(date1); @@ -381,7 +378,7 @@ public ArrayList getMedications() for (int i = 0; i < count; i++) { - @SuppressLint("Range") LocalTime lt = LocalTime.parse(cursor.getString(cursor.getColumnIndex(DRUG_TIME))); + LocalTime lt = LocalTime.parse(cursor.getString(cursor.getColumnIndexOrThrow(DRUG_TIME))); timesArr.add(LocalDateTime.of(LocalDate.MIN, lt)); @@ -420,7 +417,6 @@ public ArrayList getMedications() * @param id The ID of the Medication * @return Medication retrieved from database **************************************************************************/ - @SuppressLint("Range") public Medication getMedication(long id) { SQLiteDatabase db =this.getReadableDatabase(); @@ -431,15 +427,15 @@ public Medication getMedication(long id) cursor.moveToFirst(); - String medName = cursor.getString(cursor.getColumnIndex(MED_NAME)); - String patient = cursor.getString(cursor.getColumnIndex(PATIENT_NAME)); - String units = cursor.getString(cursor.getColumnIndex(MED_UNITS)); + String medName = cursor.getString(cursor.getColumnIndexOrThrow(MED_NAME)); + String patient = cursor.getString(cursor.getColumnIndexOrThrow(PATIENT_NAME)); + String units = cursor.getString(cursor.getColumnIndexOrThrow(MED_UNITS)); LocalDateTime startDate = TimeFormatting.stringToLocalDateTime(cursor.getString( - cursor.getColumnIndex(START_DATE))); - long medId = Long.parseLong(cursor.getString(cursor.getColumnIndex(MED_ID))); - long frequency = Long.parseLong(cursor.getString(cursor.getColumnIndex(MED_FREQUENCY))); - float dosage = Float.parseFloat(cursor.getString(cursor.getColumnIndex(MED_DOSAGE))); - String alias = cursor.getString(cursor.getColumnIndex(ALIAS)); + cursor.getColumnIndexOrThrow(START_DATE))); + long medId = Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(MED_ID))); + long frequency = Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(MED_FREQUENCY))); + float dosage = Float.parseFloat(cursor.getString(cursor.getColumnIndexOrThrow(MED_DOSAGE))); + String alias = cursor.getString(cursor.getColumnIndexOrThrow(ALIAS)); LocalDateTime[] times = new LocalDateTime[0]; @@ -469,7 +465,7 @@ public LocalTime[] getMedicationTimes(long id) for (int i = 0; i < cursor.getCount(); i++) { - final String time = cursor.getString(cursor.getColumnIndex(DRUG_TIME)); + final String time = cursor.getString(cursor.getColumnIndexOrThrow(DRUG_TIME)); times[i] = LocalTime.parse(time); cursor.moveToNext(); } @@ -545,7 +541,7 @@ public void updateMedication(Medication medication) for (int i = maxIndex; i < oldTimes.length; i++) { String oldTimeAsString = oldTimes[i].toString(); - String whereClause = DRUG_TIME + "=\"" + oldTimeAsString + "\" AND " + MED_ID + String whereClause = DRUG_TIME + "='" + oldTimeAsString + "' AND " + MED_ID + "=" + medication.getMedId(); db.delete(MEDICATION_TIMES, whereClause, null); @@ -624,7 +620,6 @@ public long addToMedicationTracker(Medication medication, LocalDateTime time) * @param doseTime Time of dose * @return Dose ID of match found in MedicationTracker table **************************************************************************/ - @SuppressLint("Range") public long getDoseId(long medId, String doseTime) { SQLiteDatabase db = this.getReadableDatabase(); @@ -637,14 +632,13 @@ public long getDoseId(long medId, String doseTime) cursor.moveToFirst(); rowId = cursor.getCount() > 0 ? - Integer.parseInt(cursor.getString(cursor.getColumnIndex(DOSE_ID))) : -1; + Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(DOSE_ID))) : -1; cursor.close(); return rowId; } - @SuppressLint("Range") public long getMedicationIdFromTimeId(long timeId) { SQLiteDatabase db = this.getReadableDatabase(); @@ -657,7 +651,7 @@ public long getMedicationIdFromTimeId(long timeId) cursor.moveToFirst(); - rowId = Integer.parseInt(cursor.getString(cursor.getColumnIndex(DOSE_ID))); + rowId = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(DOSE_ID))); cursor.close(); return rowId; @@ -668,7 +662,6 @@ public long getMedicationIdFromTimeId(long timeId) * @param doseId ID of dose in table * @return Status of dose **************************************************************************/ - @SuppressLint("Range") public boolean getTaken(long doseId) { SQLiteDatabase db = this.getReadableDatabase(); @@ -678,7 +671,7 @@ public boolean getTaken(long doseId) Cursor cursor = db.rawQuery(query, null); cursor.moveToFirst(); - int taken = Integer.parseInt(cursor.getString(cursor.getColumnIndex(TAKEN))); + int taken = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(TAKEN))); cursor.close(); @@ -736,7 +729,7 @@ public void deleteNote(Note note) SQLiteDatabase db = this.getWritableDatabase(); String query = NOTE + " = \"" + note.getNote() + "\" AND " + ENTRY_TIME - + " = \"" + TimeFormatting.localDateTimeToString(note.getNoteTime()) + "\""; + + " = '" + TimeFormatting.localDateTimeToString(note.getNoteTime()) + "'"; db.delete(NOTES_TABLE, query, null); } @@ -761,7 +754,6 @@ public void updateNote(Note note, String newNote) * @param medId ID of Medication pertaining to Note * @return An ArrayList of all notes about given Medication **************************************************************************/ - @SuppressLint("Range") public ArrayList getNotes(long medId) { SQLiteDatabase db = this.getReadableDatabase(); @@ -776,10 +768,10 @@ public ArrayList getNotes(long medId) while (!cursor.isAfterLast()) { - long noteId = Long.parseLong(cursor.getString(cursor.getColumnIndex(NOTE_ID))); - String note = cursor.getString(cursor.getColumnIndex(NOTE)); + long noteId = Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(NOTE_ID))); + String note = cursor.getString(cursor.getColumnIndexOrThrow(NOTE)); LocalDateTime entryTime = TimeFormatting.stringToLocalDateTime(cursor.getString( - cursor.getColumnIndex(ENTRY_TIME))); + cursor.getColumnIndexOrThrow(ENTRY_TIME))); notes.add(new Note(noteId, medId, note, entryTime)); @@ -791,7 +783,6 @@ public ArrayList getNotes(long medId) return notes; } - @SuppressLint("Range") public long[] getMedicationTimeIds(Medication medication) { SQLiteDatabase db = this.getReadableDatabase(); @@ -806,7 +797,7 @@ public long[] getMedicationTimeIds(Medication medication) for (int i = 0; i < cursor.getCount(); i++) { - timeIds[i] = Long.parseLong(cursor.getString(cursor.getColumnIndex(TIME_ID))); + timeIds[i] = Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(TIME_ID))); cursor.moveToNext(); } @@ -825,7 +816,6 @@ public void setTimeBeforeDose(int hoursBeforeDose) db.update(SETTINGS_TABLE, cv, null, null); } - @SuppressLint("Range") public int getTimeBeforeDose() { SQLiteDatabase db = this.getReadableDatabase(); @@ -835,7 +825,7 @@ public int getTimeBeforeDose() Cursor cursor = db.rawQuery(query, null); cursor.moveToFirst(); - int timeBefore = Integer.parseInt(cursor.getString(cursor.getColumnIndex(TIME_BEFORE_DOSE))); + int timeBefore = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(TIME_BEFORE_DOSE))); cursor.close(); @@ -852,7 +842,6 @@ public void setNotificationEnabled(boolean status) db.update(SETTINGS_TABLE, cv, null, null); } - @SuppressLint("Range") public boolean getNotificationEnabled() { SQLiteDatabase db = this.getReadableDatabase(); @@ -863,14 +852,13 @@ public boolean getNotificationEnabled() cursor.moveToFirst(); boolean enabled - = Integer.parseInt(cursor.getString(cursor.getColumnIndex(ENABLE_NOTIFICATIONS))) == 1; + = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(ENABLE_NOTIFICATIONS))) == 1; cursor.close(); return enabled; } - @SuppressLint("Range") public String getSavedTheme() { SQLiteDatabase db = this.getReadableDatabase(); @@ -880,7 +868,7 @@ public String getSavedTheme() Cursor cursor = db.rawQuery(query, null); cursor.moveToFirst(); - theme = cursor.getString(cursor.getColumnIndex(THEME)); + theme = cursor.getString(cursor.getColumnIndexOrThrow(THEME)); cursor.close(); diff --git a/app/src/main/java/projects/medicationtracker/Receivers/EventReceiver.java b/app/src/main/java/projects/medicationtracker/Receivers/EventReceiver.java index 1c1435dd..3bd0ae22 100644 --- a/app/src/main/java/projects/medicationtracker/Receivers/EventReceiver.java +++ b/app/src/main/java/projects/medicationtracker/Receivers/EventReceiver.java @@ -118,8 +118,6 @@ private void markDoseTaken( med = db.getMedication(medId); - System.out.println(med.getMedName()); - long doseId = db.isInMedicationTracker(med, doseTime) ? db.getDoseId(med.getMedId(), TimeFormatting.localDateTimeToString(doseTime)) : db.addToMedicationTracker(med, doseTime); From 4f5a8a2009b39339c76c595721b8749f13328322 Mon Sep 17 00:00:00 2001 From: Adam Guidarini <45023561+AdamG95@users.noreply.github.com> Date: Thu, 17 Nov 2022 11:03:58 -0600 Subject: [PATCH 5/5] String changes --- app/src/main/res/values/strings.xml | 110 +--------------------- app/src/main/res/xml/root_preferences.xml | 35 ------- 2 files changed, 3 insertions(+), 142 deletions(-) delete mode 100644 app/src/main/res/xml/root_preferences.xml diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58d160cf..6fdcb3e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,113 +34,9 @@ Place holder, tap again then hit cancel Your Medications: Settings - - - Messages - Sync - - - Your signature - Default reply action - - - Sync email periodically - Download incoming attachments - Automatically download attachments for incoming emails - - Only download attachments when manually requested Delete All No notes for this medication Add Note - - "Material is the metaphor.\n\n" - - "A material metaphor is the unifying theory of a rationalized space and a system of motion." - "The material is grounded in tactile reality, inspired by the study of paper and ink, yet " - "technologically advanced and open to imagination and magic.\n" - "Surfaces and edges of the material provide visual cues that are grounded in reality. The " - "use of familiar tactile attributes helps users quickly understand affordances. Yet the " - "flexibility of the material creates new affordances that supercede those in the physical " - "world, without breaking the rules of physics.\n" - "The fundamentals of light, surface, and movement are key to conveying how objects move, " - "interact, and exist in space and in relation to each other. Realistic lighting shows " - "seams, divides space, and indicates moving parts.\n\n" - - "Bold, graphic, intentional.\n\n" - - "The foundational elements of print based design typography, grids, space, scale, color, " - "and use of imagery guide visual treatments. These elements do far more than please the " - "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge " - "imagery, large scale typography, and intentional white space create a bold and graphic " - "interface that immerse the user in the experience.\n" - "An emphasis on user actions makes core functionality immediately apparent and provides " - "waypoints for the user.\n\n" - - "Motion provides meaning.\n\n" - - "Motion respects and reinforces the user as the prime mover. Primary user actions are " - "inflection points that initiate motion, transforming the whole design.\n" - "All action takes place in a single environment. Objects are presented to the user without " - "breaking the continuity of experience even as they transform and reorganize.\n" - "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. " - "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n" - - "3D world.\n\n" - - "The material environment is a 3D space, which means all objects have x, y, and z " - "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the " - "positive z-axis extending towards the viewer. Every sheet of material occupies a single " - "position along the z-axis and has a standard 1dp thickness.\n" - "On the web, the z-axis is used for layering and not for perspective. The 3D world is " - "emulated by manipulating the y-axis.\n\n" - - "Light and shadow.\n\n" - - "Within the material environment, virtual lights illuminate the scene. Key lights create " - "directional shadows, while ambient light creates soft shadows from all angles.\n" - "Shadows in the material environment are cast by these two light sources. In Android " - "development, shadows occur when light sources are blocked by sheets of material at " - "various positions along the z-axis. On the web, shadows are depicted by manipulating the " - "y-axis only. The following example shows the card with a height of 6dp.\n\n" - - "Resting elevation.\n\n" - - "All material objects, regardless of size, have a resting elevation, or default elevation " - "that does not change. If an object changes elevation, it should return to its resting " - "elevation as soon as possible.\n\n" - - "Component elevations.\n\n" - - "The resting elevation for a component type is consistent across apps (e.g., FAB elevation " - "does not vary from 6dp in one app to 16dp in another app).\n" - "Components may have different resting elevations across platforms, depending on the depth " - "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n" - - "Responsive elevation and dynamic elevation offsets.\n\n" - - "Some component types have responsive elevation, meaning they change elevation in response " - "to user input (e.g., normal, focused, and pressed) or system events. These elevation " - "changes are consistently implemented using dynamic elevation offsets.\n" - "Dynamic elevation offsets are the goal elevation that a component moves towards, relative " - "to the component’s resting state. They ensure that elevation changes are consistent " - "across actions and component types. For example, all components that lift on press have " - "the same elevation change relative to their resting elevation.\n" - "Once the input event is completed or cancelled, the component will return to its resting " - "elevation.\n\n" - - "Avoiding elevation interference.\n\n" - - "Components with responsive elevations may encounter other components as they move between " - "their resting elevations and dynamic elevation offsets. Because material cannot pass " - "through other material, components avoid interfering with one another any number of ways, " - "whether on a per component basis or using the entire app layout.\n" - "On a component level, components can move or be removed before they cause interference. " - "For example, a floating action button (FAB) can disappear or move off screen before a " - "user picks up a card, or it can move if a snackbar appears.\n" - "On the layout level, design your app layout to minimize opportunities for interference. " - "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " - "when a user tries to pick up one of cards.\n\n" - Ex. mg, g, drops Delete Medication Patient Name: @@ -169,11 +65,11 @@ Start Date Taken at Unit of Time - Mark as taken - Remind me in 15 minutes + Taken + Snooze Options License - MediTrak is a free and open source (FOSS) application designed to help you keep track of your medications, so you can more easily answer the question \"did I take my medication yesterday?\" + MediTrak is a free and open source application designed to help you keep track of your medications, so you can more easily answer the question \"did I take my medication yesterday?\" Copyright © 2022 Adam Guidarini MediTrak is free software and may be redistributed and/or modified under the terms of the GNU General Public License as published by the Free software foundation, either version 2 or (at your option) later. diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml deleted file mode 100644 index 67158dbb..00000000 --- a/app/src/main/res/xml/root_preferences.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file