improved the displaying of averages with marks

This commit is contained in:
Odweta
2024-11-30 11:10:23 +01:00
parent 0a4ea395fd
commit 597971288e
2 changed files with 16 additions and 27 deletions
@@ -1,5 +1,6 @@
package com.odweta.solon
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -166,8 +167,13 @@ fun MarksAll() {
.background(Color.Black)
)
val currAvg = Util.avg(markList).replace(".", ",")
var textToShow = currAvg
if (currAvg.length == 3 && currAvg[2] == '0') {
textToShow = currAvg[0].toString()
}
Text(
text = Util.avg(markList).replace(".", ","),
text = textToShow,
fontSize = 28.sp,
color = Color.White,
textAlign = TextAlign.Center,
@@ -259,8 +265,13 @@ fun MarksSubject() {
.padding(vertical = 15.dp),
contentAlignment = Alignment.Center
) {
val currAvg = Util.avg(marks[subjectToShow]!!).replace(".", ",")
var textToShow = currAvg
if (currAvg.length == 3 && currAvg[2] == '0') {
textToShow = currAvg[0].toString()
}
Text(
text = Util.avg(marks[subjectToShow]!!).replace(".", ","),
text = textToShow,
color = Color.White,
textAlign = TextAlign.Center,
fontSize = 25.sp
@@ -1,37 +1,18 @@
package com.odweta.solon
import android.animation.Animator
import android.animation.AnimatorInflater
import android.animation.AnimatorListenerAdapter
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.app.ActivityManager
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Handler
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
import android.view.animation.AnimationUtils
import android.widget.Button
import androidx.compose.ui.graphics.Color
import androidx.core.content.ContextCompat
import androidx.core.content.pm.PackageInfoCompat
import androidx.core.content.res.ResourcesCompat
import com.odweta.solon.ui.theme.PastelGreenTransparent
import com.odweta.solon.ui.theme.PastelOrangeTransparent
import com.odweta.solon.ui.theme.PastelRedTransparent
import com.odweta.solon.ui.theme.PastelYellowTransparent
import java.io.File
import java.io.IOException
import java.nio.charset.Charset
import kotlin.math.round
class Util {
companion object {
@@ -146,10 +127,6 @@ class Util {
return false
}
fun pixelsToDp(pixels: Int, resources: Resources): Int {
return (pixels * resources.displayMetrics.density).toInt()
}
fun avg(marks: MutableList<Mark>): String {
var sum = 0f
var len = 0
@@ -170,7 +147,8 @@ class Util {
weights.add(mark.weight.toFloat())
}
return String.format("%.2f", (sum / sum(weights))).replace(',', '.')
return "${Math.round(sum/sum(weights) * 100f) / 100f}".replace(",", ".")
//return String.format("%.2f", (sum / sum(weights))).replace(',', '.')
}
private fun sum(nums: List<Float>): Float {