added clientCode_change
This commit is contained in:
@ -155,7 +155,13 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val isDatabaseView = inputText.endsWith("_database")
|
val isDatabaseView = inputText.endsWith("_database")
|
||||||
val clientCode = if (isDatabaseView) inputText.removeSuffix("_database") else inputText
|
val isChangeView = inputText.endsWith("_change")
|
||||||
|
|
||||||
|
// Extrahiere nur den echten Code, ohne die Suffixe
|
||||||
|
val clientCode = inputText
|
||||||
|
.removeSuffix("_database")
|
||||||
|
.removeSuffix("_change")
|
||||||
|
|
||||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
@ -170,17 +176,22 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
// Normales Laden
|
||||||
|
handleNormalLoad(clientCode)
|
||||||
|
|
||||||
|
// Erweiterungen bei speziellen Suffixen
|
||||||
if (isDatabaseView) {
|
if (isDatabaseView) {
|
||||||
handleNormalLoad(clientCode)
|
|
||||||
showCompletedQuestionnaires(clientCode)
|
showCompletedQuestionnaires(clientCode)
|
||||||
} else {
|
enableCompletedQuestionnaireButtons(clientCode)
|
||||||
handleNormalLoad(clientCode)
|
} else if (isChangeView) {
|
||||||
|
enableCompletedQuestionnaireButtons(clientCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private suspend fun handleNormalLoad(clientCode: String) {
|
private suspend fun handleNormalLoad(clientCode: String) {
|
||||||
val completedIds = withContext(Dispatchers.IO) {
|
val completedIds = withContext(Dispatchers.IO) {
|
||||||
MyApp.database.completedQuestionnaireDao().getCompletedQuestionnairesForClient(clientCode)
|
MyApp.database.completedQuestionnaireDao().getCompletedQuestionnairesForClient(clientCode)
|
||||||
@ -292,8 +303,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun startQuestionnaireForButton(button: Button) {
|
private fun startQuestionnaireForButton(button: Button) {
|
||||||
val fileName = questionnaireFiles[button] ?: return
|
val fileName = questionnaireFiles[button] ?: return
|
||||||
val questionnaire = QuestionnaireGeneric(fileName)
|
val questionnaire = QuestionnaireGeneric(fileName)
|
||||||
@ -487,4 +496,25 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
|||||||
paint.isFakeBoldText = false
|
paint.isFakeBoldText = false
|
||||||
return y
|
return y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun enableCompletedQuestionnaireButtons(clientCode: String) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
val completedEntries = MyApp.database.completedQuestionnaireDao().getAllForClient(clientCode)
|
||||||
|
|
||||||
|
val completedFiles = completedEntries
|
||||||
|
.filter { it.isDone }
|
||||||
|
.map { it.questionnaireId.lowercase() }
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
questionnaireFiles.forEach { (button, fileName) ->
|
||||||
|
val isCompleted = completedFiles.any { fileName.lowercase().contains(it) }
|
||||||
|
if (isCompleted) {
|
||||||
|
button.isEnabled = true
|
||||||
|
button.alpha = 1.0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user