finished opening screen
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
package com.dano.test1
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import kotlinx.coroutines.*
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
@ -22,37 +25,46 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
private lateinit var editButton: Button
|
||||
private lateinit var uploadButton: Button
|
||||
private lateinit var downloadButton: Button
|
||||
private lateinit var databaseButton: Button // <-- NEU
|
||||
private lateinit var databaseButton: Button
|
||||
|
||||
private val dynamicButtons = mutableListOf<Button>()
|
||||
private val questionnaireFiles = mutableMapOf<Button, String>()
|
||||
|
||||
private data class CardParts(
|
||||
val title: TextView,
|
||||
val subtitle: TextView,
|
||||
val chip: TextView
|
||||
)
|
||||
private val cardParts = mutableMapOf<Button, CardParts>()
|
||||
|
||||
private val buttonPoints: MutableMap<String, Int> = mutableMapOf()
|
||||
private var questionnaireEntries: List<QuestionItem.QuestionnaireEntry> = emptyList()
|
||||
|
||||
private var uiFreeze: Boolean = false
|
||||
|
||||
// Feste Standard-Randfarben
|
||||
private val STROKE_ENABLED = Color.parseColor("#8C79F2") // wenn anklickbar
|
||||
private val STROKE_DISABLED = Color.parseColor("#D8D3F5") // wenn nicht anklickbar
|
||||
|
||||
private fun t(id: String) = LanguageManager.getText(languageID, id)
|
||||
|
||||
fun init() {
|
||||
activity.setContentView(R.layout.opening_screen)
|
||||
|
||||
bindViews()
|
||||
|
||||
loadQuestionnaireOrder()
|
||||
createQuestionnaireButtons()
|
||||
restorePreviousClientCode()
|
||||
|
||||
setupLanguageSpinner()
|
||||
setupLoadButton()
|
||||
setupSaveButton()
|
||||
setupEditButtonHandler()
|
||||
setupUploadButton()
|
||||
setupDownloadButton()
|
||||
setupDatabaseButtonHandler() // <-- NEU
|
||||
setupDatabaseButtonHandler()
|
||||
|
||||
val dbPath = "/data/data/com.dano.test1/databases/questionnaire_database"
|
||||
val pathExists = File(dbPath).exists()
|
||||
val pathExists = File("/data/data/com.dano.test1/databases/questionnaire_database").exists()
|
||||
updateMainButtonsState(pathExists)
|
||||
|
||||
if (pathExists && !editText.text.isNullOrBlank()) {
|
||||
buttonLoad.performClick()
|
||||
}
|
||||
if (pathExists && !editText.text.isNullOrBlank()) buttonLoad.performClick()
|
||||
}
|
||||
|
||||
private fun bindViews() {
|
||||
@ -65,11 +77,11 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
editButton = activity.findViewById(R.id.editButton)
|
||||
uploadButton = activity.findViewById(R.id.uploadButton)
|
||||
downloadButton = activity.findViewById(R.id.downloadButton)
|
||||
databaseButton = activity.findViewById(R.id.databaseButton) // <-- NEU
|
||||
databaseButton = activity.findViewById(R.id.databaseButton)
|
||||
|
||||
val tag = editText.tag as? String ?: ""
|
||||
editText.hint = LanguageManager.getText(languageID, tag)
|
||||
textView.text = LanguageManager.getText(languageID, "example_text")
|
||||
editText.hint = t(tag)
|
||||
textView.text = t("example_text")
|
||||
}
|
||||
|
||||
private fun loadQuestionnaireOrder() {
|
||||
@ -84,11 +96,9 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
val conditionObj = obj.optJSONObject("condition")
|
||||
val condition = parseCondition(conditionObj)
|
||||
val showPoints = obj.optBoolean("showPoints", false)
|
||||
|
||||
QuestionItem.QuestionnaireEntry(file, condition, showPoints)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} catch (_: Exception) {
|
||||
questionnaireEntries = emptyList()
|
||||
}
|
||||
}
|
||||
@ -104,17 +114,14 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
return QuestionItem.Condition.AnyOf(conditions)
|
||||
}
|
||||
if (conditionObj.has("alwaysAvailable")) {
|
||||
val flag = conditionObj.optBoolean("alwaysAvailable", false)
|
||||
if (flag) return QuestionItem.Condition.AlwaysAvailable
|
||||
if (conditionObj.has("alwaysAvailable") && conditionObj.optBoolean("alwaysAvailable", false)) {
|
||||
return QuestionItem.Condition.AlwaysAvailable
|
||||
}
|
||||
val requiresList = mutableListOf<String>()
|
||||
if (conditionObj.has("requiresCompleted")) {
|
||||
val reqArr = conditionObj.optJSONArray("requiresCompleted")
|
||||
if (reqArr != null) {
|
||||
for (i in 0 until reqArr.length()) {
|
||||
requiresList.add(reqArr.optString(i))
|
||||
}
|
||||
for (i in 0 until reqArr.length()) requiresList.add(reqArr.optString(i))
|
||||
} else {
|
||||
conditionObj.optString("requiresCompleted")?.let { if (it.isNotBlank()) requiresList.add(it) }
|
||||
}
|
||||
@ -123,17 +130,15 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
val questionId = conditionObj.optString("questionId", null)
|
||||
val operator = conditionObj.optString("operator", null)
|
||||
val value = conditionObj.optString("value", null)
|
||||
val hasQuestionCheck = !questionnaire.isNullOrBlank() && !questionId.isNullOrBlank() && !operator.isNullOrBlank() && value != null
|
||||
val hasQuestionCheck =
|
||||
!questionnaire.isNullOrBlank() && !questionId.isNullOrBlank() && !operator.isNullOrBlank() && value != null
|
||||
return when {
|
||||
requiresList.isNotEmpty() && hasQuestionCheck -> {
|
||||
requiresList.isNotEmpty() && hasQuestionCheck ->
|
||||
QuestionItem.Condition.Combined(requiresList, QuestionItem.Condition.QuestionCondition(questionnaire!!, questionId!!, operator!!, value!!))
|
||||
}
|
||||
hasQuestionCheck -> {
|
||||
hasQuestionCheck ->
|
||||
QuestionItem.Condition.QuestionCondition(questionnaire!!, questionId!!, operator!!, value!!)
|
||||
}
|
||||
requiresList.isNotEmpty() -> {
|
||||
requiresList.isNotEmpty() ->
|
||||
QuestionItem.Condition.RequiresCompleted(requiresList)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@ -142,34 +147,95 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
buttonContainer.removeAllViews()
|
||||
dynamicButtons.clear()
|
||||
questionnaireFiles.clear()
|
||||
for ((index, entry) in questionnaireEntries.withIndex()) {
|
||||
val button = Button(activity).apply {
|
||||
cardParts.clear()
|
||||
|
||||
val vMargin = dp(8)
|
||||
val startEnabled = mutableListOf<Button>()
|
||||
|
||||
questionnaireEntries.forEachIndexed { index, entry ->
|
||||
val row = FrameLayout(activity).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
).apply { setMargins(0, 8, 0, 8) }
|
||||
text = "Questionnaire ${index + 1}"
|
||||
).also { it.setMargins(0, vMargin, 0, vMargin) }
|
||||
}
|
||||
|
||||
val btn = MaterialButton(activity).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
dp(84)
|
||||
)
|
||||
text = ""
|
||||
isAllCaps = false
|
||||
setMinimumWidth(0)
|
||||
setMinimumHeight(0)
|
||||
cornerRadius = dp(22)
|
||||
strokeWidth = dp(1)
|
||||
strokeColor = ColorStateList.valueOf(STROKE_DISABLED)
|
||||
backgroundTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
rippleColor = ColorStateList.valueOf(Color.parseColor("#22000000"))
|
||||
gravity = Gravity.START or Gravity.CENTER_VERTICAL
|
||||
setPadding(dp(20), 0, dp(20), 0)
|
||||
id = View.generateViewId()
|
||||
setOnClickListener {
|
||||
GlobalValues.LAST_CLIENT_CODE = GlobalValues.LOADED_CLIENT_CODE
|
||||
val fileName = questionnaireFiles[this] ?: return@setOnClickListener
|
||||
val questionnaire = QuestionnaireGeneric(fileName)
|
||||
startQuestionnaire(questionnaire)
|
||||
applySetButtonsEnabled(dynamicButtons.filter { it == this }, allowCompleted = false, force = false)
|
||||
}
|
||||
}
|
||||
buttonContainer.addView(button)
|
||||
dynamicButtons.add(button)
|
||||
questionnaireFiles[button] = entry.file
|
||||
}
|
||||
updateButtonTexts()
|
||||
|
||||
val alwaysButtons = questionnaireEntries.mapIndexedNotNull { idx, entry ->
|
||||
val btn = dynamicButtons.getOrNull(idx)
|
||||
if (entry.condition is QuestionItem.Condition.AlwaysAvailable) btn else null
|
||||
}
|
||||
setButtonsEnabled(alwaysButtons)
|
||||
|
||||
dynamicButtons.forEach { button ->
|
||||
button.setOnClickListener {
|
||||
GlobalValues.LAST_CLIENT_CODE = GlobalValues.LOADED_CLIENT_CODE
|
||||
startQuestionnaireForButton(button)
|
||||
setButtonsEnabled(dynamicButtons.filter { it == button })
|
||||
val textColumn = LinearLayout(activity).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.START or Gravity.CENTER_VERTICAL
|
||||
).also { it.marginStart = dp(24) }
|
||||
}
|
||||
val tvTitle = TextView(activity).apply {
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
|
||||
setTextColor(Color.parseColor("#2F2A49"))
|
||||
setPadding(0, dp(6), 0, dp(2))
|
||||
}
|
||||
val tvSubtitle = TextView(activity).apply {
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
|
||||
setTextColor(Color.parseColor("#7B7794"))
|
||||
visibility = View.GONE
|
||||
}
|
||||
textColumn.addView(tvTitle)
|
||||
textColumn.addView(tvSubtitle)
|
||||
|
||||
val chip = TextView(activity).apply {
|
||||
setPadding(dp(14), dp(8), dp(14), dp(8))
|
||||
setTextColor(Color.WHITE)
|
||||
text = t("start")
|
||||
setBackgroundResource(R.drawable.bg_chip_amber)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.END or Gravity.CENTER_VERTICAL
|
||||
).also { it.marginEnd = dp(16) }
|
||||
}
|
||||
|
||||
row.addView(btn)
|
||||
row.addView(textColumn)
|
||||
row.addView(chip)
|
||||
|
||||
buttonContainer.addView(row)
|
||||
dynamicButtons.add(btn)
|
||||
questionnaireFiles[btn] = entry.file
|
||||
cardParts[btn] = CardParts(tvTitle, tvSubtitle, chip)
|
||||
|
||||
tvTitle.text = "Questionnaire ${index + 1}"
|
||||
|
||||
if (entry.condition is QuestionItem.Condition.AlwaysAvailable) startEnabled.add(btn)
|
||||
}
|
||||
|
||||
applyUpdateButtonTexts(force = false)
|
||||
applySetButtonsEnabled(startEnabled, allowCompleted = false, force = false)
|
||||
}
|
||||
|
||||
private fun restorePreviousClientCode() {
|
||||
@ -186,9 +252,9 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) {
|
||||
languageID = languages[position]
|
||||
updateButtonTexts()
|
||||
applyUpdateButtonTexts(force = false)
|
||||
val hintTag = editText.tag as? String ?: ""
|
||||
editText.hint = LanguageManager.getText(languageID, hintTag)
|
||||
editText.hint = t(hintTag)
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {}
|
||||
}
|
||||
@ -203,64 +269,135 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
questionnaireEntriesProvider = { questionnaireEntries },
|
||||
dynamicButtonsProvider = { dynamicButtons },
|
||||
buttonPoints = buttonPoints,
|
||||
updateButtonTexts = { updateButtonTexts() },
|
||||
setButtonsEnabled = { setButtonsEnabled(it) },
|
||||
updateButtonTexts = { applyUpdateButtonTexts(force = false) },
|
||||
setButtonsEnabled = { list -> applySetButtonsEnabled(list, allowCompleted = false, force = false) },
|
||||
updateMainButtonsState = { updateMainButtonsState(it) },
|
||||
).setup()
|
||||
}
|
||||
|
||||
private fun updateButtonTexts() {
|
||||
// --- dynamische Fragebogen-Buttons wie gehabt ---
|
||||
private fun applyUpdateButtonTexts(force: Boolean) {
|
||||
if (uiFreeze && !force) return
|
||||
|
||||
questionnaireFiles.forEach { (button, fileName) ->
|
||||
val entry = questionnaireEntries.firstOrNull { it.file == fileName }
|
||||
val key = fileName.substringAfter("questionnaire_").substringAfter("_").removeSuffix(".json")
|
||||
var buttonText = LanguageManager.getText(languageID, key)
|
||||
val pointsAvailable = buttonPoints.entries.firstOrNull { fileName.contains(it.key, ignoreCase = true) }
|
||||
val points = pointsAvailable?.value ?: 0
|
||||
val titleText = t(key)
|
||||
|
||||
if (entry?.showPoints == true && pointsAvailable != null) {
|
||||
buttonText += " (${points} P)"
|
||||
}
|
||||
button.text = buttonText
|
||||
val parts = cardParts[button] ?: return@forEach
|
||||
parts.title.text = titleText
|
||||
|
||||
if (entry?.showPoints == true && pointsAvailable != null) {
|
||||
when {
|
||||
points in 0..12 -> button.setBackgroundColor(Color.parseColor("#4CAF50"))
|
||||
points in 13..36 -> button.setBackgroundColor(Color.parseColor("#FFEB3B"))
|
||||
points in 37..100-> button.setBackgroundColor(Color.parseColor("#F44336"))
|
||||
else -> button.setBackgroundColor(Color.parseColor("#E0E0E0"))
|
||||
}
|
||||
val points = buttonPoints.entries.firstOrNull { fileName.contains(it.key, ignoreCase = true) }?.value
|
||||
val completed = isCompleted(button)
|
||||
val enabled = button.isEnabled
|
||||
val locked = !enabled && !completed
|
||||
|
||||
// Rahmenbreite & -farbe je nach Klickbarkeit
|
||||
setClickableStroke(button, enabled)
|
||||
|
||||
if (locked) {
|
||||
setLockedAppearance(button, true)
|
||||
parts.title.setTextColor(Color.WHITE)
|
||||
parts.subtitle.setTextColor(Color.parseColor("#E0E0E0"))
|
||||
} else {
|
||||
button.setBackgroundColor(Color.parseColor("#E0E0E0"))
|
||||
setLockedAppearance(button, false)
|
||||
parts.title.setTextColor(Color.parseColor("#2F2A49"))
|
||||
parts.subtitle.setTextColor(Color.parseColor("#7B7794"))
|
||||
// Tönung nur wenn showPoints == true
|
||||
applyTintForButton(button, points, emphasize = enabled)
|
||||
}
|
||||
|
||||
if (entry?.showPoints == true && points != null) {
|
||||
parts.subtitle.visibility = View.VISIBLE
|
||||
parts.subtitle.text = "${t("points")}: $points"
|
||||
} else {
|
||||
parts.subtitle.visibility = View.GONE
|
||||
parts.subtitle.text = ""
|
||||
}
|
||||
|
||||
when {
|
||||
completed -> {
|
||||
parts.chip.text = t("done")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_green)
|
||||
parts.chip.setTextColor(Color.WHITE)
|
||||
}
|
||||
enabled -> {
|
||||
parts.chip.text = t("start")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_amber)
|
||||
parts.chip.setTextColor(Color.WHITE)
|
||||
}
|
||||
else -> {
|
||||
parts.chip.text = t("locked")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_grey)
|
||||
parts.chip.setTextColor(Color.parseColor("#2F2A49"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- HIER: alle Hauptbuttons nach Sprache neu setzen ---
|
||||
buttonLoad.text = LanguageManager.getText(languageID, "load")
|
||||
saveButton.text = LanguageManager.getText(languageID, "save")
|
||||
editButton.text = LanguageManager.getText(languageID, "edit")
|
||||
uploadButton.text = LanguageManager.getText(languageID, "upload")
|
||||
downloadButton.text= LanguageManager.getText(languageID, "download")
|
||||
databaseButton.text= LanguageManager.getText(languageID, "database")
|
||||
buttonLoad.text = t("load")
|
||||
saveButton.text = t("save")
|
||||
editButton.text = t("edit")
|
||||
uploadButton.text = t("upload")
|
||||
downloadButton.text = t("download")
|
||||
databaseButton.text = t("database")
|
||||
|
||||
// optional: Beispieltext/Hints auch aktualisieren
|
||||
val hintTag = editText.tag as? String ?: ""
|
||||
editText.hint = LanguageManager.getText(languageID, hintTag)
|
||||
textView.text = LanguageManager.getText(languageID, "example_text")
|
||||
editText.hint = t(hintTag)
|
||||
textView.text = t("example_text")
|
||||
}
|
||||
|
||||
private fun setButtonsEnabled(enabledButtons: List<Button>) {
|
||||
private fun applySetButtonsEnabled(enabledButtons: List<Button>, allowCompleted: Boolean, force: Boolean) {
|
||||
if (uiFreeze && !force) return
|
||||
|
||||
questionnaireFiles.keys.forEach { button ->
|
||||
button.isEnabled = enabledButtons.contains(button)
|
||||
button.alpha = if (button.isEnabled) 1.0f else 0.5f
|
||||
val completed = isCompleted(button)
|
||||
val isAllowed = enabledButtons.contains(button)
|
||||
val shouldEnable = if (allowCompleted) isAllowed else isAllowed && !completed
|
||||
val locked = !shouldEnable && !completed
|
||||
|
||||
button.isEnabled = shouldEnable
|
||||
button.alpha = if (completed || shouldEnable) 1.0f else 0.6f
|
||||
|
||||
// Rahmenbreite & -farbe je nach Klickbarkeit
|
||||
setClickableStroke(button, shouldEnable)
|
||||
|
||||
cardParts[button]?.let { parts ->
|
||||
if (locked) {
|
||||
setLockedAppearance(button, true)
|
||||
parts.title.setTextColor(Color.WHITE)
|
||||
parts.subtitle.setTextColor(Color.parseColor("#E0E0E0"))
|
||||
} else {
|
||||
setLockedAppearance(button, false)
|
||||
parts.title.setTextColor(Color.parseColor("#2F2A49"))
|
||||
parts.subtitle.setTextColor(Color.parseColor("#7B7794"))
|
||||
// Tönung nur wenn showPoints == true
|
||||
applyTintForButton(button, getPointsForButton(button), emphasize = shouldEnable)
|
||||
}
|
||||
|
||||
when {
|
||||
completed -> {
|
||||
parts.chip.text = t("done")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_green)
|
||||
parts.chip.setTextColor(Color.WHITE)
|
||||
}
|
||||
shouldEnable -> {
|
||||
parts.chip.text = t("start")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_amber)
|
||||
parts.chip.setTextColor(Color.WHITE)
|
||||
}
|
||||
else -> {
|
||||
parts.chip.text = t("locked")
|
||||
parts.chip.setBackgroundResource(R.drawable.bg_chip_grey)
|
||||
parts.chip.setTextColor(Color.parseColor("#2F2A49"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startQuestionnaireForButton(button: Button) {
|
||||
val fileName = questionnaireFiles[button] ?: return
|
||||
val questionnaire = QuestionnaireGeneric(fileName)
|
||||
startQuestionnaire(questionnaire)
|
||||
}
|
||||
// öffentliche Wrapper
|
||||
private fun updateButtonTexts() = applyUpdateButtonTexts(force = false)
|
||||
private fun setButtonsEnabled(enabledButtons: List<Button>, allowCompleted: Boolean = false) =
|
||||
applySetButtonsEnabled(enabledButtons, allowCompleted, force = false)
|
||||
|
||||
private fun startQuestionnaire(questionnaire: QuestionnaireBase<*>) {
|
||||
activity.startQuestionnaire(questionnaire, languageID)
|
||||
@ -285,48 +422,46 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
languageIDProvider = { languageID },
|
||||
questionnaireFiles = questionnaireFiles,
|
||||
buttonPoints = buttonPoints,
|
||||
updateButtonTexts = { updateButtonTexts() },
|
||||
setButtonsEnabled = { setButtonsEnabled(it) },
|
||||
updateButtonTexts = { applyUpdateButtonTexts(force = true) },
|
||||
setButtonsEnabled = { list, allowCompleted ->
|
||||
applySetButtonsEnabled(list, allowCompleted, force = true)
|
||||
},
|
||||
setUiFreeze = { freeze -> uiFreeze = freeze },
|
||||
triggerLoad = { buttonLoad.performClick() }
|
||||
).setup()
|
||||
}
|
||||
|
||||
private fun setupUploadButton() {
|
||||
uploadButton.text = "Upload"
|
||||
uploadButton.text = t("upload")
|
||||
uploadButton.setOnClickListener {
|
||||
val clientCode = editText.text.toString().trim()
|
||||
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
val input = EditText(activity).apply { hint = "Server-Passwort" }
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
.setTitle(t("login_required"))
|
||||
.setView(input)
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
val password = input.text.toString()
|
||||
if (password.isNotBlank()) {
|
||||
Toast.makeText(activity, "Login wird überprüft...", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, t("checking_login"), Toast.LENGTH_SHORT).show()
|
||||
DatabaseUploader.uploadDatabaseWithLogin(activity, password)
|
||||
} else {
|
||||
Toast.makeText(activity, "Bitte Passwort eingeben", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, t("enter_password"), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Abbrechen", null)
|
||||
.setNegativeButton(t("cancel"), null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDownloadButton() {
|
||||
downloadButton.text = "Download"
|
||||
downloadButton.text = t("download")
|
||||
downloadButton.setOnClickListener {
|
||||
val clientCode = editText.text.toString().trim()
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
val input = EditText(activity).apply { hint = "Server-Passwort" }
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
.setTitle(t("login_required"))
|
||||
.setView(input)
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
val password = input.text.toString()
|
||||
@ -335,7 +470,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
context = activity,
|
||||
password = password,
|
||||
onSuccess = { token ->
|
||||
Toast.makeText(activity, "Login erfolgreich", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, t("login_ok"), Toast.LENGTH_SHORT).show()
|
||||
DatabaseDownloader.downloadAndReplaceDatabase(activity, token)
|
||||
updateMainButtonsState(true)
|
||||
},
|
||||
@ -344,10 +479,10 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Toast.makeText(activity, "Bitte Passwort eingeben", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, t("enter_password"), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Abbrechen", null)
|
||||
.setNegativeButton(t("cancel"), null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@ -356,20 +491,92 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
DatabaseButtonHandler(
|
||||
activity = activity,
|
||||
databaseButton = databaseButton,
|
||||
onClose = {
|
||||
// zurück zum Opening-Screen
|
||||
init()
|
||||
},
|
||||
languageIDProvider = { languageID } // aktuelle Sprache an DatabaseButtonHandler weitergeben
|
||||
onClose = { init() },
|
||||
languageIDProvider = { languageID }
|
||||
).setup()
|
||||
}
|
||||
|
||||
|
||||
private fun updateMainButtonsState(isDatabaseAvailable: Boolean) {
|
||||
val buttons = listOf(buttonLoad, saveButton, editButton, databaseButton) // <-- NEU dabei
|
||||
buttons.forEach { button ->
|
||||
button.isEnabled = isDatabaseAvailable
|
||||
button.alpha = if (isDatabaseAvailable) 1.0f else 0.5f
|
||||
listOf(buttonLoad, saveButton, editButton, databaseButton).forEach { b ->
|
||||
b.isEnabled = isDatabaseAvailable
|
||||
b.alpha = if (isDatabaseAvailable) 1.0f else 0.5f
|
||||
}
|
||||
}
|
||||
|
||||
private fun dp(v: Int): Int =
|
||||
(v * activity.resources.displayMetrics.density).toInt()
|
||||
|
||||
private fun isCompleted(button: Button): Boolean {
|
||||
val fileName = questionnaireFiles[button] ?: return false
|
||||
return buttonPoints.keys.any { k ->
|
||||
fileName.contains(k, ignoreCase = true) || k.contains(fileName, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPointsForButton(button: Button): Int? {
|
||||
val fileName = questionnaireFiles[button] ?: return null
|
||||
return buttonPoints.entries.firstOrNull { (k, _) ->
|
||||
fileName.contains(k, ignoreCase = true) || k.contains(fileName, ignoreCase = true)
|
||||
}?.value
|
||||
}
|
||||
|
||||
/** Locked-Optik: schwarzer Hintergrund, fester grauer Rand */
|
||||
private fun setLockedAppearance(button: Button, locked: Boolean) {
|
||||
val mb = button as? MaterialButton ?: return
|
||||
if (locked) {
|
||||
mb.backgroundTintList = ColorStateList.valueOf(Color.BLACK)
|
||||
mb.strokeColor = ColorStateList.valueOf(STROKE_DISABLED)
|
||||
} else {
|
||||
mb.backgroundTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
mb.strokeColor = ColorStateList.valueOf(if (button.isEnabled) STROKE_ENABLED else STROKE_DISABLED)
|
||||
}
|
||||
}
|
||||
|
||||
/** Standardfarben wiederherstellen (wenn showPoints == false) – hier nicht mehr für locked zuständig */
|
||||
private fun resetTint(button: Button) {
|
||||
val mb = button as? MaterialButton ?: return
|
||||
mb.backgroundTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
mb.strokeColor = ColorStateList.valueOf(STROKE_DISABLED)
|
||||
}
|
||||
|
||||
/** Tönung nur anwenden, wenn showPoints == true (und Button nicht locked) */
|
||||
private fun applyTintForButton(button: Button, points: Int?, emphasize: Boolean) {
|
||||
val file = questionnaireFiles[button] ?: return
|
||||
val entry = questionnaireEntries.firstOrNull { it.file == file }
|
||||
|
||||
if (entry?.showPoints != true) {
|
||||
val mb = button as? MaterialButton ?: return
|
||||
mb.backgroundTintList = ColorStateList.valueOf(if (emphasize) Color.parseColor("#F1EEFF") else Color.WHITE)
|
||||
mb.strokeColor = ColorStateList.valueOf(if (emphasize) STROKE_ENABLED else STROKE_DISABLED)
|
||||
return
|
||||
}
|
||||
|
||||
setScoreTint(button, points, emphasize)
|
||||
}
|
||||
|
||||
/** Dickere Kontur, wenn anklickbar; Farbe bleibt fix */
|
||||
private fun setClickableStroke(button: Button, enabled: Boolean) {
|
||||
val mb = button as? MaterialButton ?: return
|
||||
mb.strokeWidth = if (enabled) dp(2) else dp(1)
|
||||
mb.strokeColor = ColorStateList.valueOf(if (enabled) STROKE_ENABLED else STROKE_DISABLED)
|
||||
}
|
||||
|
||||
/** Hintergrund nach Score; Rand bleibt fix */
|
||||
private fun setScoreTint(button: Button, points: Int?, emphasize: Boolean) {
|
||||
val mb = button as? MaterialButton ?: return
|
||||
|
||||
val bg = when {
|
||||
points == null && emphasize -> Color.parseColor("#F1EEFF")
|
||||
points == null -> Color.parseColor("#FFFFFF")
|
||||
points in 0..12 && emphasize -> Color.parseColor("#C8E6C9")
|
||||
points in 0..12 -> Color.parseColor("#E8F5E9")
|
||||
points in 13..36 && emphasize -> Color.parseColor("#FFE0B2")
|
||||
points in 13..36 -> Color.parseColor("#FFF8E1")
|
||||
points >= 37 && emphasize -> Color.parseColor("#FFCDD2")
|
||||
else -> Color.parseColor("#FFEBEE")
|
||||
}
|
||||
|
||||
mb.backgroundTintList = ColorStateList.valueOf(bg)
|
||||
mb.strokeColor = ColorStateList.valueOf(if (emphasize) STROKE_ENABLED else STROKE_DISABLED)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user