fix days evaluation
This commit is contained in:
		@@ -24,8 +24,8 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.Product
 | 
			
		||||
import org.foxarmy.barcodescannerforemployees.getActivity
 | 
			
		||||
import org.foxarmy.barcodescannerforemployees.getImageUri
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.time.Duration
 | 
			
		||||
import java.time.LocalDate
 | 
			
		||||
import java.time.Period
 | 
			
		||||
import java.time.format.DateTimeFormatter
 | 
			
		||||
 | 
			
		||||
class ProductView: LinearLayout {
 | 
			
		||||
@@ -103,19 +103,14 @@ class ProductView: LinearLayout {
 | 
			
		||||
    fun evaluateColor(): Int {
 | 
			
		||||
        val dateFormatter: DateTimeFormatter =  DateTimeFormatter.ofPattern("d.M.yyyy")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        val fresh = LocalDate.parse(product.dateOfProduction, 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)
 | 
			
		||||
        Log.d("QWERTYUIOP", today.toString())
 | 
			
		||||
 | 
			
		||||
        val daysBeforeExpiry = Period.between(today, expired).days
 | 
			
		||||
        val daysBeforeExpiry = Duration.between(today.atStartOfDay(), expired.atStartOfDay()).toDays()
 | 
			
		||||
 | 
			
		||||
        val freshnessPercentage: Double = daysBeforeExpiry / shelfLife.toDouble()
 | 
			
		||||
        Log.d("QWERTYUIOP", "$daysBeforeExpiry, $shelfLife, $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
 | 
			
		||||
 | 
			
		||||
        Log.d("QWERTYUIOP", "GP: $gradientPosition")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        val red = (startColor.red + gradientPosition * (endColor.red - startColor.red )).toInt()
 | 
			
		||||
        val green = (startColor.green  + gradientPosition * (endColor.green - startColor.green)).toInt()
 | 
			
		||||
        val blue = (startColor.blue + gradientPosition * (endColor.blue - startColor.blue)).toInt()
 | 
			
		||||
@@ -144,7 +136,6 @@ class ProductView: LinearLayout {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        val colorString = "#$redHex$greenHex$blueHex"
 | 
			
		||||
        Log.d("QWERTYUIOP", "Color: $colorString\nRGB:$red:$green:$blue")
 | 
			
		||||
        return Color.parseColor(colorString)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user