Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-25 11:17:02 +02:00
commit f7a629ccde
91 changed files with 8743 additions and 0 deletions

View File

@ -0,0 +1,116 @@
package com.dano.test1
import android.view.View
import android.widget.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class HandlerClientCoachCode(
private val answers: MutableMap<String, Any>,
private val languageID: String,
private val goToNextQuestion: () -> Unit,
private val goToPreviousQuestion: () -> Unit,
private val showToast: (String) -> Unit,
) : QuestionHandler {
private lateinit var question: QuestionItem.ClientCoachCodeQuestion
private lateinit var layout: View
override fun bind(layout: View, question: QuestionItem) {
if (question !is QuestionItem.ClientCoachCodeQuestion) return
this.layout = layout
this.question = question
// Bind UI components
val clientCodeField = layout.findViewById<EditText>(R.id.client_code)
val coachCodeField = layout.findViewById<EditText>(R.id.coach_code)
val questionTextView = layout.findViewById<TextView>(R.id.question)
// Fill question text using language manager
questionTextView.text = question.question?.let {
LanguageManager.getText(languageID, it)
} ?: ""
// Load last used client code if available
val lastClientCode = GlobalValues.LAST_CLIENT_CODE
if (!lastClientCode.isNullOrBlank()) {
clientCodeField.setText(lastClientCode)
clientCodeField.isEnabled = false
} else {
clientCodeField.setText(answers["client_code"] as? String ?: "")
clientCodeField.isEnabled = true
}
// Load saved coach code
coachCodeField.setText(answers["coach_code"] as? String ?: "")
// Set click listener for Next button
layout.findViewById<Button>(R.id.Qnext).setOnClickListener {
onNextClicked(clientCodeField, coachCodeField)
}
// Set click listener for Previous button
layout.findViewById<Button>(R.id.Qprev).setOnClickListener {
onPreviousClicked(clientCodeField, coachCodeField)
}
}
// Handle Next button click
private fun onNextClicked(clientCodeField: EditText, coachCodeField: EditText) {
if (!validate()) {
val message = LanguageManager.getText(languageID, "fill_both_fields")
showToast(message)
return
}
val clientCode = clientCodeField.text.toString()
val coachCode = coachCodeField.text.toString()
// Check if client code already exists asynchronously
CoroutineScope(Dispatchers.IO).launch {
val existingClient = MyApp.database.clientDao().getClientByCode(clientCode)
withContext(Dispatchers.Main) {
if (existingClient != null && clientCodeField.isEnabled) {
// Client code already exists and field was editable
val message = LanguageManager.getText(languageID, "client_code_exists")
showToast(message)
} else {
// Either no existing client or re-using previous code
saveAnswers(clientCode, coachCode)
goToNextQuestion()
}
}
}
}
// Handle Previous button click
private fun onPreviousClicked(clientCodeField: EditText, coachCodeField: EditText) {
val clientCode = clientCodeField.text.toString()
val coachCode = coachCodeField.text.toString()
saveAnswers(clientCode, coachCode)
goToPreviousQuestion()
}
// Validate that both fields are filled
override fun validate(): Boolean {
val clientCode = layout.findViewById<EditText>(R.id.client_code).text
val coachCode = layout.findViewById<EditText>(R.id.coach_code).text
return clientCode.isNotBlank() && coachCode.isNotBlank()
}
// Save answers to shared state and global value
private fun saveAnswers(clientCode: String, coachCode: String) {
GlobalValues.LAST_CLIENT_CODE = clientCode
answers["client_code"] = clientCode
answers["coach_code"] = coachCode
}
// Required override but not used here
override fun saveAnswer() {
// Not used
}
}