Finish NotenActivity and FachActivity
This commit is contained in:
@@ -3,9 +3,11 @@ package com.schoolapp.cleverclass
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.SharedPreferences.Editor
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -20,9 +22,12 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.BottomAppBar
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -44,17 +49,46 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
|
||||
import com.schoolapp.cleverclass.ui.theme.TextOnColouredButton
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
val subjects = listOf("Biologie","Chemie","Deutsch","Englisch","Ethik","Evangelisch","Französisch",
|
||||
"Geographie","Geschichte","Informatik","Katolisch","Kunst","Latein","Mathe","Musik","Physik",
|
||||
"Pulitik und Gesellschaft","Sport","Wirtschaft")
|
||||
private val subjects = listOf(
|
||||
"Mathe", "Deutsch", "Englisch", "Französisch", "Latein",
|
||||
"Physik", "Chemie", "Biologie", "Informatik",
|
||||
"Geographie", "Wirtschaft", "Geschichte", "Politik und Gesellschaft",
|
||||
"Ethik", "Evangelisch", "Katholisch",
|
||||
"Kunst", "Musik", "Sport"
|
||||
)
|
||||
|
||||
val colors = listOf(
|
||||
Color(0xFF69F0AE),
|
||||
Color(0xFFEEFF41),
|
||||
Color(0xFFFFAB40),
|
||||
private val saWeights = listOf(
|
||||
2, 2, 2, 2, 2,
|
||||
1, 1, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0
|
||||
)
|
||||
|
||||
private val colorsA = listOf(
|
||||
Color(0xFF536DFE),
|
||||
Color(0xFF18FFFF),
|
||||
Color(0xFFB2FF59))
|
||||
Color(0xFF448AFF),
|
||||
Color(0xFF64FFDA),
|
||||
Color(0xFF40C4FF)
|
||||
)
|
||||
private val colorsB = listOf(
|
||||
Color(0xFFFFFF00),
|
||||
Color(0xFFFFAB40),
|
||||
Color(0xFFFFD740),
|
||||
Color(0xFFEEFF41)
|
||||
)
|
||||
private val colorsC = listOf(
|
||||
Color(0xFFFF5252),
|
||||
Color(0xFFFF4081),
|
||||
Color(0xFFFF6052),
|
||||
Color(0xFFFF6E40)
|
||||
)
|
||||
|
||||
|
||||
class NotenActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -77,10 +111,14 @@ class NotenActivity : ComponentActivity() {
|
||||
@Composable
|
||||
fun NotenContent(activity: ComponentActivity){
|
||||
val sharedPreferences = activity.getSharedPreferences("gradeAverages", Context.MODE_PRIVATE)
|
||||
val editor = sharedPreferences.edit()
|
||||
|
||||
var allAverage by remember {
|
||||
mutableStateOf(calculateAllAverage(loadAllAverages(sharedPreferences)))
|
||||
}
|
||||
var showDeleteConfirmation by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -101,6 +139,16 @@ fun NotenContent(activity: ComponentActivity){
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { showDeleteConfirmation = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Delete,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(28.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
},
|
||||
@@ -126,31 +174,114 @@ fun NotenContent(activity: ComponentActivity){
|
||||
}
|
||||
}
|
||||
) {innerPadding ->
|
||||
Column(modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(innerPadding))
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(innerPadding)
|
||||
)
|
||||
{
|
||||
subjects.forEach { name ->
|
||||
GroopTitle("Hauptfächer", true)
|
||||
for (i in 0..4){
|
||||
FachButton(
|
||||
color = colors.random(),
|
||||
subject = name,
|
||||
saWeight = 2,
|
||||
color = colorsA[i],
|
||||
subject = subjects[i],
|
||||
saWeight = saWeights[i],
|
||||
activity = activity,
|
||||
sharedPreferences = sharedPreferences,
|
||||
onAvgChange = { allAverage = calculateAllAverage(loadAllAverages(sharedPreferences)) }
|
||||
)
|
||||
}
|
||||
|
||||
GroopTitle("Naturwissenschaften", false)
|
||||
for (i in 5..8){
|
||||
FachButton(
|
||||
color = colorsB[i - 5],
|
||||
subject = subjects[i],
|
||||
saWeight = saWeights[i],
|
||||
activity = activity,
|
||||
sharedPreferences = sharedPreferences,
|
||||
onAvgChange = { allAverage = calculateAllAverage(loadAllAverages(sharedPreferences)) }
|
||||
)
|
||||
}
|
||||
|
||||
GroopTitle("Gesellschaftswissenschaften", false)
|
||||
for (i in 9..12){
|
||||
FachButton(
|
||||
color = colorsC[i - 9],
|
||||
subject = subjects[i],
|
||||
saWeight = saWeights[i],
|
||||
activity = activity,
|
||||
sharedPreferences = sharedPreferences,
|
||||
onAvgChange = { allAverage = calculateAllAverage(loadAllAverages(sharedPreferences)) }
|
||||
)
|
||||
}
|
||||
|
||||
GroopTitle("Religionen", false)
|
||||
for (i in 13..15){
|
||||
FachButton(
|
||||
color = colorsA[i - 13],
|
||||
subject = subjects[i],
|
||||
saWeight = saWeights[i],
|
||||
activity = activity,
|
||||
sharedPreferences = sharedPreferences,
|
||||
onAvgChange = { allAverage = calculateAllAverage(loadAllAverages(sharedPreferences)) }
|
||||
)
|
||||
}
|
||||
|
||||
GroopTitle("Sonstiges", false)
|
||||
for (i in 16..18){
|
||||
FachButton(
|
||||
color = colorsB[i - 16],
|
||||
subject = subjects[i],
|
||||
saWeight = saWeights[i],
|
||||
activity = activity,
|
||||
sharedPreferences = sharedPreferences,
|
||||
onAvgChange = { allAverage = calculateAllAverage(loadAllAverages(sharedPreferences)) }
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
if (showDeleteConfirmation){
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDeleteConfirmation = false },
|
||||
text = { Text(text = "Möchten Sie wirklich alle Noten aus Allen Fächern löschen?", color = MaterialTheme.colorScheme.onPrimaryContainer, style = MaterialTheme.typography.labelMedium) },
|
||||
confirmButton = {
|
||||
Row(modifier = Modifier.fillMaxWidth()){
|
||||
Text(
|
||||
text = "Bestätigen",
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
modifier = Modifier.clickable {
|
||||
deleteAll(editor, activity)
|
||||
showDeleteConfirmation = false
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Text(
|
||||
text = "Abbrechen",
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
modifier = Modifier.clickable { showDeleteConfirmation = false }
|
||||
)
|
||||
}
|
||||
},
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FachButton(
|
||||
color : Color,
|
||||
subject : String,
|
||||
saWeight: Int, activity :
|
||||
ComponentActivity,
|
||||
saWeight: Int,
|
||||
activity: ComponentActivity,
|
||||
sharedPreferences: SharedPreferences,
|
||||
onAvgChange: () -> Unit){
|
||||
var avg by remember {
|
||||
@@ -176,7 +307,7 @@ fun FachButton(
|
||||
color = TextOnColouredButton,
|
||||
style = MaterialTheme.typography.labelMedium)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(text = "Ø${formatFloat(avg)}",
|
||||
Text(text = if (avg != 0.0f) "Ø${formatFloat(avg)}" else "---",
|
||||
color = TextOnColouredButton,
|
||||
style = MaterialTheme.typography.labelMedium)
|
||||
}
|
||||
@@ -201,6 +332,17 @@ fun FachButton(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun GroopTitle(name: String, top: Boolean){
|
||||
if(!top) {
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
Divider()
|
||||
}
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
Text(text = name, style = MaterialTheme.typography.headlineSmall, color = MaterialTheme.colorScheme.onBackground)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
}
|
||||
|
||||
fun calculateAllAverage(avgs: List<Float>): Float{
|
||||
var total = 0.0f
|
||||
var number = 0
|
||||
@@ -223,3 +365,12 @@ fun loadAllAverages(sharedPreferences: SharedPreferences): List<Float>{
|
||||
|
||||
return avgs
|
||||
}
|
||||
|
||||
fun deleteAll(editor: Editor, context: Context){
|
||||
subjects.forEach{name ->
|
||||
editor.putFloat(name, 0.0f).apply()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
GradeStoreManager.saveGrades(context, emptyList(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user