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

View File

@@ -1,10 +1,18 @@
package com.schoolapp.cleverclass
import android.app.TimePickerDialog
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.widget.TimePicker
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
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.Info
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -38,12 +47,14 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.currentCompositionLocalContext
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
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.InputPrimaryColor
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
@@ -93,19 +121,25 @@ fun TimeTableSetupContent(activity: ComponentActivity){
),
focusedBorderColor = InputSecondaryColor,
unfocusedBorderColor = Color.Transparent
)
)
val sharedPreferences = activity.getSharedPreferences("TimeTable", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
var maxLessons by remember {
mutableStateOf(sharedPreferences.getString("maxLessons", "-1").toString())
}
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 {
@@ -114,6 +148,8 @@ fun TimeTableSetupContent(activity: ComponentActivity){
var showDeleteConfirmation by remember {
mutableStateOf(false)
}
val listOfDays = listOf("Mo", "Di", "Mi", "Do", "Fr")
Column {
TopAppBar(
@@ -165,7 +201,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
}
else if (activityType == "FirstSetup")
else if (activityType == "TimeSetup")
IconButton(onClick = { showInfo = !showInfo }) {
Icon(
imageVector = Icons.Outlined.Info,
@@ -174,78 +210,271 @@ fun TimeTableSetupContent(activity: ComponentActivity){
)
}
}
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = maxLessons,
onValueChange = { maxLessons = it },
placeholder = {
Text(
text = "Maximale Stundenanzahl an einem Tag",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primaryContainer
)
},
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors
)
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = lessonLength,
onValueChange = { lessonLength = it },
placeholder = {
Text(
text = "Länge einer Schulstunde",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primaryContainer
)
},
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = RoundedCornerShape(20),
textStyle = MaterialTheme.typography.labelMedium,
colors = inputFieldColors,
visualTransformation = if(showPassword) VisualTransformation.None else PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
trailingIcon = {
IconButton(onClick = { showPassword = !showPassword })
{
Image(
painter = painterResource(
id = if(showPassword)
R.drawable.baseline_visibility_24
else
R.drawable.baseline_visibility_off_24
),
contentDescription = null,
if (activityType == "TimeSetup") {
Text(
text = "Beginn der 1. Stunde",
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 ->
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))
OutlinedTextField(
value = lessonLength,
onValueChange = { lessonLength = it },
label = {
Text(
text = "Länge einer Schulstunde 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(16.dp))
OutlinedTextField(
value = breakAmnt,
onValueChange = { breakAmnt = it},
label = {
Text(
text = "Anzahl der Pausen"
)
},
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(
contentAlignment = Alignment.Center,
modifier = Modifier.clickable {
editor.putString("maxLessons", maxLessons)
editor.putString("lessonLength", lessonLength)
editor.apply()
activity.finish()
Row {
FilledTonalButton(
onClick = {
activity.finish()
},
modifier = Modifier
.padding(5.dp)
.weight(1f)
) {
Text(
text = "Abbrechen",
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium
)
}
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
)
}
}
) {
Text(
text = "Speichen",
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium,
modifier = Modifier.padding(10.dp)
)
}
}
}
@@ -257,7 +486,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
onDismissRequest = { showInfo = false },
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,
style = MaterialTheme.typography.labelMedium)
},
@@ -292,8 +521,7 @@ fun TimeTableSetupContent(activity: ComponentActivity){
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelMedium,
modifier = Modifier.clickable {
editor.putString("username", "")
editor.putString("password", "")
editor.putString("maxLessons", "")
editor.apply()
showDeleteConfirmation = false
activity.finish()
@@ -313,4 +541,11 @@ fun TimeTableSetupContent(activity: ComponentActivity){
containerColor = MaterialTheme.colorScheme.primaryContainer
)
}
}
@Composable
fun TestButton(text: String, onClick: ()-> Unit){
Button(onClick = onClick,) {
Text(text = text)
}
}