From 8ad939db274c73017efc40c2700f5795f2d6612e Mon Sep 17 00:00:00 2001 From: oxidiert Date: Fri, 19 Sep 2025 11:07:31 +0200 Subject: [PATCH] added glass graphik --- .../dano/test1/HandlerGlassScaleQuestion.kt | 141 ++++++++++-------- app/src/main/res/drawable/ic_glass_0.xml | 9 ++ app/src/main/res/drawable/ic_glass_1.xml | 7 + app/src/main/res/drawable/ic_glass_2.xml | 7 + app/src/main/res/drawable/ic_glass_3.xml | 7 + app/src/main/res/drawable/ic_glass_4.xml | 7 + .../main/res/layout/glass_scale_question.xml | 78 ++++++---- 7 files changed, 164 insertions(+), 92 deletions(-) create mode 100644 app/src/main/res/drawable/ic_glass_0.xml create mode 100644 app/src/main/res/drawable/ic_glass_1.xml create mode 100644 app/src/main/res/drawable/ic_glass_2.xml create mode 100644 app/src/main/res/drawable/ic_glass_3.xml create mode 100644 app/src/main/res/drawable/ic_glass_4.xml diff --git a/app/src/main/java/com/dano/test1/HandlerGlassScaleQuestion.kt b/app/src/main/java/com/dano/test1/HandlerGlassScaleQuestion.kt index d45472f..9a5d46f 100644 --- a/app/src/main/java/com/dano/test1/HandlerGlassScaleQuestion.kt +++ b/app/src/main/java/com/dano/test1/HandlerGlassScaleQuestion.kt @@ -1,13 +1,12 @@ package com.dano.test1 import android.content.Context +import android.util.TypedValue import android.view.Gravity import android.view.View import android.widget.* -import kotlinx.coroutines.* -import android.util.TypedValue -import android.widget.TextView import androidx.core.widget.TextViewCompat +import kotlinx.coroutines.* class HandlerGlassScaleQuestion( private val context: Context, @@ -23,7 +22,13 @@ class HandlerGlassScaleQuestion( private lateinit var layout: View private lateinit var question: QuestionItem.GlassScaleQuestion - private val scaleLabels = listOf("never_glass","little_glass","moderate_glass","much_glass","extreme_glass") + private val scaleLabels = listOf( + "never_glass", + "little_glass", + "moderate_glass", + "much_glass", + "extreme_glass" + ) private val pointsMap = mapOf( "never_glass" to 0, @@ -33,6 +38,14 @@ class HandlerGlassScaleQuestion( "extreme_glass" to 4 ) + private val glassIconForLabel = mapOf( + "never_glass" to R.drawable.ic_glass_0, + "little_glass" to R.drawable.ic_glass_1, + "moderate_glass" to R.drawable.ic_glass_2, + "much_glass" to R.drawable.ic_glass_3, + "extreme_glass" to R.drawable.ic_glass_4 + ) + override fun bind(layout: View, question: QuestionItem) { if (question !is QuestionItem.GlassScaleQuestion) return this.layout = layout @@ -41,48 +54,42 @@ class HandlerGlassScaleQuestion( val titleTv = layout.findViewById(R.id.textView) val questionTv = layout.findViewById(R.id.question) - // Texte setzen titleTv.text = question.textKey?.let { LanguageManager.getText(languageID, it) } ?: "" questionTv.text = question.question?.let { LanguageManager.getText(languageID, it) } ?: "" - // === Schriftgrößen prozentual zur Bildschirmhöhe === - setTextSizePercentOfScreenHeight(titleTv, 0.03f) // ~3% der Screen-Höhe - setTextSizePercentOfScreenHeight(questionTv, 0.03f) // ~3% der Screen-Höhe - // =================================================== + setTextSizePercentOfScreenHeight(titleTv, 0.03f) + setTextSizePercentOfScreenHeight(questionTv, 0.03f) + + // --- FIXE ICON-LEISTE AUFBAUEN (bleibt stehen) --- + val header = layout.findViewById(R.id.glass_header) + header.removeAllViews() + + // linker Platzhalter (entspricht der Symptom-Spalte mit weight=4) + header.addView(Space(context).apply { + layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 4f) + }) + + val iconSizePx = (context.resources.displayMetrics.density * 36).toInt() // ~36dp + scaleLabels.forEach { labelKey -> + val cell = FrameLayout(context).apply { + layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f) + } + val img = ImageView(context).apply { + setImageResource(glassIconForLabel[labelKey]!!) + layoutParams = FrameLayout.LayoutParams(iconSizePx, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER) + adjustViewBounds = true + scaleType = ImageView.ScaleType.FIT_CENTER + } + cell.addView(img) + header.addView(cell) + } + // --------------------------------------------------- val tableLayout = layout.findViewById(R.id.glass_table) tableLayout.removeAllViews() - // Header-Reihe - val headerRow = TableRow(context).apply { - layoutParams = TableLayout.LayoutParams( - TableLayout.LayoutParams.MATCH_PARENT, - TableLayout.LayoutParams.WRAP_CONTENT - ) - gravity = Gravity.CENTER - } - - val emptyCell = TextView(context).apply { - layoutParams = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 4f) - } - headerRow.addView(emptyCell) - - scaleLabels.forEach { labelKey -> - val labelText = LanguageManager.getText(languageID, labelKey) - val labelView = TextView(context).apply { - text = labelText - gravity = Gravity.START - layoutParams = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1f) - // Header-Text moderat skalieren (~2.2%) - setTextSizePercentOfScreenHeight(this, 0.022f) - } - headerRow.addView(labelView) - } - tableLayout.addView(headerRow) - addSymptomRows(tableLayout) - // ggf. DB-Restore val anySymptomNeedsRestore = question.symptoms.any { !answers.containsKey(it) } if (anySymptomNeedsRestore) { CoroutineScope(Dispatchers.IO).launch { @@ -94,16 +101,18 @@ class HandlerGlassScaleQuestion( val answerMap = allAnswersForClient.associateBy({ it.questionId }, { it.answerValue }) withContext(Dispatchers.Main) { + val table = tableLayout for ((index, symptomKey) in question.symptoms.withIndex()) { val answerMapKey = questionnaireMeta + "-" + symptomKey val dbAnswer = answerMap[answerMapKey]?.takeIf { it.isNotBlank() }?.trim() if (!answers.containsKey(symptomKey) && !dbAnswer.isNullOrBlank()) { - val rowIndex = index + 1 // Header ist 0 - if (rowIndex < tableLayout.childCount) { - val row = tableLayout.getChildAt(rowIndex) as? TableRow ?: continue + val rowIndex = index // erste Datenzeile ist Index 1 im TableLayout-Aufbau unten + if (rowIndex < table.childCount) { + val row = table.getChildAt(rowIndex) as? TableRow ?: continue val radioGroup = row.getChildAt(1) as? RadioGroup ?: continue for (i in 0 until radioGroup.childCount) { - val rb = radioGroup.getChildAt(i) as? RadioButton ?: continue + val cell = radioGroup.getChildAt(i) as? FrameLayout ?: continue + val rb = cell.getChildAt(0) as? RadioButton ?: continue if ((rb.tag as? String)?.trim() == dbAnswer) { rb.isChecked = true break @@ -130,10 +139,7 @@ class HandlerGlassScaleQuestion( showToast(LanguageManager.getText(languageID, "select_one_answer_per_row")) } } - - layout.findViewById