added glass graphik
This commit is contained in:
@ -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<TextView>(R.id.textView)
|
||||
val questionTv = layout.findViewById<TextView>(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<LinearLayout>(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<TableLayout>(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<Button>(R.id.Qprev).setOnClickListener {
|
||||
goToPreviousQuestion()
|
||||
}
|
||||
layout.findViewById<Button>(R.id.Qprev).setOnClickListener { goToPreviousQuestion() }
|
||||
}
|
||||
|
||||
private fun addSymptomRows(table: TableLayout) {
|
||||
@ -151,7 +157,6 @@ class HandlerGlassScaleQuestion(
|
||||
text = LanguageManager.getText(languageID, symptomKey)
|
||||
layoutParams = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 4f)
|
||||
setPadding(4, 16, 4, 16)
|
||||
// Zeilenbeschriftung etwas kleiner als Titel (~2.2%)
|
||||
setTextSizePercentOfScreenHeight(this, 0.022f)
|
||||
}
|
||||
row.addView(symptomText)
|
||||
@ -162,16 +167,23 @@ class HandlerGlassScaleQuestion(
|
||||
}
|
||||
|
||||
scaleLabels.forEach { labelKey ->
|
||||
val cell = FrameLayout(context).apply {
|
||||
layoutParams = RadioGroup.LayoutParams(0, RadioGroup.LayoutParams.WRAP_CONTENT, 1f)
|
||||
}
|
||||
val radioButton = RadioButton(context).apply {
|
||||
tag = labelKey
|
||||
id = View.generateViewId()
|
||||
isChecked = savedLabel == labelKey
|
||||
layoutParams = RadioGroup.LayoutParams(
|
||||
0, RadioGroup.LayoutParams.WRAP_CONTENT, 1f
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.CENTER
|
||||
)
|
||||
gravity = Gravity.CENTER
|
||||
setPadding(0, 0, 0, 0)
|
||||
}
|
||||
radioGroup.addView(radioButton)
|
||||
cell.addView(radioButton)
|
||||
radioGroup.addView(cell)
|
||||
}
|
||||
row.addView(radioGroup)
|
||||
table.addView(row)
|
||||
@ -180,37 +192,44 @@ class HandlerGlassScaleQuestion(
|
||||
|
||||
override fun validate(): Boolean {
|
||||
val table = layout.findViewById<TableLayout>(R.id.glass_table)
|
||||
for (i in 1 until table.childCount) {
|
||||
for (i in 0 until table.childCount) {
|
||||
val row = table.getChildAt(i) as TableRow
|
||||
val radioGroup = row.getChildAt(1) as RadioGroup
|
||||
if (radioGroup.checkedRadioButtonId == -1) return false
|
||||
var anyChecked = false
|
||||
for (j in 0 until radioGroup.childCount) {
|
||||
val cell = radioGroup.getChildAt(j) as FrameLayout
|
||||
val rb = cell.getChildAt(0) as RadioButton
|
||||
if (rb.isChecked) { anyChecked = true; break }
|
||||
}
|
||||
if (!anyChecked) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun saveAnswer() {
|
||||
// Vorherige Punkte dieser Frage entfernen (falls vorhanden)
|
||||
question.symptoms.forEach { key ->
|
||||
val previousLabel = answers[key] as? String
|
||||
previousLabel?.let { lbl -> pointsMap[lbl] }?.let { points.remove(it) }
|
||||
}
|
||||
|
||||
val table = layout.findViewById<TableLayout>(R.id.glass_table)
|
||||
for (i in 1 until table.childCount) {
|
||||
for (i in 0 until table.childCount) {
|
||||
val row = table.getChildAt(i) as TableRow
|
||||
val symptomKey = question.symptoms[i - 1]
|
||||
val symptomKey = question.symptoms[i]
|
||||
val radioGroup = row.getChildAt(1) as RadioGroup
|
||||
val checkedId = radioGroup.checkedRadioButtonId
|
||||
if (checkedId != -1) {
|
||||
val radioButton = radioGroup.findViewById<RadioButton>(checkedId)
|
||||
val selectedLabel = radioButton.tag as String
|
||||
answers[symptomKey] = selectedLabel
|
||||
points.add(pointsMap[selectedLabel] ?: 0)
|
||||
for (j in 0 until radioGroup.childCount) {
|
||||
val cell = radioGroup.getChildAt(j) as FrameLayout
|
||||
val rb = cell.getChildAt(0) as RadioButton
|
||||
if (rb.isChecked) {
|
||||
val selectedLabel = rb.tag as String
|
||||
answers[symptomKey] = selectedLabel
|
||||
points.add(pointsMap[selectedLabel] ?: 0)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: Textgröße prozentual zur Bildschirmhöhe setzen (in sp)
|
||||
private fun setTextSizePercentOfScreenHeight(view: TextView, percentOfHeight: Float) {
|
||||
val dm = (view.context ?: layout.context).resources.displayMetrics
|
||||
val sp = (dm.heightPixels * percentOfHeight) / dm.scaledDensity
|
||||
|
||||
9
app/src/main/res/drawable/ic_glass_0.xml
Normal file
9
app/src/main/res/drawable/ic_glass_0.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="64" android:viewportHeight="64">
|
||||
<!-- Glas-Outline -->
|
||||
<path android:fillColor="#00000000" android:strokeColor="#424242" android:strokeWidth="3"
|
||||
android:pathData="M20,6h24a6,6 0 0 1 6,6v40a6,6 0 0 1 -6,6H20a6,6 0 0 1 -6,-6V12a6,6 0 0 1 6,-6z"/>
|
||||
<!-- Füllung 0% -->
|
||||
<path android:fillColor="#9FA8DA" android:pathData="M22,52H42V52H22z"/>
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/ic_glass_1.xml
Normal file
7
app/src/main/res/drawable/ic_glass_1.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="64" android:viewportHeight="64">
|
||||
<path android:fillColor="#00000000" android:strokeColor="#424242" android:strokeWidth="3"
|
||||
android:pathData="M20,6h24a6,6 0 0 1 6,6v40a6,6 0 0 1 -6,6H20a6,6 0 0 1 -6,-6V12a6,6 0 0 1 6,-6z"/>
|
||||
<path android:fillColor="#9FA8DA" android:pathData="M22,46H42V52H22z"/>
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/ic_glass_2.xml
Normal file
7
app/src/main/res/drawable/ic_glass_2.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="64" android:viewportHeight="64">
|
||||
<path android:fillColor="#00000000" android:strokeColor="#424242" android:strokeWidth="3"
|
||||
android:pathData="M20,6h24a6,6 0 0 1 6,6v40a6,6 0 0 1 -6,6H20a6,6 0 0 1 -6,-6V12a6,6 0 0 1 6,-6z"/>
|
||||
<path android:fillColor="#9FA8DA" android:pathData="M22,38H42V52H22z"/>
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/ic_glass_3.xml
Normal file
7
app/src/main/res/drawable/ic_glass_3.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="64" android:viewportHeight="64">
|
||||
<path android:fillColor="#00000000" android:strokeColor="#424242" android:strokeWidth="3"
|
||||
android:pathData="M20,6h24a6,6 0 0 1 6,6v40a6,6 0 0 1 -6,6H20a6,6 0 0 1 -6,-6V12a6,6 0 0 1 6,-6z"/>
|
||||
<path android:fillColor="#9FA8DA" android:pathData="M22,30H42V52H22z"/>
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/ic_glass_4.xml
Normal file
7
app/src/main/res/drawable/ic_glass_4.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="64" android:viewportHeight="64">
|
||||
<path android:fillColor="#00000000" android:strokeColor="#424242" android:strokeWidth="3"
|
||||
android:pathData="M20,6h24a6,6 0 0 1 6,6v40a6,6 0 0 1 -6,6H20a6,6 0 0 1 -6,-6V12a6,6 0 0 1 6,-6z"/>
|
||||
<path android:fillColor="#9FA8DA" android:pathData="M22,14H42V52H22z"/>
|
||||
</vector>
|
||||
@ -5,15 +5,59 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- Titel -->
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHeight_percent="0.15"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.051"
|
||||
app:layout_constraintWidth_percent="0.9" />
|
||||
|
||||
<!-- Leitfrage -->
|
||||
<TextView
|
||||
android:id="@+id/question"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHeight_percent="0.15"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/textView"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:layout_constraintWidth_percent="0.9" />
|
||||
|
||||
<!-- FIXE ICON-LEISTE (bleibt stehen) -->
|
||||
<LinearLayout
|
||||
android:id="@+id/glass_header"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8dp"
|
||||
android:weightSum="9"
|
||||
app:layout_constraintTop_toBottomOf="@id/question"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintWidth_percent="1" />
|
||||
|
||||
<!-- Scrollbarer Bereich NUR für Symptome + Kreise -->
|
||||
<ScrollView
|
||||
android:id="@+id/glassScroll"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:fillViewport="true"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/question"
|
||||
app:layout_constraintTop_toBottomOf="@id/glass_header"
|
||||
app:layout_constraintBottom_toTopOf="@+id/Qprev"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
@ -29,6 +73,7 @@
|
||||
android:textStyle="bold" />
|
||||
</ScrollView>
|
||||
|
||||
<!-- Buttons unten -->
|
||||
<Button
|
||||
android:id="@+id/Qprev"
|
||||
android:layout_width="0dp"
|
||||
@ -73,33 +118,4 @@
|
||||
app:layout_constraintVertical_bias="1.0"
|
||||
app:layout_constraintWidth_percent="0.30" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHeight_percent="0.15"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.051"
|
||||
app:layout_constraintWidth_percent="0.9" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/question"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHeight_percent="0.15"
|
||||
app:layout_constraintHorizontal_bias="0.512"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:layout_constraintWidth_percent="0.9" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in New Issue
Block a user