diff --git a/README.md b/README.md index 16cbabeb..fde01500 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ MediTrak is an Android application designed to make it easier for users to keep ## Requirements -- Android 10+ +- Android 9+ ## Languages - English diff --git a/app/build.gradle b/app/build.gradle index 06c3b824..90df8138 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,12 +12,12 @@ android { defaultConfig { applicationId "projects.medicationtracker" - minSdkVersion 29 + minSdkVersion 28 targetSdkVersion 34 compileSdk 34 - versionCode 30 - versionName "0.13.1" + versionCode 31 + versionName "0.13.2" resourceConfigurations += ['en', 'de', 'es', 'it', 'tr'] ndk { diff --git a/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.cpp b/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.cpp index 0d823ce4..e2d08b8d 100644 --- a/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.cpp +++ b/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.cpp @@ -47,7 +47,7 @@ void DatabaseController::create() { + MED_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MED_NAME + " TEXT," + PATIENT_NAME + " Text," - + MED_DOSAGE + " DECIMAL(3,2)," + + MED_DOSAGE + " REAL," + MED_UNITS + " TEXT," + START_DATE + " DATETIME," + MED_FREQUENCY + " INTEGER," @@ -69,7 +69,7 @@ void DatabaseController::create() { + DOSE_TIME + " DATETIME," + TAKEN + " BOOLEAN," + TIME_TAKEN + " DATETIME," - + OVERRIDE_DOSE_AMOUNT + " INTEGER," + + OVERRIDE_DOSE_AMOUNT + " REAL," + OVERRIDE_DOSE_UNIT + " TEXT," + "FOREIGN KEY (" + MED_ID + ") REFERENCES " + MEDICATION_TABLE + "(" + MED_ID + ") ON DELETE CASCADE" @@ -231,6 +231,60 @@ void DatabaseController::upgrade(int currentVersion) { repairImportErrors(); } + if (currentVersion < 16) { + string sql = + "BEGIN TRANSACTION; PRAGMA foreign_keys = OFF; CREATE TABLE " + + MEDICATION_TABLE + "_1(" + + MED_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + MED_NAME + " TEXT," + + PATIENT_NAME + " Text," + + MED_DOSAGE + " REAL," + + MED_UNITS + " TEXT," + + START_DATE + " DATETIME," + + MED_FREQUENCY + " INTEGER," + + ALIAS + " TEXT," + + ACTIVE + " BOOLEAN DEFAULT 1," + + PARENT_ID + " INTEGER," + + CHILD_ID + " INTEGER," + + INSTRUCTIONS + " TEXT," + + "FOREIGN KEY (" + PARENT_ID + ") REFERENCES " + + MEDICATION_TABLE + "(" + MED_ID + ") ON DELETE CASCADE," + + "FOREIGN KEY (" + CHILD_ID + ") REFERENCES " + + MEDICATION_TABLE + "(" + MED_ID + ") ON DELETE CASCADE" + + ");" + + + "INSERT INTO " + MEDICATION_TABLE + "_1" + " SELECT * FROM " + + MEDICATION_TABLE + + ";" + + "DROP TABLE " + MEDICATION_TABLE + ";" + + "ALTER TABLE " + MEDICATION_TABLE + "_1" + " RENAME TO '" + + MEDICATION_TABLE + "';" + + + "CREATE TABLE " + MEDICATION_TRACKER_TABLE + "_1 (" + + DOSE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + + MED_ID + " INTEGER," + + DOSE_TIME + " DATETIME," + + TAKEN + " BOOLEAN," + + TIME_TAKEN + " DATETIME," + + OVERRIDE_DOSE_AMOUNT + " REAL," + + OVERRIDE_DOSE_UNIT + " TEXT," + + "FOREIGN KEY (" + MED_ID + ") REFERENCES " + MEDICATION_TABLE + "(" + + MED_ID + + ") ON DELETE CASCADE" + + ");" + + + "INSERT INTO " + MEDICATION_TRACKER_TABLE + "_1 " + + "SELECT * FROM " + MEDICATION_TRACKER_TABLE + ";" + + "DROP TABLE " + MEDICATION_TRACKER_TABLE + ";" + + "ALTER TABLE " + MEDICATION_TRACKER_TABLE + "_1 RENAME TO '" + + MEDICATION_TRACKER_TABLE + "';" + + + " PRAGMA foreign_keys = ON;" + + " COMMIT;"; + + manager.execSql(sql); + } + manager.execSql("PRAGMA schema_version = " + to_string(DB_VERSION)); } @@ -325,7 +379,7 @@ Medication DatabaseController::getMedication(long medicationId) { {}, table->getItem(START_DATE), stol(table->getItem(MED_ID)), - stoi(table->getItem(MED_DOSAGE)), + stof(table->getItem(MED_DOSAGE)), stoi(table->getItem(MED_FREQUENCY)), table->getItem(ACTIVE) == "1", table->getItem(ALIAS) @@ -365,11 +419,11 @@ vector DatabaseController::getTakenDoses(long medicationId) { Table *table = manager.execSqlWithReturn(query); while (table->getCount() > 0 && !table->isAfterLast()) { - int overrideDose = -1; + float overrideDose = -1; string overrideUnit; if (!empty(table->getItem(OVERRIDE_DOSE_AMOUNT))) { - overrideDose = stoi(table->getItem(OVERRIDE_DOSE_AMOUNT)); + overrideDose = stof(table->getItem(OVERRIDE_DOSE_AMOUNT)); } if (!empty(table->getItem(OVERRIDE_DOSE_UNIT))) { @@ -400,11 +454,11 @@ Dose *DatabaseController::setDose(Table *table) { if (table->getCount() > 0) { table->moveToFirst(); - int overrideDose = -1; + float overrideDose = -1; string overrideUnit; if (!empty(table->getItem(OVERRIDE_DOSE_AMOUNT))) { - overrideDose = stoi(table->getItem(OVERRIDE_DOSE_AMOUNT)); + overrideDose = stof(table->getItem(OVERRIDE_DOSE_AMOUNT)); } if (!empty(table->getItem(OVERRIDE_DOSE_UNIT))) { @@ -650,7 +704,7 @@ void DatabaseController::repairImportErrors() { } else if (!match && timeEdited.length() == DateFormats::DB_DATE_FORMAT.length() - 1) { manager.update( NOTES_TABLE, - {pair(TIME_EDITED, timeEdited += "0")}, + {pair(TIME_EDITED, timeEdited + "0")}, {pair(NOTE_ID, notes->getItem(NOTE_ID))} ); } diff --git a/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.h b/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.h index 80430680..84ce1e55 100644 --- a/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.h +++ b/app/src/main/cpp/MediTrakCore/DatabaseController/DatabaseController.h @@ -29,11 +29,11 @@ namespace DateFormats { class DatabaseController { private: - const int DB_VERSION = 15; + const int DB_VERSION = 16; const string DATABASE_NAME = "Medications.db"; vector tablesToIgnore; DbManager manager; - + const string ANDROID_METADATA = "android_metadata"; const string MEDICATION_TABLE = "Medication"; @@ -104,10 +104,6 @@ class DatabaseController { */ Dose* setDose(Table* table); - /** - * Resolves issues in caused by imports where the last character of the last record was removed - */ - void repairImportErrors(); public: const string NOTES_TABLE = "Notes"; const string SETTINGS_TABLE = "Settings"; @@ -253,6 +249,11 @@ class DatabaseController { * @param id ID of notification to delete */ void deleteNotification(long id); + + /** + * Resolves issues in caused by imports where the last character of the last record was removed + */ + void repairImportErrors(); }; #endif //MEDICATIONTRACKER_DATABASECONTROLLER_H diff --git a/app/src/main/cpp/MediTrakCore/Dose/Dose.cpp b/app/src/main/cpp/MediTrakCore/Dose/Dose.cpp index 06faddc1..9605802d 100644 --- a/app/src/main/cpp/MediTrakCore/Dose/Dose.cpp +++ b/app/src/main/cpp/MediTrakCore/Dose/Dose.cpp @@ -12,7 +12,15 @@ Dose::Dose() { doseTime = {}; } -Dose::Dose(long id, long medicationId, bool taken, std::string doseTime, std::string timeTaken, int overrideDoseAmount, std::string overrideDoseUnit) { +Dose::Dose( + long id, + long medicationId, + bool taken, + std::string doseTime, + std::string timeTaken, + float overrideDoseAmount, + std::string overrideDoseUnit +) { this->id = id; this->medicationId = medicationId; this->taken = taken; diff --git a/app/src/main/cpp/MediTrakCore/Dose/Dose.h b/app/src/main/cpp/MediTrakCore/Dose/Dose.h index a1c9cf8e..85b054a8 100644 --- a/app/src/main/cpp/MediTrakCore/Dose/Dose.h +++ b/app/src/main/cpp/MediTrakCore/Dose/Dose.h @@ -13,11 +13,20 @@ struct Dose { bool taken; std::string doseTime; std::string timeTaken; - int overrideDoseAmount; + float overrideDoseAmount; std::string overrideDoseUnit; Dose(); - Dose(long id, long medicationId, bool taken, std::string doseTime, std::string timeTaken, int overrideDose = -1, std::string overrideDoseUnit = ""); + + Dose( + long id, + long medicationId, + bool taken, + std::string doseTime, + std::string timeTaken, + float overrideDose = -1, + std::string overrideDoseUnit = "" + ); }; diff --git a/app/src/main/cpp/MediTrakCore/Medication/Medication.cpp b/app/src/main/cpp/MediTrakCore/Medication/Medication.cpp index 87faf73f..496a8ff5 100644 --- a/app/src/main/cpp/MediTrakCore/Medication/Medication.cpp +++ b/app/src/main/cpp/MediTrakCore/Medication/Medication.cpp @@ -24,7 +24,7 @@ Medication::Medication( vector times, string startDate, long id, - int dosage, + float dosage, int frequency, bool active, string alias diff --git a/app/src/main/cpp/MediTrakCore/Medication/Medication.h b/app/src/main/cpp/MediTrakCore/Medication/Medication.h index 88fd8595..cf2bb49c 100644 --- a/app/src/main/cpp/MediTrakCore/Medication/Medication.h +++ b/app/src/main/cpp/MediTrakCore/Medication/Medication.h @@ -21,7 +21,7 @@ struct Medication { vector times; vector doses; long id; - int dosage; + float dosage; int frequency; bool active; shared_ptr parent = nullptr; @@ -52,7 +52,7 @@ struct Medication { vector times, string startDate, long id, - int dosage, + float dosage, int frequency, bool active, string alias = "" diff --git a/app/src/main/cpp/medicationtracker.cpp b/app/src/main/cpp/medicationtracker.cpp index 92a86b54..85a08411 100644 --- a/app/src/main/cpp/medicationtracker.cpp +++ b/app/src/main/cpp/medicationtracker.cpp @@ -35,7 +35,7 @@ jobject doseToJavaConverter(const Dose& dose, JNIEnv *env, jobject &jMedication) auto jDoses = static_cast(env->GetObjectField(jMedication, medDoses)); jclass jDose = env->GetObjectClass(env->GetObjectArrayElement(jDoses, 0)); - jmethodID setOverrideDoseAmount = env->GetMethodID(jDose, "setOverrideDoseAmount", "(I)V"); + jmethodID setOverrideDoseAmount = env->GetMethodID(jDose, "setOverrideDoseAmount", "(F)V"); jmethodID setOverrideDoseUnit = env->GetMethodID(jDose, "setOverrideDoseUnit", "(Ljava/lang/String;)V"); @@ -45,12 +45,6 @@ jobject doseToJavaConverter(const Dose& dose, JNIEnv *env, jobject &jMedication) jmethodID setTimeTaken = env->GetMethodID(jDose, "setTimeTaken", "(Ljava/lang/String;)V"); jmethodID setDoseTime = env->GetMethodID(jDose, "setDoseTime", "(Ljava/lang/String;)V"); - jmethodID constructor = env->GetMethodID( - jDose, - "", - "(JJZLjava/lang/String;Ljava/lang/String;)V" - ); - jmethodID constructorDefault = env->GetMethodID( jDose, "", @@ -95,7 +89,7 @@ Dose javaDoseToNativeDoseConverter(jobject jDose, JNIEnv *env) { "()Ljava/lang/String;"); jmethodID getDoseTimeText = env->GetMethodID(jDoseClass, "getDoseTimeText", "()Ljava/lang/String;"); - jmethodID getOverrideDoseAmount = env->GetMethodID(jDoseClass, "getOverrideDoseAmount", "()I"); + jmethodID getOverrideDoseAmount = env->GetMethodID(jDoseClass, "getOverrideDoseAmount", "()F"); jmethodID getOverrideDoseUnit = env->GetMethodID(jDoseClass, "getOverrideDoseUnit", "()Ljava/lang/String;"); @@ -107,7 +101,7 @@ Dose javaDoseToNativeDoseConverter(jobject jDose, JNIEnv *env) { new jboolean(false)), env->GetStringUTFChars((jstring) env->CallObjectMethod(jDose, getTimeTakenText), new jboolean(false)), - env->CallIntMethod(jDose, getOverrideDoseAmount), + env->CallFloatMethod(jDose, getOverrideDoseAmount), env->GetStringUTFChars((jstring) env->CallObjectMethod(jDose, getOverrideDoseUnit), new jboolean(false)) ); @@ -119,7 +113,7 @@ jobject medicationToJavaConverter(Medication med, JNIEnv *env, jclass jMedicatio jmethodID medConstructor = env->GetMethodID( jMedication, "", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;JIILjava/lang/String;)V" + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;JIFLjava/lang/String;)V" ); for (int i = 0; i < med.times.size(); i++) { @@ -139,7 +133,7 @@ jobject medicationToJavaConverter(Medication med, JNIEnv *env, jclass jMedicatio env->NewStringUTF(med.startDate.c_str()), med.id, jint(med.frequency), - jint(med.dosage), + med.dosage, env->NewStringUTF(med.alias.c_str()) ); @@ -274,6 +268,7 @@ Java_projects_medicationtracker_Helpers_NativeDbHelper_dbImporter( try { controller.importJSONString(fileContents, ignoredTbls); + controller.repairImportErrors(); } catch (exception &e) { __android_log_write(ANDROID_LOG_ERROR, nullptr, e.what()); diff --git a/app/src/main/java/projects/medicationtracker/Adapters/HistoryAdapter.java b/app/src/main/java/projects/medicationtracker/Adapters/HistoryAdapter.java index 6e8253af..793a9d5e 100644 --- a/app/src/main/java/projects/medicationtracker/Adapters/HistoryAdapter.java +++ b/app/src/main/java/projects/medicationtracker/Adapters/HistoryAdapter.java @@ -1,5 +1,7 @@ package projects.medicationtracker.Adapters; +import static projects.medicationtracker.MediTrak.formatter; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,9 +13,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Arrays; import java.util.Locale; -import java.util.stream.Stream; import projects.medicationtracker.Models.Medication; import projects.medicationtracker.R; @@ -82,9 +82,9 @@ public void onBindViewHolder(@NonNull HistoryAdapter.ViewHolder holder, int posi String doseLbl = ""; if (doses[position].getOverrideDoseAmount() != -1) { - doseLbl += doses[position].getOverrideDoseAmount() + " "; + doseLbl += formatter.format(doses[position].getOverrideDoseAmount()) + " "; } else { - doseLbl += currentMed.getDosage() + " "; + doseLbl += formatter.format(currentMed.getDosage()) + " "; } if (!doses[position].getOverrideDoseUnit().isEmpty()) { diff --git a/app/src/main/java/projects/medicationtracker/AddMedication.java b/app/src/main/java/projects/medicationtracker/AddMedication.java index dd2c3450..02efac8a 100644 --- a/app/src/main/java/projects/medicationtracker/AddMedication.java +++ b/app/src/main/java/projects/medicationtracker/AddMedication.java @@ -3,6 +3,7 @@ import static projects.medicationtracker.Helpers.DBHelper.DATE_FORMAT; import static projects.medicationtracker.Helpers.DBHelper.TIME_FORMAT; import static projects.medicationtracker.MainActivity.preferences; +import static projects.medicationtracker.MediTrak.formatter; import android.annotation.SuppressLint; import android.app.NotificationManager; @@ -54,6 +55,7 @@ import projects.medicationtracker.Helpers.NativeDbHelper; import projects.medicationtracker.Helpers.NotificationHelper; import projects.medicationtracker.Helpers.TimeFormatting; +import projects.medicationtracker.InputFilters.DecimalPlacesFilter; import projects.medicationtracker.Models.Medication; public class AddMedication extends AppCompatActivity { @@ -102,7 +104,7 @@ public class AddMedication extends AppCompatActivity { private TextInputEditText instructions; /* - * Validators + * Validators */ private boolean isPatientNameValid = true; private boolean isMedNameValid = false; @@ -265,8 +267,13 @@ private void setPatientCard() { patientNameInput.setAdapter(patientNamesAdapter); patientNameInput.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -339,8 +346,13 @@ private void setMedNameAndDosageCard() { }); medNameInput.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -357,12 +369,18 @@ public void afterTextChanged(Editable editable) { } }); + dosageAmountInput.setFilters(new DecimalPlacesFilter[]{new DecimalPlacesFilter()}); + dosageAmountInput.addTextChangedListener(new TextWatcher() { - private final int amount = medication.getDosage(); + private final float amount = medication.getDosage(); + @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -383,7 +401,7 @@ public void afterTextChanged(Editable editable) { } } - if (!editable.toString().isEmpty() && Integer.parseInt(editable.toString()) != amount && medId != -1) { + if (!editable.toString().isEmpty() && Float.parseFloat(editable.toString()) != amount && medId != -1) { applyRetroactiveCard.setVisibility(View.VISIBLE); } @@ -395,9 +413,12 @@ public void afterTextChanged(Editable editable) { private final String unit = medication.getDosageUnits(); @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -420,10 +441,12 @@ public void afterTextChanged(Editable editable) { instructions.addTextChangedListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + } @Override public void afterTextChanged(Editable s) { @@ -437,11 +460,7 @@ public void afterTextChanged(Editable s) { aliasInput.setText(medication.getAlias()); } - if (medication.getDosage() == medication.getDosage()) { - dosageAmountInput.setText(String.format(Locale.getDefault(), "%d", medication.getDosage())); - } else { - dosageAmountInput.setText(String.valueOf(medication.getDosage())); - } + dosageAmountInput.setText(formatter.format(medication.getDosage())); dosageUnitsInput.setText(medication.getDosageUnits()); @@ -514,7 +533,7 @@ private void setFrequencyCard() { } } - frequencyDropDown.setOnItemClickListener((adapterView, view, i, l) -> { + frequencyDropDown.setOnItemClickListener((adapterView, view, i, l) -> { frequencyDropdownLayout.setErrorEnabled(false); isMedFrequencyValid = false; @@ -563,8 +582,14 @@ private void setFrequencyCard() { frequencyDropDown.addTextChangedListener(new TextWatcher() { private final String selected = frequencyDropDown.getText().toString(); - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -602,8 +627,13 @@ private void setMultiplePerDayFrequencyViews() { startDateMultiplePerDay.addTextChangedListener( new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -614,8 +644,13 @@ public void afterTextChanged(Editable editable) { ); numberOfTimersPerDay.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -701,8 +736,13 @@ public void afterTextChanged(Editable editable) { }); timeEntry.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -740,16 +780,19 @@ public void afterTextChanged(Editable editable) { numberOfTimersPerDay.addTextChangedListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + } @Override public void afterTextChanged(Editable s) { if (s.toString().isEmpty()) return; if (Integer.parseInt(s.toString()) != initialNumTimes) { - applyRetroactiveCard.setVisibility(View.VISIBLE); + applyRetroactiveCard.setVisibility(View.VISIBLE); } } }); @@ -798,9 +841,13 @@ private void setDailyFrequencyViews() { dailyMedTime.addTextChangedListener(new TextWatcher() { private final LocalTime time = medication.getStartDate().toLocalTime(); - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -815,11 +862,14 @@ public void afterTextChanged(Editable editable) { dailyMedStartDate.addTextChangedListener(new TextWatcher() { private final LocalDate date = medication.getStartDate().toLocalDate(); + @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -889,9 +939,13 @@ private void setCustomFrequencyViews() { customFreqMedTime.addTextChangedListener(new TextWatcher() { private final LocalTime time = medication.getStartDate().toLocalTime(); - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -914,11 +968,14 @@ public void afterTextChanged(Editable editable) { customFreqStartDate.addTextChangedListener(new TextWatcher() { private final LocalDate date = medication.getStartDate().toLocalDate(); + @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -941,8 +998,13 @@ public void afterTextChanged(Editable editable) { }); customFreqMTakenEveryEnter.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -1024,8 +1086,13 @@ public void afterTextChanged(Editable editable) { } customFreqTimeUnitEnter.addTextChangedListener(new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -1059,8 +1126,13 @@ private void setAsNeededViews() { asNeededStartInput.addTextChangedListener( new TextWatcher() { - @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void afterTextChanged(Editable editable) { @@ -1247,7 +1319,7 @@ private boolean isMedNameAndDosageCardValid() { } if ((dosageAmountInputLayout.getError() == null || floatIsParsable(dosageAmountInput.getText().toString())) && !dosageAmountInput.getText().toString().isEmpty()) { - medication.setDosage(Integer.parseInt(dosageAmountInput.getText().toString())); + medication.setDosage(Float.parseFloat(dosageAmountInput.getText().toString())); dosageAmountInputLayout.setErrorEnabled(false); } else { @@ -1319,7 +1391,7 @@ && intIsParsable(numberOfTimersPerDay.getText().toString()) childLayout.setErrorEnabled(false); - if ((time!= null && time.getText().toString().isEmpty()) || start == null || Objects.requireNonNull(time).getTag() == null) { + if ((time != null && time.getText().toString().isEmpty()) || start == null || Objects.requireNonNull(time).getTag() == null) { errorCount++; } else { times[i] = LocalDateTime.of(start.toLocalDate(), (LocalTime) time.getTag()); @@ -1417,6 +1489,10 @@ private boolean isCustomFrequencyValid() { return false; } + /** + * Validates fields for as needed medications + * @return true if valid, false if invalid + */ private boolean isAsNeededValid() { if (!Objects.requireNonNull(asNeededStartInput.getText()).toString().isEmpty()) { asNeededStart.setErrorEnabled(false); @@ -1466,7 +1542,8 @@ private boolean floatIsParsable(String floatToParse) { /** * Compares changes to medication an adds notes for each - * @param child Newly modified medication + * + * @param child Newly modified medication * @param parent Old version of medication * @return Notes for all changes made to medication or empty string */ @@ -1506,7 +1583,7 @@ private String createChangesNote(Medication child, Medication parent) { createClone = true; note += getString(R.string.changed_dosage, - parent.getDosage() + " " +parent.getDosageUnits(), + parent.getDosage() + " " + parent.getDosageUnits(), child.getDosage() + " " + child.getDosageUnits() ); } @@ -1535,11 +1612,14 @@ private String createChangesNote(Medication child, Medication parent) { return note; } + /** + * Enables the save button if all fields are valid + */ private void validateForm() { boolean allValid = isPatientNameValid && isMedNameValid && isMedDosageValid - && isMedDoseUnitValid + && isMedDoseUnitValid && isMedFrequencyValid; saveButton.setEnabled(allValid); diff --git a/app/src/main/java/projects/medicationtracker/Dialogs/DoseInfoDialog.java b/app/src/main/java/projects/medicationtracker/Dialogs/DoseInfoDialog.java index a511e05d..d1397d59 100644 --- a/app/src/main/java/projects/medicationtracker/Dialogs/DoseInfoDialog.java +++ b/app/src/main/java/projects/medicationtracker/Dialogs/DoseInfoDialog.java @@ -3,6 +3,7 @@ import static projects.medicationtracker.Helpers.DBHelper.DATE_FORMAT; import static projects.medicationtracker.Helpers.DBHelper.TIME_FORMAT; import static projects.medicationtracker.MainActivity.preferences; +import static projects.medicationtracker.MediTrak.formatter; import android.app.Dialog; import android.content.DialogInterface; @@ -33,6 +34,7 @@ import projects.medicationtracker.Fragments.TimePickerFragment; import projects.medicationtracker.Helpers.DBHelper; import projects.medicationtracker.Helpers.NativeDbHelper; +import projects.medicationtracker.InputFilters.DecimalPlacesFilter; import projects.medicationtracker.Interfaces.IDialogCloseListener; import projects.medicationtracker.R; import projects.medicationtracker.Models.Dose; @@ -111,9 +113,9 @@ public Dialog onCreateDialog(Bundle savedInstances) { dateTaken.setTag(doseDate.toLocalDate()); if (thisDose.getOverrideDoseAmount() == -1) { - dosageAmount.setText(String.valueOf(medication.getDosage())); + dosageAmount.setText(formatter.format(medication.getDosage())); } else { - dosageAmount.setText(String.valueOf(thisDose.getOverrideDoseAmount())); + dosageAmount.setText(formatter.format(thisDose.getOverrideDoseAmount())); } if (thisDose.getOverrideDoseUnit().isEmpty()) { @@ -138,6 +140,8 @@ public void afterTextChanged(Editable editable) { timeTaken.addTextChangedListener(tw); dateTaken.addTextChangedListener(tw); + dosageAmount.setFilters(new DecimalPlacesFilter[]{new DecimalPlacesFilter()}); + dosageAmount.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} @@ -155,7 +159,7 @@ public void afterTextChanged(Editable editable) { inputLayout.setError(getString(R.string.err_required)); } else { try { - Integer.valueOf(editable.toString()); + Float.valueOf(editable.toString()); isDosageValid = true; } catch (Exception e) { inputLayout.setError(getString(R.string.val_too_big)); @@ -231,7 +235,7 @@ private void save() { LocalDate date = (LocalDate) dateTaken.getTag(); LocalTime time = (LocalTime) timeTaken.getTag(); LocalDateTime dateTime = LocalDateTime.of(date, time).withSecond(0); - int overrideAmount = Integer.parseInt(dosageAmount.getText().toString()); + float overrideAmount = Float.parseFloat(dosageAmount.getText().toString()); String overrideUnits = dosageUnit.getText().toString(); Fragment parent = getParentFragment(); diff --git a/app/src/main/java/projects/medicationtracker/Dialogs/OpenNotificationsDialog.java b/app/src/main/java/projects/medicationtracker/Dialogs/OpenNotificationsDialog.java index db7f4192..8ece5837 100644 --- a/app/src/main/java/projects/medicationtracker/Dialogs/OpenNotificationsDialog.java +++ b/app/src/main/java/projects/medicationtracker/Dialogs/OpenNotificationsDialog.java @@ -3,6 +3,7 @@ import static projects.medicationtracker.Helpers.DBHelper.DATE_FORMAT; import static projects.medicationtracker.Helpers.DBHelper.TIME_FORMAT; import static projects.medicationtracker.MainActivity.preferences; +import static projects.medicationtracker.MediTrak.formatter; import static projects.medicationtracker.Workers.NotificationWorker.SUMMARY_ID; import android.app.Activity; @@ -164,7 +165,7 @@ private void generateCheckBoxes(AlertDialog dialog) { continue; } - label = m.getName() + " - " + m.getDosage() + " " + m.getDosageUnits() + " - "; + label = m.getName() + " - " + formatter.format(m.getDosage()) + " " + m.getDosageUnits() + " - "; label += DateTimeFormatter.ofPattern( preferences.getString(DATE_FORMAT), diff --git a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java index b72b6ac0..9624d722 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/MedicationScheduleFragment.java @@ -3,6 +3,7 @@ import static projects.medicationtracker.Helpers.DBHelper.DATE_FORMAT; import static projects.medicationtracker.Helpers.DBHelper.TIME_FORMAT; import static projects.medicationtracker.MainActivity.preferences; +import static projects.medicationtracker.MediTrak.formatter; import static projects.medicationtracker.Workers.NotificationWorker.SUMMARY_ID; import android.app.NotificationManager; @@ -11,7 +12,6 @@ import android.os.Bundle; import android.os.Parcelable; import android.service.notification.StatusBarNotification; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -320,9 +320,9 @@ private String createLabel(Medication medication, Dose dose, LocalDateTime doseT String dosage; if (dose.getDoseId() != -1 && !Objects.isNull(dose) && dose.getOverrideDoseAmount() != -1) { - dosage = String.valueOf(dose.getOverrideDoseAmount()); + dosage = formatter.format(dose.getOverrideDoseAmount()); } else { - dosage = String.valueOf(medication.getDosage()); + dosage = formatter.format(medication.getDosage()); } dosage += " "; diff --git a/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java b/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java index ddfc7d3e..3e4de9f1 100644 --- a/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java +++ b/app/src/main/java/projects/medicationtracker/Fragments/MyMedicationsFragment.java @@ -3,6 +3,7 @@ import static projects.medicationtracker.Helpers.DBHelper.DATE_FORMAT; import static projects.medicationtracker.Helpers.DBHelper.TIME_FORMAT; import static projects.medicationtracker.MainActivity.preferences; +import static projects.medicationtracker.MediTrak.formatter; import android.content.Intent; import android.os.Build; @@ -102,7 +103,7 @@ private void insertMedicationData(Medication medication, View v) { medication.setTimes(dateTimes); name.setText(medication.getName()); - dosage.setText(String.valueOf(medication.getDosage())); + dosage.setText(formatter.format(medication.getDosage())); doseUnit.setText(medication.getDosageUnits()); String label = medication.generateFrequencyLabel( diff --git a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java index b470951d..88e087fc 100644 --- a/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java +++ b/app/src/main/java/projects/medicationtracker/Helpers/DBHelper.java @@ -93,16 +93,8 @@ public static class DateFormats { public static final String DB_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; } - public static class Languages { - public static final String ENGLISH = "en"; - public static final String GERMAN = "de"; - public static final String SPANISH = "es"; - public static final String ITALIAN = "it"; - } - private NativeDbHelper nativeHelper; private Context context; - public DBHelper(@Nullable Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; @@ -240,7 +232,7 @@ public ArrayList getMedicationsForPatient(String patient) { Medication medToAdd; int medId = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MED_ID))); - int dosage = Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MED_DOSAGE))); + float dosage = Float.parseFloat(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)); @@ -340,7 +332,7 @@ public ArrayList getMedications() { // Iterates through cursors to create instances of Medication object while (!meds.isAfterLast()) { int medId = Integer.parseInt(meds.getString(meds.getColumnIndexOrThrow(MED_ID))); - int dosage = meds.getInt(meds.getColumnIndexOrThrow(MED_DOSAGE)); + float dosage = meds.getFloat(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)); @@ -434,7 +426,7 @@ public Medication getMedication(long id) { cursor.getColumnIndexOrThrow(START_DATE))); int medId = cursor.getInt(cursor.getColumnIndexOrThrow(MED_ID)); int frequency = cursor.getInt(cursor.getColumnIndexOrThrow(MED_FREQUENCY)); - int dosage = cursor.getInt(cursor.getColumnIndexOrThrow(MED_DOSAGE)); + float dosage = cursor.getFloat(cursor.getColumnIndexOrThrow(MED_DOSAGE)); String alias = cursor.getString(cursor.getColumnIndexOrThrow(ALIAS)); String instructions = cursor.getString(cursor.getColumnIndexOrThrow(INSTRUCTIONS)); diff --git a/app/src/main/java/projects/medicationtracker/Helpers/NotificationHelper.java b/app/src/main/java/projects/medicationtracker/Helpers/NotificationHelper.java index be296243..89ab50eb 100644 --- a/app/src/main/java/projects/medicationtracker/Helpers/NotificationHelper.java +++ b/app/src/main/java/projects/medicationtracker/Helpers/NotificationHelper.java @@ -3,6 +3,8 @@ import static android.content.Context.ALARM_SERVICE; import static android.os.Build.VERSION.SDK_INT; +import static projects.medicationtracker.MediTrak.formatter; + import android.app.AlarmManager; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -126,7 +128,7 @@ private static String createMedicationReminderMessage(Medication medication, Con String message; String patientName = medication.getPatientName(); String medicationName = medication.getName(); - String dosage = medication.getDosage() + " " + medication.getDosageUnits(); + String dosage = formatter.format(medication.getDosage()) + " " + medication.getDosageUnits(); if (medication.getAlias() != null && !medication.getAlias().isEmpty()) medicationName = medication.getAlias(); diff --git a/app/src/main/java/projects/medicationtracker/InputFilters/DecimalPlacesFilter.java b/app/src/main/java/projects/medicationtracker/InputFilters/DecimalPlacesFilter.java new file mode 100644 index 00000000..bb2ee5ec --- /dev/null +++ b/app/src/main/java/projects/medicationtracker/InputFilters/DecimalPlacesFilter.java @@ -0,0 +1,56 @@ +package projects.medicationtracker.InputFilters; + +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.method.DigitsKeyListener; + +import java.util.Locale; + +public class DecimalPlacesFilter extends DigitsKeyListener { + + public DecimalPlacesFilter() { + super(Locale.getDefault(), false, true); + } + + @Override + public CharSequence filter( + CharSequence source, int start, int end, + Spanned dest, int dstart, int dend + ) { + CharSequence out = super.filter(source, start, end, dest, dstart, dend); + final int digits = 3; + String regex = "([.,])"; + + if (out != null) { + source = out; + start = 0; + end = out.length(); + } + + int len = end - start; + + if (len == 0) { + return source; + } + + String destString = dest.toString(); + + if (destString.contains(".") || destString.contains(",")) { + String[] split = destString.split(regex); + + return split.length == 2 && split[1].length() >= digits ? + "" : new SpannableStringBuilder(source, start, end); + } + + String sourceString = source.toString(); + + if (sourceString.contains(".") || sourceString.contains(",")) { + String[] split = sourceString.split(regex); + + return split.length == 2 && split[1].length() >= digits ? + "" : new SpannableStringBuilder(source, start, end); + } + + return new SpannableStringBuilder(source, start, end); + } +} diff --git a/app/src/main/java/projects/medicationtracker/MediTrak.java b/app/src/main/java/projects/medicationtracker/MediTrak.java index 7cf8d895..f85fc049 100644 --- a/app/src/main/java/projects/medicationtracker/MediTrak.java +++ b/app/src/main/java/projects/medicationtracker/MediTrak.java @@ -7,11 +7,15 @@ import androidx.annotation.NonNull; import androidx.work.Configuration; +import java.text.DecimalFormat; + import projects.medicationtracker.Helpers.DBHelper; import projects.medicationtracker.Helpers.NativeDbHelper; public class MediTrak extends Application implements Configuration.Provider { + public final static DecimalFormat formatter = new DecimalFormat("0.###"); + @NonNull @Override public Configuration getWorkManagerConfiguration() { diff --git a/app/src/main/java/projects/medicationtracker/MedicationHistory.java b/app/src/main/java/projects/medicationtracker/MedicationHistory.java index 91a89243..62324338 100644 --- a/app/src/main/java/projects/medicationtracker/MedicationHistory.java +++ b/app/src/main/java/projects/medicationtracker/MedicationHistory.java @@ -75,7 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { } Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setTitle(getString(R.string.history) + " - " + medication.getName()); + getSupportActionBar().setTitle(getString(R.string.history) + ": " + medication.getName()); getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { diff --git a/app/src/main/java/projects/medicationtracker/Models/Dose.java b/app/src/main/java/projects/medicationtracker/Models/Dose.java index 848f757a..cd89afdc 100644 --- a/app/src/main/java/projects/medicationtracker/Models/Dose.java +++ b/app/src/main/java/projects/medicationtracker/Models/Dose.java @@ -20,7 +20,7 @@ public class Dose { private long medId; private LocalDateTime timeTaken; private LocalDateTime doseTime; - private int overrideDoseAmount = -1; + private float overrideDoseAmount = -1; private String overrideDoseUnit = ""; /** @@ -49,7 +49,7 @@ public Dose(long id, long medicationId, boolean isTaken, @Nullable String timeTa this.doseTime = doseTime.length() == dateFormat.length() ? LocalDateTime.parse(doseTime, formatter) : null; } - public Dose(long id, long medicationId, boolean isTaken, @Nullable LocalDateTime timeTaken, @Nullable LocalDateTime doseTime, int overrideAmount, String overrideUnit) { + public Dose(long id, long medicationId, boolean isTaken, @Nullable LocalDateTime timeTaken, @Nullable LocalDateTime doseTime, float overrideAmount, String overrideUnit) { doseId = id; medId = medicationId; taken = isTaken; @@ -59,7 +59,7 @@ public Dose(long id, long medicationId, boolean isTaken, @Nullable LocalDateTime overrideDoseUnit = overrideUnit; } - public Dose(long id, long medicationId, boolean isTaken, String timeTaken, String doseTime, int overrideAmount, String overrideUnit) { + public Dose(long id, long medicationId, boolean isTaken, String timeTaken, String doseTime, float overrideAmount, String overrideUnit) { final String dateFormat = "yyyy-MM-dd HH:mm:ss"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat, Locale.getDefault()); @@ -154,11 +154,11 @@ public void setDoseTime(LocalDateTime doseTime) { this.doseTime = doseTime; } - public int getOverrideDoseAmount() { + public float getOverrideDoseAmount() { return overrideDoseAmount; } - public void setOverrideDoseAmount(int overrideDoseValue) { + public void setOverrideDoseAmount(float overrideDoseValue) { this.overrideDoseAmount = overrideDoseValue; } diff --git a/app/src/main/java/projects/medicationtracker/Models/Medication.java b/app/src/main/java/projects/medicationtracker/Models/Medication.java index 6128c1b5..0b211d60 100644 --- a/app/src/main/java/projects/medicationtracker/Models/Medication.java +++ b/app/src/main/java/projects/medicationtracker/Models/Medication.java @@ -28,7 +28,7 @@ public class Medication implements Cloneable, Parcelable { private Dose[] doses; private long medId; private int medFrequency; - private int medDosage; + private float medDosage; private boolean active; private Medication parent = null; private Medication child = null; @@ -48,7 +48,7 @@ public class Medication implements Cloneable, Parcelable { * @param medAlias An alias for the Medication to appear in notifications */ public Medication(String thisMed, String patient, String units, LocalDateTime[] time, - LocalDateTime firstDate, int id, int frequency, int dosage, String medAlias) { + LocalDateTime firstDate, int id, int frequency, float dosage, String medAlias) { medName = thisMed; patientName = patient; medDosageUnits = units; @@ -62,7 +62,7 @@ public Medication(String thisMed, String patient, String units, LocalDateTime[] } public Medication(String thisMed, String patient, String units, String[] times, - String firstDate, long id, int frequency, int dosage, String medAlias) { + String firstDate, long id, int frequency, float dosage, String medAlias) { final String dateFormat = "yyyy-MM-dd HH:mm:ss"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat, Locale.getDefault()); LocalDateTime[] medTimes = new LocalDateTime[times.length]; @@ -103,7 +103,7 @@ protected Medication(Parcel in) { alias = in.readString(); medId = in.readInt(); medFrequency = in.readInt(); - medDosage = in.readInt(); + medDosage = in.readFloat(); } public static final Creator CREATOR = new Creator() { @@ -150,7 +150,7 @@ public int getFrequency() { * * @return Medication dosage */ - public int getDosage() { + public float getDosage() { return medDosage; } @@ -258,7 +258,7 @@ public void setFrequency(int medFrequency) { * * @param medDosage dosage of Medication */ - public void setDosage(int medDosage) { + public void setDosage(float medDosage) { this.medDosage = medDosage; } @@ -419,6 +419,6 @@ public void writeToParcel(Parcel parcel, int i) { parcel.writeString(alias); parcel.writeLong(medId); parcel.writeLong(medFrequency); - parcel.writeInt(medDosage); + parcel.writeFloat(medDosage); } } diff --git a/app/src/main/res/layout/activity_add_medication.xml b/app/src/main/res/layout/activity_add_medication.xml index 7bf510a2..ee3fb709 100644 --- a/app/src/main/res/layout/activity_add_medication.xml +++ b/app/src/main/res/layout/activity_add_medication.xml @@ -162,7 +162,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:hint="@string/medication_dosage" - android:inputType="number" /> + android:inputType="numberDecimal" /> @@ -270,7 +270,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" - android:layout_marginBottom="15dp" android:hint="@string/start_date"> + android:inputType="numberDecimal"/>