diff --git a/mobile/app/src/main/java/com/odweta/solon/Global.kt b/mobile/app/src/main/java/com/odweta/solon/Global.kt index e2fdee8..d4aa448 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Global.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Global.kt @@ -138,7 +138,8 @@ var resetNav: Boolean = false var isAPISetUp: Boolean = false -var lectureNotes: HashMap = hashMapOf() +var lectureNotes: HashMap> = hashMapOf() +var selectedLecture: Int = 0 var selectedDay: Int = 0 var dayEndString: String = "" diff --git a/mobile/app/src/main/java/com/odweta/solon/Timetable.kt b/mobile/app/src/main/java/com/odweta/solon/Timetable.kt index 49002d6..be58c4a 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Timetable.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Timetable.kt @@ -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,12 +69,60 @@ 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 fun DayPager(modifier: Modifier = Modifier) { @@ -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 + }) } } } diff --git a/mobile/app/src/main/java/com/odweta/solon/Util.kt b/mobile/app/src/main/java/com/odweta/solon/Util.kt index 3f98dcc..5a9ae0f 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Util.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Util.kt @@ -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 { - val hashMap = HashMap() + fun csvToHashMap(filePath: String): HashMap> { + val hashMap = HashMap>() 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): String { + fun hashMapToCsv(hashMap: HashMap>): String { var result = "" for ((key, value) in hashMap) { - result += "$key,$value\n" + result += "$key,${value.value}\n" } return result }