you can now add notes to every lecture and they will automatically be saved locally

This commit is contained in:
Odweta
2024-12-15 00:05:44 +01:00
parent e67f87864c
commit a163d6b285
3 changed files with 72 additions and 41 deletions
@@ -138,7 +138,8 @@ var resetNav: Boolean = false
var isAPISetUp: Boolean = false
var lectureNotes: HashMap<Int, String> = hashMapOf()
var lectureNotes: HashMap<Int, MutableState<String>> = hashMapOf()
var selectedLecture: Int = 0
var selectedDay: Int = 0
var dayEndString: String = ""
@@ -1,6 +1,7 @@
package com.odweta.solon
import android.annotation.SuppressLint
import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
@@ -58,6 +59,8 @@ import java.time.LocalTime
import java.time.format.DateTimeFormatter
import kotlin.math.abs
var showDetailDialog = mutableStateOf(false)
@Composable
fun TimetableScreen() {
Box(
@@ -66,11 +69,59 @@ fun TimetableScreen() {
contentAlignment = Alignment.BottomCenter
) {
DayPager()
//if (settings.showRefreshButton.checked.value) {
// RefreshButton()
//}
if (showDetailDialog.value) {
DetailDialog()
}
}
}
@SuppressLint("UnrememberedMutableState")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DetailDialog(modifier: Modifier = Modifier) {
Dialog(
onDismissRequest = { showDetailDialog.value = false }, // Close the dialog on dismiss
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true
),
content = {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp)
.background(
color = Color.Black,
shape = RoundedCornerShape(roundedCornerDimen)
)
) {
if (lectureNotes[selectedLecture] == null) {
lectureNotes[selectedLecture] = mutableStateOf("")
}
TextField(
value = lectureNotes[selectedLecture]!!.value,
onValueChange = { newText: String ->
lectureNotes[selectedLecture]!!.value = newText
Util.saveLectureIds()
},
placeholder = { Text("Sem můžete napsat poznámky k\u00A0této hodině.") },
colors = TextFieldDefaults.textFieldColors(
focusedTextColor = Color.White,
containerColor = Color.Black,
selectionColors = TextSelectionColors(
handleColor = PastelYellow,
backgroundColor = PastelYellowTransparent
),
cursorColor = PastelYellow,
focusedIndicatorColor = PastelYellow,
unfocusedIndicatorColor = PastelYellowTransparent
)
)
}
}
)
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
@@ -167,11 +218,9 @@ fun subjectModifier(d: Day, s: Subject, lectureNumber: Int): Modifier {
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun DayScreen(day: Day) {
val scrollState = rememberScrollState()
var showDetailDialog by remember { mutableStateOf(false) }
Column(modifier = Modifier.fillMaxSize()) {
Row(
@@ -200,6 +249,7 @@ private fun DayScreen(day: Day) {
.verticalScroll(scrollState)
) {
for ((subjectIndex, subject) in day.subjects.withIndex()) {
val lectureId = Util.getLectureId(day.date, subjectIndex)
val amoledModifier = if (settings.useAmoledMode.checked.value) {
Modifier
.width(50.dp)
@@ -368,36 +418,13 @@ private fun DayScreen(day: Day) {
}
}
Box(modifier = Modifier.fillMaxSize().zIndex(99f).clickable { showDetailDialog = true })
if (showDetailDialog) {
Dialog(
onDismissRequest = { showDetailDialog = false }, // Close the dialog on dismiss
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true
),
content = {
Box(
modifier = Modifier
.width(100.dp)
.height(100.dp)
.background(
color = Color.Black,
shape = RoundedCornerShape(roundedCornerDimen)
)
) {
TextField(
value = lectureNotes[Util.getLectureId(day.date, subjectIndex)] ?: "",
onValueChange = { newText ->
lectureNotes[Util.getLectureId(day.date, subjectIndex)] = newText
Util.saveLectureIds()
}
)
}
}
)
}
Box(modifier = Modifier
.fillMaxSize()
.zIndex(99f)
.clickable {
selectedLecture = lectureId
showDetailDialog.value = true
})
}
}
}
@@ -8,6 +8,8 @@ import android.net.NetworkCapabilities
import android.os.Build
import android.util.DisplayMetrics
import android.view.WindowManager
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.core.content.pm.PackageInfoCompat
import java.io.File
import java.io.IOException
@@ -266,8 +268,8 @@ class Util {
})
}
fun csvToHashMap(filePath: String): HashMap<Int, String> {
val hashMap = HashMap<Int, String>()
fun csvToHashMap(filePath: String): HashMap<Int, MutableState<String>> {
val hashMap = HashMap<Int, MutableState<String>>()
val lines = fileToString(filePath).lines()
for (line in lines) {
if (line.isBlank()) continue
@@ -277,17 +279,18 @@ class Util {
if (parts.size == 2) {
val key = parts[0].trim().toInt()
val value = parts[1].trim()
hashMap[key] = value
hashMap[key] = mutableStateOf("")
hashMap[key]!!.value = value
}
}
return hashMap
}
fun hashMapToCsv(hashMap: HashMap<Int, String>): String {
fun hashMapToCsv(hashMap: HashMap<Int, MutableState<String>>): String {
var result = ""
for ((key, value) in hashMap) {
result += "$key,$value\n"
result += "$key,${value.value}\n"
}
return result
}