removed comments

This commit is contained in:
Daniel Ocks
2025-08-01 12:03:29 +02:00
parent 1f496b5a0c
commit 26967f5618
3 changed files with 5 additions and 52 deletions

View File

@ -10,7 +10,6 @@ import kotlinx.coroutines.*
import org.json.JSONArray
import android.util.Log
// Global constants and values
var INTEGRATION_INDEX_POINTS: Int? = null
class HandlerOpeningScreen(private val activity: MainActivity) {
@ -170,11 +169,9 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
return@launch
}
// Profil ist gültig → entweder normal laden oder PDF erzeugen
withContext(Dispatchers.Main) {
if (isDatabaseView) {
// Profil laden + PDF erzeugen
handleNormalLoad(clientCode) // ← Option: Zeige auch Punktefarben etc.
handleNormalLoad(clientCode)
showCompletedQuestionnaires(clientCode)
} else {
handleNormalLoad(clientCode)
@ -237,10 +234,10 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
else -> true // fallback: zeige Fragebogen
}
if (conditionMet) break // Bedingung erfüllt → anzeigen
else nextIndex++ // überspringen
if (conditionMet) break
else nextIndex++
} else {
break // keine Bedingung → anzeigen
break
}
}
@ -258,7 +255,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
private fun updateButtonTexts() {
questionnaireFiles.forEach { (button, fileName) ->
// Suche passenden QuestionnaireEntry
val entry = questionnaireEntries.firstOrNull { it.file == fileName }
val key = fileName.substringAfter("questionnaire_").substringAfter("_").removeSuffix(".json")
@ -273,7 +269,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
button.text = buttonText
// Farbe setzen nur wenn Punkte angezeigt werden und Fragebogen ausgefüllt ist
if (entry?.showPoints == true && pointsAvailable != null) {
when {
points in 0..12 -> button.setBackgroundColor(Color.parseColor("#4CAF50")) // Grün
@ -282,7 +277,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
else -> button.setBackgroundColor(Color.parseColor("#E0E0E0")) // Grau bei 0 Punkten
}
} else {
// Standardgrau, wenn Punkte nicht angezeigt werden sollen oder Fragebogen nicht ausgefüllt ist
button.setBackgroundColor(Color.parseColor("#E0E0E0"))
}
}
@ -322,13 +316,11 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
Log.d("PDF_DEBUG", "Questionnaire ID: ${entry.questionnaireId}, Done: ${entry.isDone}, Points: ${entry.sumPoints}")
}
// ===== PDF ERSTELLUNG =====
val pdfDocument = PdfDocument()
val pageWidth = 595
val pageHeight = 842
val paint = Paint().apply { textSize = 12f }
// ===== CSV AUFBAU =====
val csvBuilder = StringBuilder()
csvBuilder.appendLine("ClientCode,QuestionnaireID,IsDone,Points,Question,Answer")
@ -338,7 +330,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
var canvas = page.canvas
var yPosition = 40f
// Header PDF
canvas.drawText("Client Code: $actualClientCode", 20f, yPosition, paint)
yPosition += 20f
canvas.drawText("Questionnaire: ${entry.questionnaireId}", 20f, yPosition, paint)
@ -359,7 +350,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
println("Answer " + answer.answerValue)
val answerText = rawAnswerText.trim().removePrefix("[").removeSuffix("]")
// PDF
yPosition = drawMultilineText(canvas, "Question: $questionText", 20f, yPosition, paint, pageWidth - 40, isBold = true)
yPosition += 8f
yPosition = drawMultilineText(canvas, "Answer: $answerText", 20f, yPosition, paint, pageWidth - 40)
@ -369,7 +359,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
canvas.drawLine(20f, yPosition - 30f, pageWidth - 20f, yPosition - 30f, paint)
paint.strokeWidth = 0f
// CSV
val sanitizedQuestion = questionText.replace(",", " ").replace("\n", " ")
val sanitizedAnswer = answerText.replace(",", " ").replace("\n", " ")
csvBuilder.appendLine("${actualClientCode},${entry.questionnaireId},${entry.isDone},${entry.sumPoints ?: ""},\"$sanitizedQuestion\",\"$sanitizedAnswer\"")
@ -386,14 +375,12 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
pdfDocument.finishPage(page)
}
// ==== CSV LOG AUSGABE ====
Log.d("CSV_OUTPUT", "Generated CSV:\n${csvBuilder.toString()}")
val pdfFileName = "DatabaseOutput_${actualClientCode}.pdf"
val csvFileName = "DatabaseOutput_${actualClientCode}.csv"
val resolver = activity.contentResolver
// Bestehende Dateien löschen
val deleteIfExists: (String) -> Unit = { name ->
val projection = arrayOf(android.provider.MediaStore.MediaColumns._ID)
val selection = "${android.provider.MediaStore.MediaColumns.DISPLAY_NAME} = ?"
@ -412,7 +399,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
deleteIfExists(pdfFileName)
deleteIfExists(csvFileName)
// PDF und CSV speichern
try {
val pdfUri = resolver.insert(
android.provider.MediaStore.Downloads.EXTERNAL_CONTENT_URI,
@ -501,6 +487,4 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
paint.isFakeBoldText = false
return y
}
}