Stundenplan bugfixes
fixed indexing with wrong variable for breaks in core added compatibility for lessons without subject, room or teacher added horizontal scroll for too long user input added info icon with alert dialog for scroll explanation
This commit is contained in:
@@ -7,21 +7,23 @@ import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.Edit
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -31,6 +33,10 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
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.text.style.TextDecoration
|
||||
@@ -56,7 +62,7 @@ class StundenplanActivity : ComponentActivity() {
|
||||
|
||||
//Loading saved lessons when NOT auto-loading the setup
|
||||
if (setupDone) {
|
||||
listOfDays.forEachIndexed() { index, dayLessons ->
|
||||
listOfDays.forEachIndexed { index, dayLessons ->
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
getLessons(this@StundenplanActivity, dayLessons).collect { savedLessons ->
|
||||
lessons[index] = savedLessons.toMutableList()
|
||||
@@ -102,7 +108,11 @@ fun StundenplanContent(activity: ComponentActivity, loadedLessons: List<List<Les
|
||||
listOfBreakLengths.add(sharedPreferences.getInt("break${i}Length", 0))
|
||||
}
|
||||
|
||||
Column() {
|
||||
var showInfo by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
Column {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
|
||||
title = {
|
||||
@@ -121,6 +131,16 @@ fun StundenplanContent(activity: ComponentActivity, loadedLessons: List<List<Les
|
||||
}
|
||||
},
|
||||
actions ={
|
||||
//Info button
|
||||
IconButton(
|
||||
onClick = { showInfo = !showInfo }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(28.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
//Edit button
|
||||
IconButton(
|
||||
onClick = {
|
||||
@@ -157,16 +177,18 @@ fun StundenplanContent(activity: ComponentActivity, loadedLessons: List<List<Les
|
||||
)
|
||||
|
||||
//Creation of 5 Columns
|
||||
loadedLessons.forEachIndexed() { index, dailyLessons ->
|
||||
Column(modifier = Modifier.wrapContentWidth()) {
|
||||
loadedLessons.forEachIndexed { index, dailyLessons ->
|
||||
//Width variable for variable Box sizes
|
||||
Column(modifier = Modifier.width(250.dp)) {
|
||||
//Additional extraIndex to count lessons without breaks getting into the way
|
||||
var extraIndex = 0
|
||||
|
||||
//Box with the day on top of each Column()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(200.dp, 50.dp)
|
||||
.size(250.dp, 50.dp)
|
||||
.padding(3.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.primaryContainer
|
||||
@@ -186,8 +208,7 @@ fun StundenplanContent(activity: ComponentActivity, loadedLessons: List<List<Les
|
||||
if (listOfBreakIndexes.indexOf(i) != -1) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(200.dp, 100.dp)
|
||||
.padding(3.dp)
|
||||
.size(250.dp, 100.dp)
|
||||
)
|
||||
}
|
||||
//Else creation of a Box containing all the information from the LessonData object
|
||||
@@ -211,6 +232,29 @@ fun StundenplanContent(activity: ComponentActivity, loadedLessons: List<List<Les
|
||||
)
|
||||
}
|
||||
}
|
||||
if (showInfo) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showInfo = false },
|
||||
text = {
|
||||
Text(
|
||||
text = "Die Breite der Spalten ist auf eine bestimmte Größe festgelegt.\n\n" +
|
||||
"Zu lange eingaben können horizontal gescrollt werden.",
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
style = MaterialTheme.typography.labelMedium)
|
||||
},
|
||||
confirmButton = {
|
||||
Text(
|
||||
text = "Schließen",
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
modifier = Modifier.clickable { showInfo = false }
|
||||
)
|
||||
},
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
modifier = Modifier
|
||||
.padding(5.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//Data class to save objects via DataShare containing information about lessons
|
||||
@@ -225,22 +269,52 @@ data class LessonData(
|
||||
// contains the information from the corresponding LessonData object
|
||||
@Composable
|
||||
fun LessonBox(subject: String, teacher: String, room: String) {
|
||||
Box(modifier = Modifier
|
||||
.defaultMinSize(200.dp, 100.dp)
|
||||
.padding(3.dp)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(250.dp, 100.dp)
|
||||
.padding(3.dp)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
text = "$subject\n@$room\n/w$teacher",
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
Column {
|
||||
if (subject != "") {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.horizontalScroll(rememberScrollState())
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.padding(horizontal = 5.dp),
|
||||
text = subject,
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
if (room != "") {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.horizontalScroll(rememberScrollState())
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.padding(horizontal = 5.dp),
|
||||
text = room,
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
if (teacher != "") {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.horizontalScroll(rememberScrollState())
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.padding(horizontal = 5.dp),
|
||||
text = teacher,
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Left-/Right-Handed info Column
|
||||
@Composable
|
||||
fun InfoColumn(loadedLessons: List<List<LessonData>>, breakAmnt: Int, breaksStartTime: List<String>, firstLesson: String, lessonLength: Int, breaksLength: List<Int>) {
|
||||
@@ -314,8 +388,8 @@ fun InfoColumn(loadedLessons: List<List<LessonData>>, breakAmnt: Int, breaksStar
|
||||
lessonTimeIncrement += breaksLength[breaksStartTime.indexOf(breakTime)]
|
||||
//Add info that one moe brake exists to the indexing increment
|
||||
lessonNegIncrement++
|
||||
//Add the extraIndex (overallIndex) into the listOfBreakIndexes list to include breaks in timetable core
|
||||
listOfBreakIndexes.add(extraIndex)
|
||||
//Add the extraIndex (lessonIndex) into the listOfBreakIndexes list to include breaks in timetable core
|
||||
listOfBreakIndexes.add(i)
|
||||
//Prevent double creation of Boxes
|
||||
loopDone = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user