fix days evaluation

This commit is contained in:
leca 2024-10-15 13:43:23 +03:00
parent 231419eb77
commit e8e2a50cad
1 changed files with 3 additions and 12 deletions

View File

@ -24,8 +24,8 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.Product
import org.foxarmy.barcodescannerforemployees.getActivity import org.foxarmy.barcodescannerforemployees.getActivity
import org.foxarmy.barcodescannerforemployees.getImageUri import org.foxarmy.barcodescannerforemployees.getImageUri
import java.io.File import java.io.File
import java.time.Duration
import java.time.LocalDate import java.time.LocalDate
import java.time.Period
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
class ProductView: LinearLayout { class ProductView: LinearLayout {
@ -103,19 +103,14 @@ class ProductView: LinearLayout {
fun evaluateColor(): Int { fun evaluateColor(): Int {
val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("d.M.yyyy") val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("d.M.yyyy")
val fresh = LocalDate.parse(product.dateOfProduction, dateFormatter) val fresh = LocalDate.parse(product.dateOfProduction, dateFormatter)
val expired = LocalDate.parse(product.dateOfExpiry, dateFormatter) val expired = LocalDate.parse(product.dateOfExpiry, dateFormatter)
val shelfLife = Period.between(fresh, expired).days val shelfLife = Duration.between(fresh.atStartOfDay(), expired.atStartOfDay()).toDays()
val today = LocalDate.parse(LocalDate.now().format(dateFormatter), dateFormatter) val today = LocalDate.parse(LocalDate.now().format(dateFormatter), dateFormatter)
Log.d("QWERTYUIOP", today.toString()) val daysBeforeExpiry = Duration.between(today.atStartOfDay(), expired.atStartOfDay()).toDays()
val daysBeforeExpiry = Period.between(today, expired).days
val freshnessPercentage: Double = daysBeforeExpiry / shelfLife.toDouble() val freshnessPercentage: Double = daysBeforeExpiry / shelfLife.toDouble()
Log.d("QWERTYUIOP", "$daysBeforeExpiry, $shelfLife, $freshnessPercentage")
return calculateFreshnessGradient(freshnessPercentage) return calculateFreshnessGradient(freshnessPercentage)
} }
@ -126,9 +121,6 @@ class ProductView: LinearLayout {
val gradientPosition = 1 - if (percentage > 0.5) (percentage - 0.5) * 2 else percentage * 2 val gradientPosition = 1 - if (percentage > 0.5) (percentage - 0.5) * 2 else percentage * 2
Log.d("QWERTYUIOP", "GP: $gradientPosition")
val red = (startColor.red + gradientPosition * (endColor.red - startColor.red )).toInt() val red = (startColor.red + gradientPosition * (endColor.red - startColor.red )).toInt()
val green = (startColor.green + gradientPosition * (endColor.green - startColor.green)).toInt() val green = (startColor.green + gradientPosition * (endColor.green - startColor.green)).toInt()
val blue = (startColor.blue + gradientPosition * (endColor.blue - startColor.blue)).toInt() val blue = (startColor.blue + gradientPosition * (endColor.blue - startColor.blue)).toInt()
@ -144,7 +136,6 @@ class ProductView: LinearLayout {
val colorString = "#$redHex$greenHex$blueHex" val colorString = "#$redHex$greenHex$blueHex"
Log.d("QWERTYUIOP", "Color: $colorString\nRGB:$red:$green:$blue")
return Color.parseColor(colorString) return Color.parseColor(colorString)
} }
} }