removed comments
This commit is contained in:
@ -10,9 +10,6 @@ interface ClientDao {
|
|||||||
@Query("SELECT * FROM clients WHERE clientCode = :code LIMIT 1")
|
@Query("SELECT * FROM clients WHERE clientCode = :code LIMIT 1")
|
||||||
suspend fun getClientByCode(code: String): Client?
|
suspend fun getClientByCode(code: String): Client?
|
||||||
|
|
||||||
//@Query("SELECT * FROM clients")
|
|
||||||
//suspend fun getAllClients(): List<Client>
|
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun deleteClient(client: Client)
|
suspend fun deleteClient(client: Client)
|
||||||
}
|
}
|
||||||
@ -24,12 +21,8 @@ interface QuestionnaireDao {
|
|||||||
|
|
||||||
@Query("SELECT * FROM questionnaires WHERE id = :id LIMIT 1")
|
@Query("SELECT * FROM questionnaires WHERE id = :id LIMIT 1")
|
||||||
suspend fun getById(id: String): Questionnaire?
|
suspend fun getById(id: String): Questionnaire?
|
||||||
|
|
||||||
//@Query("SELECT * FROM questionnaires")
|
|
||||||
//suspend fun getAllQuestionnaires(): List<Questionnaire>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface QuestionDao {
|
interface QuestionDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
@ -43,13 +36,8 @@ interface QuestionDao {
|
|||||||
|
|
||||||
@Query("SELECT * FROM questions WHERE questionnaireId = :questionnaireId")
|
@Query("SELECT * FROM questions WHERE questionnaireId = :questionnaireId")
|
||||||
suspend fun getQuestionsForQuestionnaire(questionnaireId: String): List<Question>
|
suspend fun getQuestionsForQuestionnaire(questionnaireId: String): List<Question>
|
||||||
|
|
||||||
//@Query("SELECT * FROM questions")
|
|
||||||
//suspend fun getAllQuestions(): List<Question> // <-- HIER NEU
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface AnswerDao {
|
interface AnswerDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
@ -83,6 +71,4 @@ interface CompletedQuestionnaireDao {
|
|||||||
|
|
||||||
@Query("SELECT questionnaireId FROM completed_questionnaires WHERE clientCode = :clientCode")
|
@Query("SELECT questionnaireId FROM completed_questionnaires WHERE clientCode = :clientCode")
|
||||||
suspend fun getCompletedQuestionnairesForClient(clientCode: String): List<String>
|
suspend fun getCompletedQuestionnairesForClient(clientCode: String): List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -10,7 +10,6 @@ import kotlinx.coroutines.*
|
|||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
|
||||||
// Global constants and values
|
|
||||||
var INTEGRATION_INDEX_POINTS: Int? = null
|
var INTEGRATION_INDEX_POINTS: Int? = null
|
||||||
|
|
||||||
class HandlerOpeningScreen(private val activity: MainActivity) {
|
class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||||
@ -170,11 +169,9 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Profil ist gültig → entweder normal laden oder PDF erzeugen
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (isDatabaseView) {
|
if (isDatabaseView) {
|
||||||
// Profil laden + PDF erzeugen
|
handleNormalLoad(clientCode)
|
||||||
handleNormalLoad(clientCode) // ← Option: Zeige auch Punktefarben etc.
|
|
||||||
showCompletedQuestionnaires(clientCode)
|
showCompletedQuestionnaires(clientCode)
|
||||||
} else {
|
} else {
|
||||||
handleNormalLoad(clientCode)
|
handleNormalLoad(clientCode)
|
||||||
@ -237,10 +234,10 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
else -> true // fallback: zeige Fragebogen
|
else -> true // fallback: zeige Fragebogen
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conditionMet) break // Bedingung erfüllt → anzeigen
|
if (conditionMet) break
|
||||||
else nextIndex++ // überspringen
|
else nextIndex++
|
||||||
} else {
|
} else {
|
||||||
break // keine Bedingung → anzeigen
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +255,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
private fun updateButtonTexts() {
|
private fun updateButtonTexts() {
|
||||||
questionnaireFiles.forEach { (button, fileName) ->
|
questionnaireFiles.forEach { (button, fileName) ->
|
||||||
|
|
||||||
// Suche passenden QuestionnaireEntry
|
|
||||||
val entry = questionnaireEntries.firstOrNull { it.file == fileName }
|
val entry = questionnaireEntries.firstOrNull { it.file == fileName }
|
||||||
|
|
||||||
val key = fileName.substringAfter("questionnaire_").substringAfter("_").removeSuffix(".json")
|
val key = fileName.substringAfter("questionnaire_").substringAfter("_").removeSuffix(".json")
|
||||||
@ -273,7 +269,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
|
|
||||||
button.text = buttonText
|
button.text = buttonText
|
||||||
|
|
||||||
// Farbe setzen nur wenn Punkte angezeigt werden und Fragebogen ausgefüllt ist
|
|
||||||
if (entry?.showPoints == true && pointsAvailable != null) {
|
if (entry?.showPoints == true && pointsAvailable != null) {
|
||||||
when {
|
when {
|
||||||
points in 0..12 -> button.setBackgroundColor(Color.parseColor("#4CAF50")) // Grün
|
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 -> button.setBackgroundColor(Color.parseColor("#E0E0E0")) // Grau bei 0 Punkten
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Standardgrau, wenn Punkte nicht angezeigt werden sollen oder Fragebogen nicht ausgefüllt ist
|
|
||||||
button.setBackgroundColor(Color.parseColor("#E0E0E0"))
|
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}")
|
Log.d("PDF_DEBUG", "Questionnaire ID: ${entry.questionnaireId}, Done: ${entry.isDone}, Points: ${entry.sumPoints}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== PDF ERSTELLUNG =====
|
|
||||||
val pdfDocument = PdfDocument()
|
val pdfDocument = PdfDocument()
|
||||||
val pageWidth = 595
|
val pageWidth = 595
|
||||||
val pageHeight = 842
|
val pageHeight = 842
|
||||||
val paint = Paint().apply { textSize = 12f }
|
val paint = Paint().apply { textSize = 12f }
|
||||||
|
|
||||||
// ===== CSV AUFBAU =====
|
|
||||||
val csvBuilder = StringBuilder()
|
val csvBuilder = StringBuilder()
|
||||||
csvBuilder.appendLine("ClientCode,QuestionnaireID,IsDone,Points,Question,Answer")
|
csvBuilder.appendLine("ClientCode,QuestionnaireID,IsDone,Points,Question,Answer")
|
||||||
|
|
||||||
@ -338,7 +330,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
var canvas = page.canvas
|
var canvas = page.canvas
|
||||||
var yPosition = 40f
|
var yPosition = 40f
|
||||||
|
|
||||||
// Header PDF
|
|
||||||
canvas.drawText("Client Code: $actualClientCode", 20f, yPosition, paint)
|
canvas.drawText("Client Code: $actualClientCode", 20f, yPosition, paint)
|
||||||
yPosition += 20f
|
yPosition += 20f
|
||||||
canvas.drawText("Questionnaire: ${entry.questionnaireId}", 20f, yPosition, paint)
|
canvas.drawText("Questionnaire: ${entry.questionnaireId}", 20f, yPosition, paint)
|
||||||
@ -359,7 +350,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
println("Answer " + answer.answerValue)
|
println("Answer " + answer.answerValue)
|
||||||
val answerText = rawAnswerText.trim().removePrefix("[").removeSuffix("]")
|
val answerText = rawAnswerText.trim().removePrefix("[").removeSuffix("]")
|
||||||
|
|
||||||
// PDF
|
|
||||||
yPosition = drawMultilineText(canvas, "Question: $questionText", 20f, yPosition, paint, pageWidth - 40, isBold = true)
|
yPosition = drawMultilineText(canvas, "Question: $questionText", 20f, yPosition, paint, pageWidth - 40, isBold = true)
|
||||||
yPosition += 8f
|
yPosition += 8f
|
||||||
yPosition = drawMultilineText(canvas, "Answer: $answerText", 20f, yPosition, paint, pageWidth - 40)
|
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)
|
canvas.drawLine(20f, yPosition - 30f, pageWidth - 20f, yPosition - 30f, paint)
|
||||||
paint.strokeWidth = 0f
|
paint.strokeWidth = 0f
|
||||||
|
|
||||||
// CSV
|
|
||||||
val sanitizedQuestion = questionText.replace(",", " ").replace("\n", " ")
|
val sanitizedQuestion = questionText.replace(",", " ").replace("\n", " ")
|
||||||
val sanitizedAnswer = answerText.replace(",", " ").replace("\n", " ")
|
val sanitizedAnswer = answerText.replace(",", " ").replace("\n", " ")
|
||||||
csvBuilder.appendLine("${actualClientCode},${entry.questionnaireId},${entry.isDone},${entry.sumPoints ?: ""},\"$sanitizedQuestion\",\"$sanitizedAnswer\"")
|
csvBuilder.appendLine("${actualClientCode},${entry.questionnaireId},${entry.isDone},${entry.sumPoints ?: ""},\"$sanitizedQuestion\",\"$sanitizedAnswer\"")
|
||||||
@ -386,14 +375,12 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
pdfDocument.finishPage(page)
|
pdfDocument.finishPage(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== CSV LOG AUSGABE ====
|
|
||||||
Log.d("CSV_OUTPUT", "Generated CSV:\n${csvBuilder.toString()}")
|
Log.d("CSV_OUTPUT", "Generated CSV:\n${csvBuilder.toString()}")
|
||||||
|
|
||||||
val pdfFileName = "DatabaseOutput_${actualClientCode}.pdf"
|
val pdfFileName = "DatabaseOutput_${actualClientCode}.pdf"
|
||||||
val csvFileName = "DatabaseOutput_${actualClientCode}.csv"
|
val csvFileName = "DatabaseOutput_${actualClientCode}.csv"
|
||||||
val resolver = activity.contentResolver
|
val resolver = activity.contentResolver
|
||||||
|
|
||||||
// Bestehende Dateien löschen
|
|
||||||
val deleteIfExists: (String) -> Unit = { name ->
|
val deleteIfExists: (String) -> Unit = { name ->
|
||||||
val projection = arrayOf(android.provider.MediaStore.MediaColumns._ID)
|
val projection = arrayOf(android.provider.MediaStore.MediaColumns._ID)
|
||||||
val selection = "${android.provider.MediaStore.MediaColumns.DISPLAY_NAME} = ?"
|
val selection = "${android.provider.MediaStore.MediaColumns.DISPLAY_NAME} = ?"
|
||||||
@ -412,7 +399,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
deleteIfExists(pdfFileName)
|
deleteIfExists(pdfFileName)
|
||||||
deleteIfExists(csvFileName)
|
deleteIfExists(csvFileName)
|
||||||
|
|
||||||
// PDF und CSV speichern
|
|
||||||
try {
|
try {
|
||||||
val pdfUri = resolver.insert(
|
val pdfUri = resolver.insert(
|
||||||
android.provider.MediaStore.Downloads.EXTERNAL_CONTENT_URI,
|
android.provider.MediaStore.Downloads.EXTERNAL_CONTENT_URI,
|
||||||
@ -501,6 +487,4 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
paint.isFakeBoldText = false
|
paint.isFakeBoldText = false
|
||||||
return y
|
return y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,6 @@ import android.widget.Button
|
|||||||
|
|
||||||
open class QuestionnaireGeneric(private val questionnaireFileName: String) : QuestionnaireBase<Unit>() {
|
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() {
|
override fun startQuestionnaire() {
|
||||||
val (meta, questionsList) = loadQuestionnaireFromJson(questionnaireFileName)
|
val (meta, questionsList) = loadQuestionnaireFromJson(questionnaireFileName)
|
||||||
questionnaireMeta = meta
|
questionnaireMeta = meta
|
||||||
@ -16,42 +12,29 @@ open class QuestionnaireGeneric(private val questionnaireFileName: String) : Que
|
|||||||
showCurrentQuestion()
|
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() {
|
override fun showCurrentQuestion() {
|
||||||
val question = questions[currentIndex]
|
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")
|
val layoutResId = getLayoutResId(question.layout ?: "default_layout")
|
||||||
|
|
||||||
if (layoutResId == 0) {
|
if (layoutResId == 0) {
|
||||||
// No valid layout found, show empty screen instead
|
|
||||||
showEmptyScreen()
|
showEmptyScreen()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to the question layout and initialize it
|
|
||||||
navigateTo(layoutResId) { layout ->
|
navigateTo(layoutResId) { layout ->
|
||||||
|
|
||||||
// Localize all views in the layout tree according to current language
|
|
||||||
LocalizationHelper.localizeViewTree(layout, languageID)
|
LocalizationHelper.localizeViewTree(layout, languageID)
|
||||||
|
|
||||||
// Setup previous button navigation, if present
|
|
||||||
layout.findViewById<Button>(R.id.Qprev)?.setOnClickListener {
|
layout.findViewById<Button>(R.id.Qprev)?.setOnClickListener {
|
||||||
goToPreviousQuestion()
|
goToPreviousQuestion()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the appropriate handler for the question type
|
|
||||||
val handler = createHandlerForQuestion(question)
|
val handler = createHandlerForQuestion(question)
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
// Bind the question data to the UI
|
|
||||||
handler.bind(layout, question)
|
handler.bind(layout, question)
|
||||||
} else {
|
} else {
|
||||||
// No handler found for this question type; show empty screen
|
|
||||||
showEmptyScreen()
|
showEmptyScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user