lecture notes now work and also added some cosmetic fixes
This commit is contained in:
Generated
+11
@@ -14,6 +14,17 @@
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1280" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="OPPO" />
|
||||
<option name="codename" value="OP573DL1" />
|
||||
<option name="id" value="OP573DL1" />
|
||||
<option name="manufacturer" value="OPPO" />
|
||||
<option name="name" value="CPH2557" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="28" />
|
||||
<option name="brand" value="DOCOMO" />
|
||||
|
||||
@@ -168,16 +168,16 @@ class LectureNote(
|
||||
id: Int,
|
||||
note: MutableState<String>,
|
||||
type: MutableState<LectureNoteType>,
|
||||
number: MutableState<Int>,
|
||||
lectureName: MutableState<String>
|
||||
number: Int,
|
||||
lectureName: 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("")
|
||||
var number: Int = 0
|
||||
var lectureName: String = ""
|
||||
|
||||
init {
|
||||
this.id = id
|
||||
@@ -188,7 +188,7 @@ class LectureNote(
|
||||
}
|
||||
}
|
||||
|
||||
var lectureNotes: HashMap<Int, MutableState<LectureNote>> = hashMapOf()
|
||||
var lectureNotes: HashMap<Int, LectureNote> = hashMapOf()
|
||||
var selectedLecture: Int = 0
|
||||
|
||||
var selectedDay: Int = 0
|
||||
|
||||
@@ -275,7 +275,7 @@ private fun launchPhase2(ctx: Context) {
|
||||
dayList.add(day)
|
||||
}
|
||||
|
||||
Util.loadLectureIds()
|
||||
Util.loadLectureNotes()
|
||||
|
||||
loaded = true
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<Mark>): 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<Int, MutableState<LectureNote>> {
|
||||
val hashMap = HashMap<Int, MutableState<LectureNote>>()
|
||||
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<Int, MutableState<LectureNote>>): String {
|
||||
private fun lectureNotesToCsvString(hashMap: HashMap<Int, LectureNote>): 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun saveLectureIds() {
|
||||
val toSave = hashMapToCsv(lectureNotes)
|
||||
csvToLectureNotes()
|
||||
}
|
||||
|
||||
fun saveLectureNotes() {
|
||||
val toSave = lectureNotesToCsvString(lectureNotes)
|
||||
saveStringToFile(lectureNotesFilePath, toSave)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user