Skip to content

Commit

Permalink
Merge pull request #133 from avipars/patch-1
Browse files Browse the repository at this point in the history
Update AddMedication.java
  • Loading branch information
AdamGuidarini authored Dec 3, 2024
2 parents 81b0405 + f7254e0 commit 62e582a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/projects/medicationtracker/AddMedication.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,27 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@Override
public void afterTextChanged(Editable editable) {
dosageAmountInputLayout.setErrorEnabled(false);
String text = editable.toString();

if (editable.toString().isEmpty()) {
if (text.isEmpty() || text.endsWith(".")) {
isMedDosageValid = false;
dosageAmountInputLayout.setError(getString(R.string.err_enter_dosage));
} else {
try {
Float.parseFloat(dosageAmountInput.getText().toString());
isMedDosageValid = true;

if (!text.isEmpty() && Float.parseFloat(text) != amount && medId != -1) {
applyRetroactiveCard.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
isMedDosageValid = false; //invalid dosage as not a valid float
if (!dosageAmountInput.getText().toString().isEmpty()) {
dosageAmountInputLayout.setError(getString(R.string.val_too_big));
isMedDosageValid = false;
}
}
}

if (!editable.toString().isEmpty() && Float.parseFloat(editable.toString()) != amount && medId != -1) {
applyRetroactiveCard.setVisibility(View.VISIBLE);
}

validateForm();
}
});
Expand Down Expand Up @@ -1625,4 +1626,4 @@ private void validateForm() {

saveButton.setEnabled(allValid);
}
}
}

0 comments on commit 62e582a

Please sign in to comment.