diff --git a/mobile/.idea/caches/deviceStreaming.xml b/mobile/.idea/caches/deviceStreaming.xml
index b81700b..406736c 100644
--- a/mobile/.idea/caches/deviceStreaming.xml
+++ b/mobile/.idea/caches/deviceStreaming.xml
@@ -14,6 +14,17 @@
+
+
+
+
+
+
+
+
+
+
+
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 bf802c1..a3c9caa 100644
--- a/mobile/app/src/main/java/com/odweta/solon/Global.kt
+++ b/mobile/app/src/main/java/com/odweta/solon/Global.kt
@@ -168,16 +168,16 @@ class LectureNote(
id: Int,
note: MutableState,
type: MutableState,
- number: MutableState,
- lectureName: MutableState
+ number: Int,
+ lectureName: String
) {
var id: Int = 0
var note: MutableState =
mutableStateOf("")
var type: MutableState =
mutableStateOf(LectureNoteType.Normal)
- var number: MutableState = mutableIntStateOf(0)
- var lectureName: MutableState = mutableStateOf("")
+ var number: Int = 0
+ var lectureName: String = ""
init {
this.id = id
@@ -188,7 +188,7 @@ class LectureNote(
}
}
-var lectureNotes: HashMap> = hashMapOf()
+var lectureNotes: HashMap = hashMapOf()
var selectedLecture: Int = 0
var selectedDay: Int = 0
diff --git a/mobile/app/src/main/java/com/odweta/solon/Launch.kt b/mobile/app/src/main/java/com/odweta/solon/Launch.kt
index 6cc6b49..10e64bb 100644
--- a/mobile/app/src/main/java/com/odweta/solon/Launch.kt
+++ b/mobile/app/src/main/java/com/odweta/solon/Launch.kt
@@ -275,7 +275,7 @@ private fun launchPhase2(ctx: Context) {
dayList.add(day)
}
- Util.loadLectureIds()
+ Util.loadLectureNotes()
loaded = true
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 1afea78..95bf245 100644
--- a/mobile/app/src/main/java/com/odweta/solon/Timetable.kt
+++ b/mobile/app/src/main/java/com/odweta/solon/Timetable.kt
@@ -110,11 +110,12 @@ fun DetailDialog() {
) {
Text(
text = "" +
- lectureNotes[selectedLecture]?.value?.number?.value.toString() +
+ lectureNotes[selectedLecture]?.number.toString() +
" – " +
- lectureNotes[selectedLecture]?.value?.lectureName?.value.toString(),
+ lectureNotes[selectedLecture]?.lectureName.toString(),
color = Color.White,
- textAlign = TextAlign.Left
+ textAlign = TextAlign.Left,
+ modifier = Modifier.padding(top = 10.dp)
)
///////////////////////////////////////////////////////////
@@ -134,7 +135,7 @@ fun DetailDialog() {
disabledContentColor = Color.White
)
) {
- val type = when (lectureNotes[selectedLecture]?.value?.type?.value) {
+ val type = when (lectureNotes[selectedLecture]?.type?.value) {
LectureNoteType.Normal -> "Normální"
LectureNoteType.Writing -> "Písemný test"
LectureNoteType.Speaking -> "Ústní zkoušení"
@@ -159,8 +160,8 @@ fun DetailDialog() {
enabled = true,
onClick = {
isExpanded = false
- lectureNotes[selectedLecture]?.value?.type?.value =
- LectureNoteType.Normal
+ lectureNotes[selectedLecture]?.type?.value = LectureNoteType.Normal
+ Util.saveLectureNotes()
},
text = { Text("Normální poznámka", color = Color.White) }
)
@@ -169,8 +170,8 @@ fun DetailDialog() {
enabled = true,
onClick = {
isExpanded = false
- lectureNotes[selectedLecture]?.value?.type?.value =
- LectureNoteType.Writing
+ lectureNotes[selectedLecture]?.type?.value = LectureNoteType.Writing
+ Util.saveLectureNotes()
},
text = { Text("Písemný test", color = Color.White) }
)
@@ -179,8 +180,8 @@ fun DetailDialog() {
enabled = true,
onClick = {
isExpanded = false
- lectureNotes[selectedLecture]?.value?.type?.value =
- LectureNoteType.Speaking
+ lectureNotes[selectedLecture]?.type?.value = LectureNoteType.Speaking
+ Util.saveLectureNotes()
},
text = { Text("Ústní zkoušení", color = Color.White) }
)
@@ -189,8 +190,8 @@ fun DetailDialog() {
enabled = true,
onClick = {
isExpanded = false
- lectureNotes[selectedLecture]?.value?.type?.value =
- LectureNoteType.Other
+ lectureNotes[selectedLecture]?.type?.value = LectureNoteType.Other
+ Util.saveLectureNotes()
},
text = { Text("Jiné", color = Color.White) }
)
@@ -198,24 +199,13 @@ fun DetailDialog() {
////////////////////////////////////////////////
- if (lectureNotes[selectedLecture] == null) {
- lectureNotes[selectedLecture] = mutableStateOf(
- LectureNote(
- id = 0,
- note = mutableStateOf(""),
- type = mutableStateOf(LectureNoteType.Normal),
- number = mutableIntStateOf(0),
- lectureName = mutableStateOf("N/A")
- )
- )
- }
-
TextField(
- value = lectureNotes[selectedLecture]?.value?.note?.value ?: "",
+ value = lectureNotes[selectedLecture]?.note?.value ?: "",
onValueChange = { newText: String ->
- lectureNotes[selectedLecture]?.value?.note?.value = newText
- Util.saveLectureIds()
+ lectureNotes[selectedLecture]?.note?.value = newText
+ Util.saveLectureNotes()
},
+ singleLine = true,
placeholder = { Text("Sem můžete napsat poznámky k\u00A0této hodině.") }, //
colors = TextFieldDefaults.textFieldColors(
focusedTextColor = Color.White,
@@ -363,17 +353,7 @@ private fun DayScreen(day: Day) {
) {
for ((subjectIndex, subject) in day.subjects.withIndex()) {
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) {
Modifier
.width(50.dp)
@@ -554,10 +534,9 @@ private fun DayScreen(day: Day) {
})
if (
- lectureNotes[lectureId] == null ||
- (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.value?.note?.value != "") ||
- (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.value?.type?.value != LectureNoteType.Normal) &&
- (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.value?.type?.value != LectureNoteType.Other)
+ (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.note?.value != "") ||
+ (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.type?.value != LectureNoteType.Normal) &&
+ (lectureNotes[lectureId] != null && lectureNotes[lectureId]?.type?.value != LectureNoteType.Other)
) {
Icon(
modifier = Modifier.padding(start = 3.dp, top = 1.dp),
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 097d2f8..0ec0743 100644
--- a/mobile/app/src/main/java/com/odweta/solon/Util.kt
+++ b/mobile/app/src/main/java/com/odweta/solon/Util.kt
@@ -1,6 +1,5 @@
package com.odweta.solon
-import android.app.ActivityManager
import android.content.Context
import android.content.pm.PackageManager
import android.net.ConnectivityManager
@@ -8,8 +7,6 @@ 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.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.core.content.pm.PackageInfoCompat
import java.io.File
@@ -17,7 +14,6 @@ import java.io.IOException
import java.nio.charset.Charset
import java.security.MessageDigest
import kotlin.math.abs
-import kotlin.math.round
class Util {
companion object {
@@ -119,7 +115,7 @@ class Util {
}
}
- fun isAppInForeground(context: Context, packageName: String): Boolean {
+ /*fun isAppInForeground(context: Context, packageName: String): Boolean {
val activityManager =
context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val runningAppProcesses = activityManager.runningAppProcesses ?: return false
@@ -132,7 +128,7 @@ class Util {
}
}
return false
- }
+ }*/
fun avg(marks: MutableList): String {
var sum = 0f
@@ -230,7 +226,7 @@ class Util {
packageManager.getPackageInfo(packageName, 0)
}
AppVersion(
- versionName = packageInfo.versionName,
+ versionName = packageInfo.versionName.toString(),
versionNumber = PackageInfoCompat.getLongVersionCode(packageInfo),
)
} catch (e: Exception) {
@@ -269,56 +265,57 @@ class Util {
})
}
- fun csvToHashMap(filePath: String): HashMap> {
- val hashMap = HashMap>()
- val lines = fileToString(filePath).lines()
+ private fun csvToLectureNotes() {
+ val lines = fileToString(lectureNotesFilePath).lines()
for (line in lines) {
if (line.isBlank()) continue
val parts = line.split(",")
- if (parts.size == 5) {
+ if (parts.size >= 3) {
val id = parts[0].trim().toInt()
- val note = parts[1].trim()
- val type = parts[2].trim().toLectureNoteType()
- val number = parts[3].trim().toInt()
- val lectureName = parts[4].trim()
+ val type = parts[1].trim().toLectureNoteType()
+ var note = parts[2].trim()
+ for (part in 3.until(parts.size)) {
+ note += ",${parts[part]}"
+ }
- val lectureNote = LectureNote(
- id,
- mutableStateOf(note),
- mutableStateOf(type),
- mutableIntStateOf(number),
- mutableStateOf(lectureName)
- )
-
- hashMap[id] = mutableStateOf(lectureNote)
+ lectureNotes[id]?.note = mutableStateOf(note)
+ lectureNotes[id]?.type = mutableStateOf(type)
}
}
-
- return hashMap
}
- fun hashMapToCsv(hashMap: HashMap>): String {
+ private fun lectureNotesToCsvString(hashMap: HashMap): String {
var result = ""
for ((key, lectureNote) in hashMap) {
result +=
"$key," +
- "${lectureNote.value.note.value}," +
- "${lectureNote.value.type.value}," +
- "${lectureNote.value.number.value}," +
- lectureNote.value.lectureName.value +
- "\n"
+ "${lectureNote.type.value}," +
+ "${lectureNote.note.value}\n"
}
return result
}
- fun loadLectureIds() {
- lectureNotes = csvToHashMap(lectureNotesFilePath)
+ fun loadLectureNotes() {
+ for (day in days) {
+ for ((subjectIndex, subject) in day.subjects.withIndex()) {
+ val id = getLectureId(day.date, subjectIndex)
+ lectureNotes[id] = LectureNote(
+ id = id,
+ type = mutableStateOf(LectureNoteType.Normal),
+ note = mutableStateOf(""),
+ number = subject.number.toInt(),
+ lectureName = subject.name
+ )
+ }
+ }
+
+ csvToLectureNotes()
}
- fun saveLectureIds() {
- val toSave = hashMapToCsv(lectureNotes)
+ fun saveLectureNotes() {
+ val toSave = lectureNotesToCsvString(lectureNotes)
saveStringToFile(lectureNotesFilePath, toSave)
}
}