improved the displaying of averages with marks
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.odweta.solon
|
package com.odweta.solon
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
@@ -166,8 +167,13 @@ fun MarksAll() {
|
|||||||
.background(Color.Black)
|
.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(
|
||||||
text = Util.avg(markList).replace(".", ","),
|
text = textToShow,
|
||||||
fontSize = 28.sp,
|
fontSize = 28.sp,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
@@ -259,8 +265,13 @@ fun MarksSubject() {
|
|||||||
.padding(vertical = 15.dp),
|
.padding(vertical = 15.dp),
|
||||||
contentAlignment = Alignment.Center
|
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(
|
||||||
text = Util.avg(marks[subjectToShow]!!).replace(".", ","),
|
text = textToShow,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
fontSize = 25.sp
|
fontSize = 25.sp
|
||||||
|
|||||||
@@ -1,37 +1,18 @@
|
|||||||
package com.odweta.solon
|
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.app.ActivityManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
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.ConnectivityManager
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.util.Log
|
|
||||||
import android.view.WindowManager
|
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.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.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
import kotlin.math.round
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -146,10 +127,6 @@ class Util {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pixelsToDp(pixels: Int, resources: Resources): Int {
|
|
||||||
return (pixels * resources.displayMetrics.density).toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun avg(marks: MutableList<Mark>): String {
|
fun avg(marks: MutableList<Mark>): String {
|
||||||
var sum = 0f
|
var sum = 0f
|
||||||
var len = 0
|
var len = 0
|
||||||
@@ -170,7 +147,8 @@ class Util {
|
|||||||
weights.add(mark.weight.toFloat())
|
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 {
|
private fun sum(nums: List<Float>): Float {
|
||||||
|
|||||||
Reference in New Issue
Block a user