improved lecture notes with a type and showing the name and number of the lecture

This commit is contained in:
Odweta
2024-12-16 09:53:19 +01:00
parent 3bb5ce5ca7
commit 8ddbdc43f9
3 changed files with 223 additions and 34 deletions
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@@ -138,7 +139,48 @@ var resetNav: Boolean = false
var isAPISetUp: Boolean = false var isAPISetUp: Boolean = false
var lectureNotes: HashMap<Int, MutableState<String>> = hashMapOf() enum class LectureNoteType {
Normal, // obycejna poznamka
Writing, // pisemny test
Speaking, // ustni zkouseni
Other // cokoliv jineho
}
fun String.toLectureNoteType(): LectureNoteType {
return when(this) {
"Normal" -> LectureNoteType.Normal
"Writing" -> LectureNoteType.Writing
"Speaking" -> LectureNoteType.Speaking
"Other" -> LectureNoteType.Other
else -> LectureNoteType.Normal
}
}
class LectureNote(
id: Int,
note: MutableState<String>,
type: MutableState<LectureNoteType>,
number: MutableState<Int>,
lectureName: MutableState<String>
) {
var id: Int = 0
var note: MutableState<String> =
mutableStateOf("")
var type: MutableState<LectureNoteType> =
mutableStateOf(LectureNoteType.Normal)
var number: MutableState<Int> = mutableIntStateOf(0)
var lectureName: MutableState<String> = mutableStateOf("")
init {
this.id = id
this.note = note
this.type = type
this.number = number
this.lectureName = lectureName
}
}
var lectureNotes: HashMap<Int, MutableState<LectureNote>> = hashMapOf()
var selectedLecture: Int = 0 var selectedLecture: Int = 0
var selectedDay: Int = 0 var selectedDay: Int = 0
@@ -23,22 +23,35 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.TextSelectionColors import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
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.focus.focusModifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.window.PopupProperties
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import com.odweta.solon.ui.theme.PastelGreen import com.odweta.solon.ui.theme.PastelGreen
import com.odweta.solon.ui.theme.PastelGreenTransparent import com.odweta.solon.ui.theme.PastelGreenTransparent
@@ -46,6 +59,8 @@ import com.odweta.solon.ui.theme.PastelRed
import com.odweta.solon.ui.theme.PastelRedTransparent import com.odweta.solon.ui.theme.PastelRedTransparent
import com.odweta.solon.ui.theme.PastelYellow import com.odweta.solon.ui.theme.PastelYellow
import com.odweta.solon.ui.theme.PastelYellowTransparent import com.odweta.solon.ui.theme.PastelYellowTransparent
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.time.LocalDate import java.time.LocalDate
import java.time.LocalTime import java.time.LocalTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@@ -86,17 +101,118 @@ fun DetailDialog() {
shape = RoundedCornerShape(roundedCornerDimen) shape = RoundedCornerShape(roundedCornerDimen)
) )
) { ) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "" +
lectureNotes[selectedLecture]?.value?.number?.value.toString() +
" " +
lectureNotes[selectedLecture]?.value?.lectureName?.value.toString(),
color = Color.White,
textAlign = TextAlign.Left
)
///////////////////////////////////////////////////////////
var isExpanded by remember { mutableStateOf(false) }
Button(
modifier = Modifier.background(
color = Color.Black,
shape = RoundedCornerShape(roundedCornerDimen)
),
onClick = { isExpanded = true },
colors = ButtonColors(
containerColor = Color.Black,
contentColor = Color.White,
disabledContainerColor = Color.Black,
disabledContentColor = Color.White
)
) {
val type = when (lectureNotes[selectedLecture]?.value?.type?.value) {
LectureNoteType.Normal -> "Normální"
LectureNoteType.Writing -> "Písemný test"
LectureNoteType.Speaking -> "Ústní zkoušení"
LectureNoteType.Other -> "Jiné"
else -> "Jiné"
}
Text("Typ poznámky: $type")
}
DropdownMenu(
modifier = Modifier.background(color = Color.Black),
onDismissRequest = { isExpanded = false },
expanded = isExpanded,
properties = PopupProperties(
excludeFromSystemGesture = false,
dismissOnClickOutside = true,
dismissOnBackPress = true,
focusable = true
),
) {
DropdownMenuItem(
enabled = true,
onClick = {
isExpanded = false
lectureNotes[selectedLecture]?.value?.type?.value =
LectureNoteType.Normal
},
text = { Text("Normální poznámka", color = Color.White) }
)
DropdownMenuItem(
enabled = true,
onClick = {
isExpanded = false
lectureNotes[selectedLecture]?.value?.type?.value =
LectureNoteType.Writing
},
text = { Text("Písemný test", color = Color.White) }
)
DropdownMenuItem(
enabled = true,
onClick = {
isExpanded = false
lectureNotes[selectedLecture]?.value?.type?.value =
LectureNoteType.Speaking
},
text = { Text("Ústní zkoušení", color = Color.White) }
)
DropdownMenuItem(
enabled = true,
onClick = {
isExpanded = false
lectureNotes[selectedLecture]?.value?.type?.value =
LectureNoteType.Other
},
text = { Text("Jiné", color = Color.White) }
)
}
////////////////////////////////////////////////
if (lectureNotes[selectedLecture] == null) { if (lectureNotes[selectedLecture] == null) {
lectureNotes[selectedLecture] = mutableStateOf("") lectureNotes[selectedLecture] = mutableStateOf(
LectureNote(
id = 0,
note = mutableStateOf(""),
type = mutableStateOf(LectureNoteType.Normal),
number = mutableIntStateOf(0),
lectureName = mutableStateOf("N/A")
)
)
} }
TextField( TextField(
value = lectureNotes[selectedLecture]!!.value, value = lectureNotes[selectedLecture]?.value?.note?.value ?: "",
onValueChange = { newText: String -> onValueChange = { newText: String ->
lectureNotes[selectedLecture]!!.value = newText lectureNotes[selectedLecture]?.value?.note?.value = newText
Util.saveLectureIds() Util.saveLectureIds()
}, },
placeholder = { Text("Sem můžete napsat poznámky k\u00A0této hodině.") }, placeholder = { Text("Sem můžete napsat poznámky k\u00A0této hodině.") }, // &nbsp;
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.textFieldColors(
focusedTextColor = Color.White, focusedTextColor = Color.White,
containerColor = Color.Black, containerColor = Color.Black,
@@ -111,6 +227,7 @@ fun DetailDialog() {
) )
} }
} }
}
) )
} }
@@ -209,6 +326,7 @@ fun subjectModifier(d: Day, s: Subject, lectureNumber: Int): Modifier {
} }
} }
@SuppressLint("UnrememberedMutableState")
@Composable @Composable
private fun DayScreen(day: Day) { private fun DayScreen(day: Day) {
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
@@ -241,6 +359,17 @@ private fun DayScreen(day: Day) {
) { ) {
for ((subjectIndex, subject) in day.subjects.withIndex()) { for ((subjectIndex, subject) in day.subjects.withIndex()) {
val lectureId = Util.getLectureId(day.date, subjectIndex) val lectureId = Util.getLectureId(day.date, subjectIndex)
if (lectureNotes[lectureId] == null) {
lectureNotes[lectureId] = mutableStateOf(LectureNote(
id = lectureId,
note = mutableStateOf(""),
type = mutableStateOf(LectureNoteType.Normal),
number = mutableIntStateOf(0),
lectureName = mutableStateOf("N/A")
))
}
lectureNotes[lectureId]?.value?.number?.value = subject.number.toInt()
lectureNotes[lectureId]?.value?.lectureName?.value = subject.name
val amoledModifier = if (settings.useAmoledMode.checked.value) { val amoledModifier = if (settings.useAmoledMode.checked.value) {
Modifier Modifier
.width(50.dp) .width(50.dp)
@@ -9,6 +9,7 @@ import android.os.Build
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.WindowManager import android.view.WindowManager
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.core.content.pm.PackageInfoCompat import androidx.core.content.pm.PackageInfoCompat
import java.io.File import java.io.File
@@ -268,29 +269,46 @@ class Util {
}) })
} }
fun csvToHashMap(filePath: String): HashMap<Int, MutableState<String>> { fun csvToHashMap(filePath: String): HashMap<Int, MutableState<LectureNote>> {
val hashMap = HashMap<Int, MutableState<String>>() val hashMap = HashMap<Int, MutableState<LectureNote>>()
val lines = fileToString(filePath).lines() val lines = fileToString(filePath).lines()
for (line in lines) { for (line in lines) {
if (line.isBlank()) continue if (line.isBlank()) continue
val parts = line.split(",") val parts = line.split(",")
if (parts.size == 2) { if (parts.size == 5) {
val key = parts[0].trim().toInt() val id = parts[0].trim().toInt()
val value = parts[1].trim() val note = parts[1].trim()
hashMap[key] = mutableStateOf("") val type = parts[2].trim().toLectureNoteType()
hashMap[key]!!.value = value val number = parts[3].trim().toInt()
val lectureName = parts[4].trim()
val lectureNote = LectureNote(
id,
mutableStateOf(note),
mutableStateOf(type),
mutableIntStateOf(number),
mutableStateOf(lectureName)
)
hashMap[id] = mutableStateOf(lectureNote)
} }
} }
return hashMap return hashMap
} }
fun hashMapToCsv(hashMap: HashMap<Int, MutableState<String>>): String { fun hashMapToCsv(hashMap: HashMap<Int, MutableState<LectureNote>>): String {
var result = "" var result = ""
for ((key, value) in hashMap) { for ((key, lectureNote) in hashMap) {
result += "$key,${value.value}\n" result +=
"$key," +
"${lectureNote.value.note.value}," +
"${lectureNote.value.type.value}," +
"${lectureNote.value.number.value}," +
lectureNote.value.lectureName.value +
"\n"
} }
return result return result
} }