Progressed with the Stundenplan

Progressed with the TimeTableSetupActivity -> (nearly done, only individual day setup left)
hardly progressed with the StundenplanActivity
switching back to Desktop tomorrow evening (progress from holidays)
This commit is contained in:
Matthias
2024-05-31 23:29:52 +02:00
parent 344aa1ef9f
commit ac7ce0ad3d
2 changed files with 312 additions and 80 deletions

View File

@@ -45,8 +45,7 @@ class StundenplanActivity : ComponentActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val sharedPreferences = this.getSharedPreferences("TimeTable", Context.MODE_PRIVATE) val sharedPreferences = this.getSharedPreferences("TimeTable", Context.MODE_PRIVATE)
val maxLessons = sharedPreferences.getString("maxLessons", "").toString() val setupDone = sharedPreferences.getBoolean("setupDone", false)
val lessonLength = sharedPreferences.getString("lessonLength", "").toString()
setContent { setContent {
CleverClassTheme { CleverClassTheme {
@@ -54,11 +53,9 @@ class StundenplanActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
) { ) {
println(maxLessons) if (!setupDone) {
//println(lessonLength)
if (maxLessons.isEmpty() || lessonLength.isEmpty()) {
val intent = Intent(this@StundenplanActivity, TimeTableSetupActivity::class.java).apply { val intent = Intent(this@StundenplanActivity, TimeTableSetupActivity::class.java).apply {
putExtra(TimeTableSetupActivity.TYPE_KEY, "FirstSetup") putExtra(TimeTableSetupActivity.TYPE_KEY, "TimeSetup")
} }
startActivity(intent) startActivity(intent)
} }

View File

@@ -1,10 +1,18 @@
package com.schoolapp.cleverclass package com.schoolapp.cleverclass
import android.app.TimePickerDialog
import android.content.Context import android.content.Context
import android.content.Intent
import android.icu.text.DecimalFormat
import android.icu.text.DecimalFormatSymbols
import android.icu.util.Calendar
import android.os.Bundle import android.os.Bundle
import android.widget.TimePicker
import android.widget.Toast
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@@ -27,6 +35,7 @@ import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Info import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
@@ -38,12 +47,14 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.currentCompositionLocalContext
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
@@ -53,6 +64,23 @@ import androidx.compose.ui.unit.dp
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
import com.schoolapp.cleverclass.ui.theme.InputPrimaryColor import com.schoolapp.cleverclass.ui.theme.InputPrimaryColor
import com.schoolapp.cleverclass.ui.theme.InputSecondaryColor import com.schoolapp.cleverclass.ui.theme.InputSecondaryColor
import org.intellij.lang.annotations.JdkConstants.CalendarMonth
import android.text.format.DateFormat
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.TextButton
import androidx.compose.ui.focus.focusModifier
import androidx.compose.ui.text.TextStyle
import java.util.Locale
import android.app.Activity
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.core.content.ContextCompat.startActivity
import com.schoolapp.cleverclass.PSEActivity
import kotlinx.coroutines.selects.select
private lateinit var activityType : String private lateinit var activityType : String
@@ -98,14 +126,20 @@ fun TimeTableSetupContent(activity: ComponentActivity){
val sharedPreferences = activity.getSharedPreferences("TimeTable", Context.MODE_PRIVATE) val sharedPreferences = activity.getSharedPreferences("TimeTable", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit() val editor = sharedPreferences.edit()
var maxLessons by remember {
mutableStateOf(sharedPreferences.getString("maxLessons", "-1").toString())
}
var lessonLength by remember { var lessonLength by remember {
mutableStateOf(sharedPreferences.getString("lessonLength", "-1").toString()) mutableStateOf(sharedPreferences.getInt("lessonLength", 0).toString())
} }
var showPassword by remember {
mutableStateOf(false) var breakAmnt by remember {
mutableStateOf(sharedPreferences.getInt("breakAmnt", 0).toString())
}
var firstLesson by remember {
mutableStateOf(sharedPreferences.getFloat("firstLesson", 0.0f))
}
var setupDone by remember {
mutableStateOf(sharedPreferences.getBoolean("setupDone", false))
} }
var showInfo by remember { var showInfo by remember {
@@ -115,6 +149,8 @@ fun TimeTableSetupContent(activity: ComponentActivity){
mutableStateOf(false) mutableStateOf(false)
} }
val listOfDays = listOf("Mo", "Di", "Mi", "Do", "Fr")
Column { Column {
TopAppBar( TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer), colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
@@ -165,7 +201,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
tint = MaterialTheme.colorScheme.onPrimaryContainer tint = MaterialTheme.colorScheme.onPrimaryContainer
) )
} }
else if (activityType == "FirstSetup") else if (activityType == "TimeSetup")
IconButton(onClick = { showInfo = !showInfo }) { IconButton(onClick = { showInfo = !showInfo }) {
Icon( Icon(
imageVector = Icons.Outlined.Info, imageVector = Icons.Outlined.Info,
@@ -177,33 +213,43 @@ fun TimeTableSetupContent(activity: ComponentActivity){
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField( if (activityType == "TimeSetup") {
value = maxLessons,
onValueChange = { maxLessons = it },
placeholder = {
Text( Text(
text = "Maximale Stundenanzahl an einem Tag", text = "Beginn der 1. Stunde",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primaryContainer
)
},
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
singleLine = true, style = MaterialTheme.typography.labelMedium
shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors
) )
OutlinedButton(
onClick = {
val c = Calendar.getInstance()
val mHour = c.get(Calendar.HOUR_OF_DAY)
val mMinute = c.get(Calendar.MINUTE)
val timePickerDialog = TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener(function = { view, h, m ->
firstLesson = h.toFloat() + (m.toFloat() / 100)
editor.putFloat("firstLesson", firstLesson)
}), mHour, mMinute, true)
timePickerDialog.show()
},
modifier = Modifier.align(Alignment.Start)
) {
val locale = Locale.getDefault()
val symbols = DecimalFormatSymbols(locale)
symbols.decimalSeparator = ':'
val decimalFormat = DecimalFormat("00.00", symbols)
Text(decimalFormat.format(firstLesson) + " Uhr ")
Icon(imageVector = Icons.Outlined.Edit, contentDescription = null)
}
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField( OutlinedTextField(
value = lessonLength, value = lessonLength,
onValueChange = { lessonLength = it }, onValueChange = { lessonLength = it },
placeholder = { label = {
Text( Text(
text = "Länge einer Schulstunde", text = "Länge einer Schulstunde in min"
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primaryContainer
) )
}, },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -211,42 +257,225 @@ fun TimeTableSetupContent(activity: ComponentActivity){
shape = RoundedCornerShape(20), shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium, textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors, colors = inputFieldColors,
visualTransformation = if(showPassword) VisualTransformation.None else PasswordVisualTransformation(), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword)
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), )
trailingIcon = {
IconButton(onClick = { showPassword = !showPassword }) Spacer(modifier = Modifier.height(16.dp))
{
Image( OutlinedTextField(
painter = painterResource( value = breakAmnt,
id = if(showPassword) onValueChange = { breakAmnt = it},
R.drawable.baseline_visibility_24 label = {
else Text(
R.drawable.baseline_visibility_off_24 text = "Anzahl der Pausen"
), )
contentDescription = null, },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword)
)
if (breakAmnt != "0" && breakAmnt != "") {
for (i in 0 until breakAmnt.toInt()) {
var currentBrakeStartTime by remember{
mutableStateOf(sharedPreferences.getFloat("Brake${i}StartTime", 0.0f))
}
var currentBrakeLength by remember{
mutableStateOf(sharedPreferences.getInt("Brake${i}Length", 0).toString())
}
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Startzeit der ${i + 1}. Pause:",
modifier = Modifier.fillMaxWidth(),
style = MaterialTheme.typography.labelMedium
)
OutlinedButton(
onClick = {
val c = Calendar.getInstance()
val mHour = c.get(Calendar.HOUR_OF_DAY)
val mMinute = c.get(Calendar.MINUTE)
val timePickerDialog = TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener(function = { view, h, m ->
currentBrakeStartTime = h.toFloat() + (m.toFloat() / 100)
editor.putFloat("Brake${i}StartTime", currentBrakeStartTime)
}), mHour, mMinute, true)
timePickerDialog.show()
},
modifier = Modifier.align(Alignment.Start)
) {
val locale = Locale.getDefault()
val symbols = DecimalFormatSymbols(locale)
symbols.decimalSeparator = ':'
val decimalFormat = DecimalFormat("00.00", symbols)
Text(decimalFormat.format(currentBrakeStartTime) + " Uhr ")
Icon(imageVector = Icons.Outlined.Edit, contentDescription = null)
}
Spacer(modifier = Modifier.height(5.dp))
OutlinedTextField(
value = currentBrakeLength,
onValueChange = {
currentBrakeLength = it
editor.putInt("Brake${i}Length", currentBrakeLength.toInt())},
label = {
Text(
text = "Länge der ${i + 1}. Pause in min"
)
},
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword)
) )
} }
} }
)
Spacer(modifier = Modifier.height(10.dp)) Spacer(modifier = Modifier.height(10.dp))
Box( Row {
contentAlignment = Alignment.Center, FilledTonalButton(
modifier = Modifier.clickable { onClick = {
editor.putString("maxLessons", maxLessons)
editor.putString("lessonLength", lessonLength)
editor.apply()
activity.finish() activity.finish()
} },
modifier = Modifier
.padding(5.dp)
.weight(1f)
) { ) {
Text( Text(
text = "Speichen", text = "Abbrechen",
color = MaterialTheme.colorScheme.secondary, color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium, style = MaterialTheme.typography.labelMedium
modifier = Modifier.padding(10.dp)
) )
} }
Spacer(modifier = Modifier
.width(5.dp)
)
Button(
onClick = {
editor.putInt("lessonLength", lessonLength.toInt())
if (breakAmnt == "0") {
editor.putInt("breakAmnt", -1)
}
else {
editor.putInt("breakAmnt", breakAmnt.toInt())
}
editor.apply()
activity.finish()
val intent = Intent(activity, TimeTableSetupActivity::class.java).apply {
putExtra(TimeTableSetupActivity.TYPE_KEY, "DaySetup")
}
startActivity(activity, intent, null)
},
modifier = Modifier
.padding(5.dp)
.weight(1f)
) {
Text(
text = "Weiter",
style = MaterialTheme.typography.labelMedium
)
}
}
}
else if (activityType == "DaySetup") {
var state by remember {
mutableStateOf(0)
}
TabRow(selectedTabIndex = state,
containerColor = MaterialTheme.colorScheme.primaryContainer) {
for (day in listOfDays) {
Tab(selected = false,
onClick = {
state = listOfDays.indexOf(day) },
modifier = Modifier.padding(5.dp),
) {
Text(
text = day,
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelMedium
)
}
sharedPreferences.getInt("AnzahlStunden${day}", 0)
}
}
when (state) {
0 -> {
Text(text = "Montag")
}
1 -> {
Text(text = "Dienstag")
}
2 -> {
Text(text = "Mittwoch")
}
3 -> {
Text(text = "Donnerstag")
}
4 -> {
Text(text = "Freitag")
}
}
Row () {
Text(
text = "Setup beendet? ",
modifier = Modifier.align(Alignment.CenterVertically),
style = MaterialTheme.typography.labelMedium
)
Checkbox(checked = setupDone, onCheckedChange = {setupDone = !setupDone})
}
Row {
FilledTonalButton(
onClick = {
activity.finish()
val intent = Intent(activity, TimeTableSetupActivity::class.java).apply {
putExtra(TimeTableSetupActivity.TYPE_KEY, "TimeSetup")
}
startActivity(activity, intent, null)
},
modifier = Modifier
.padding(5.dp)
.weight(1f)
) {
Text(
text = "Zurück",
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium
)
}
Spacer(modifier = Modifier
.width(5.dp)
)
Button(
onClick = {
editor.putBoolean("setupDone", setupDone)
editor.apply()
activity.finish()
},
modifier = Modifier
.padding(5.dp)
.weight(1f)
) {
Text(
text = "Speichern",
style = MaterialTheme.typography.labelMedium
)
}
}
}
} }
} }
} }
@@ -257,7 +486,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
onDismissRequest = { showInfo = false }, onDismissRequest = { showInfo = false },
text = { text = {
Text( Text(
text = "Der Benutzername und das Passwort können später in den Einstellungen geändert werden", text = "Alle Eingaben können später geändert werden.",
color = MaterialTheme.colorScheme.onPrimaryContainer, color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelMedium) style = MaterialTheme.typography.labelMedium)
}, },
@@ -292,8 +521,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
color = MaterialTheme.colorScheme.secondary, color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium, style = MaterialTheme.typography.labelMedium,
modifier = Modifier.clickable { modifier = Modifier.clickable {
editor.putString("username", "") editor.putString("maxLessons", "")
editor.putString("password", "")
editor.apply() editor.apply()
showDeleteConfirmation = false showDeleteConfirmation = false
activity.finish() activity.finish()
@@ -314,3 +542,10 @@ fun TimeTableSetupContent(activity: ComponentActivity){
) )
} }
} }
@Composable
fun TestButton(text: String, onClick: ()-> Unit){
Button(onClick = onClick,) {
Text(text = text)
}
}