removed comments
This commit is contained in:
@ -10,9 +10,6 @@ interface ClientDao {
|
||||
@Query("SELECT * FROM clients WHERE clientCode = :code LIMIT 1")
|
||||
suspend fun getClientByCode(code: String): Client?
|
||||
|
||||
//@Query("SELECT * FROM clients")
|
||||
//suspend fun getAllClients(): List<Client>
|
||||
|
||||
@Delete
|
||||
suspend fun deleteClient(client: Client)
|
||||
}
|
||||
@ -24,12 +21,8 @@ interface QuestionnaireDao {
|
||||
|
||||
@Query("SELECT * FROM questionnaires WHERE id = :id LIMIT 1")
|
||||
suspend fun getById(id: String): Questionnaire?
|
||||
|
||||
//@Query("SELECT * FROM questionnaires")
|
||||
//suspend fun getAllQuestionnaires(): List<Questionnaire>
|
||||
}
|
||||
|
||||
|
||||
@Dao
|
||||
interface QuestionDao {
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
@ -43,13 +36,8 @@ interface QuestionDao {
|
||||
|
||||
@Query("SELECT * FROM questions WHERE questionnaireId = :questionnaireId")
|
||||
suspend fun getQuestionsForQuestionnaire(questionnaireId: String): List<Question>
|
||||
|
||||
//@Query("SELECT * FROM questions")
|
||||
//suspend fun getAllQuestions(): List<Question> // <-- HIER NEU
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Dao
|
||||
interface AnswerDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@ -83,6 +71,4 @@ interface CompletedQuestionnaireDao {
|
||||
|
||||
@Query("SELECT questionnaireId FROM completed_questionnaires WHERE clientCode = :clientCode")
|
||||
suspend fun getCompletedQuestionnairesForClient(clientCode: String): List<String>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,10 +4,6 @@ import android.widget.Button
|
||||
|
||||
open class QuestionnaireGeneric(private val questionnaireFileName: String) : QuestionnaireBase<Unit>() {
|
||||
|
||||
/**
|
||||
* Starts the questionnaire by loading questions and metadata from JSON,
|
||||
* then shows the first question.
|
||||
*/
|
||||
override fun startQuestionnaire() {
|
||||
val (meta, questionsList) = loadQuestionnaireFromJson(questionnaireFileName)
|
||||
questionnaireMeta = meta
|
||||
@ -16,42 +12,29 @@ open class QuestionnaireGeneric(private val questionnaireFileName: String) : Que
|
||||
showCurrentQuestion()
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the current question based on the current index.
|
||||
* Loads the appropriate layout, applies localization, sets navigation buttons,
|
||||
* and delegates question binding to the appropriate handler.
|
||||
*/
|
||||
override fun showCurrentQuestion() {
|
||||
val question = questions[currentIndex]
|
||||
|
||||
// Get the layout resource ID based on the question layout name or fallback to default
|
||||
val layoutResId = getLayoutResId(question.layout ?: "default_layout")
|
||||
|
||||
if (layoutResId == 0) {
|
||||
// No valid layout found, show empty screen instead
|
||||
showEmptyScreen()
|
||||
return
|
||||
}
|
||||
|
||||
// Navigate to the question layout and initialize it
|
||||
navigateTo(layoutResId) { layout ->
|
||||
|
||||
// Localize all views in the layout tree according to current language
|
||||
LocalizationHelper.localizeViewTree(layout, languageID)
|
||||
|
||||
// Setup previous button navigation, if present
|
||||
layout.findViewById<Button>(R.id.Qprev)?.setOnClickListener {
|
||||
goToPreviousQuestion()
|
||||
}
|
||||
|
||||
// Create the appropriate handler for the question type
|
||||
val handler = createHandlerForQuestion(question)
|
||||
|
||||
if (handler != null) {
|
||||
// Bind the question data to the UI
|
||||
handler.bind(layout, question)
|
||||
} else {
|
||||
// No handler found for this question type; show empty screen
|
||||
showEmptyScreen()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user