-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
429 fractional stock for the refill reminder (#438)
* Change database fields to double * Proper formatting and conversion * Rename .java to .kt * Finish implementation * Compile fix * Update screenshots * Allow flaky test * Fix unit test * Update documentation * Fix refilling * Allow flaky test * Minor refactoring
- Loading branch information
Showing
140 changed files
with
221 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.futsch1.medtimer.helpers | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import com.futsch1.medtimer.R | ||
import com.futsch1.medtimer.database.Medicine | ||
import java.text.NumberFormat | ||
import java.util.regex.Pattern | ||
|
||
object MedicineHelper { | ||
private val CYCLIC_COUNT: Pattern = Pattern.compile(" (\\(\\d?/\\d?)\\)") | ||
|
||
@JvmStatic | ||
fun normalizeMedicineName(medicineName: String): String { | ||
return CYCLIC_COUNT.matcher(medicineName).replaceAll("") | ||
} | ||
|
||
@JvmStatic | ||
@SuppressLint("DefaultLocale") | ||
fun getMedicineNameWithStockText(context: Context, medicine: Medicine): String { | ||
return if (medicine.isStockManagementActive) { | ||
medicine.name + " (" + context.getString( | ||
R.string.medicine_stock_string, | ||
formatAmount(medicine.amount), | ||
if (medicine.amount <= medicine.outOfStockReminderThreshold) " ⚠)" else ")" | ||
) | ||
} else { | ||
medicine.name | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun formatAmount(amount: Double): String { | ||
val numberFormat = NumberFormat.getNumberInstance() | ||
numberFormat.minimumFractionDigits = 0 | ||
numberFormat.maximumFractionDigits = 2 | ||
return numberFormat.format(amount) | ||
} | ||
|
||
fun parseAmount(amount: String): Double? { | ||
val numberRegex = Pattern.compile("\\d+(?:[.,]\\d+)?") | ||
val matcher = numberRegex.matcher(amount) | ||
|
||
return if (matcher.find() && matcher.group(0) != null) { | ||
matcher.group(0)?.replace(',', '.')?.toDoubleOrNull() | ||
} else { | ||
null | ||
} | ||
} | ||
} |
Oops, something went wrong.