removed edit button to always allow editing
This commit is contained in:
@ -1,97 +0,0 @@
|
||||
package com.dano.test1.ui
|
||||
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import com.dano.test1.LanguageManager
|
||||
import com.dano.test1.MainActivity
|
||||
import com.dano.test1.MyApp
|
||||
import kotlinx.coroutines.*
|
||||
import com.dano.test1.data.CompletedQuestionnaire
|
||||
import com.dano.test1.questionnaire.GlobalValues
|
||||
|
||||
class EditButtonHandler(
|
||||
private val activity: MainActivity,
|
||||
private val editButton: Button,
|
||||
private val editText: EditText,
|
||||
private val languageIDProvider: () -> String,
|
||||
private val questionnaireFiles: Map<Button, String>,
|
||||
private val buttonPoints: MutableMap<String, Int>,
|
||||
private val updateButtonTexts: () -> Unit,
|
||||
private val setButtonsEnabled: (List<Button>, Boolean) -> Unit,
|
||||
private val setUiFreeze: (Boolean) -> Unit,
|
||||
private val triggerLoad: () -> Unit
|
||||
) {
|
||||
|
||||
fun setup() {
|
||||
editButton.text = LanguageManager.getText(languageIDProvider(), "edit")
|
||||
editButton.setOnClickListener { handleEditButtonClick() }
|
||||
}
|
||||
|
||||
private fun handleEditButtonClick() {
|
||||
val typed = editText.text.toString().trim()
|
||||
val desiredCode = when {
|
||||
typed.isNotBlank() -> typed
|
||||
!GlobalValues.LOADED_CLIENT_CODE.isNullOrBlank() -> GlobalValues.LOADED_CLIENT_CODE!!
|
||||
else -> ""
|
||||
}
|
||||
|
||||
if (desiredCode.isBlank()) {
|
||||
val message = LanguageManager.getText(languageIDProvider(), "please_client_code")
|
||||
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
GlobalValues.LAST_CLIENT_CODE = desiredCode
|
||||
|
||||
val needLoad = GlobalValues.LOADED_CLIENT_CODE?.equals(desiredCode) != true
|
||||
if (needLoad) {
|
||||
setUiFreeze(true) // Zwischenzustände unterdrücken
|
||||
triggerLoad()
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val loadedOk = waitUntilClientLoaded(desiredCode, timeoutMs = 2500, stepMs = 50)
|
||||
if (!loadedOk) {
|
||||
withContext(Dispatchers.Main) {
|
||||
val msg = LanguageManager.getText(languageIDProvider(), "open_client_via_load")
|
||||
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show()
|
||||
setUiFreeze(false)
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
val completedEntries: List<CompletedQuestionnaire> =
|
||||
MyApp.database.completedQuestionnaireDao().getAllForClient(desiredCode)
|
||||
|
||||
val completedFiles = completedEntries.filter { it.isDone }.map { it.questionnaireId.lowercase() }
|
||||
|
||||
buttonPoints.clear()
|
||||
for (entry in completedEntries) {
|
||||
if (entry.isDone) {
|
||||
buttonPoints[entry.questionnaireId] = entry.sumPoints ?: 0
|
||||
}
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
updateButtonTexts()
|
||||
val enabledButtons = questionnaireFiles.filter { (_, fileName) ->
|
||||
completedFiles.any { completedId -> fileName.lowercase().contains(completedId) }
|
||||
}.keys.toList()
|
||||
setButtonsEnabled(enabledButtons, true)
|
||||
setUiFreeze(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun waitUntilClientLoaded(expectedCode: String, timeoutMs: Long, stepMs: Long): Boolean {
|
||||
if (GlobalValues.LOADED_CLIENT_CODE?.equals(expectedCode) == true) return true
|
||||
var waited = 0L
|
||||
while (waited < timeoutMs) {
|
||||
delay(stepMs)
|
||||
waited += stepMs
|
||||
if (GlobalValues.LOADED_CLIENT_CODE?.equals(expectedCode) == true) return true
|
||||
}
|
||||
return GlobalValues.LOADED_CLIENT_CODE?.equals(expectedCode) == true
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
private lateinit var buttonContainer: LinearLayout
|
||||
private lateinit var buttonLoad: Button
|
||||
private lateinit var saveButton: Button
|
||||
private lateinit var editButton: Button
|
||||
private lateinit var uploadButton: Button
|
||||
private lateinit var downloadButton: Button
|
||||
private lateinit var statusSession: TextView
|
||||
@ -93,7 +92,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
setupLanguageSpinner()
|
||||
setupLoadButton()
|
||||
setupSaveButton()
|
||||
setupEditButtonHandler()
|
||||
setupUploadButton()
|
||||
setupDownloadButton()
|
||||
|
||||
@ -121,7 +119,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
buttonContainer = activity.findViewById(R.id.buttonContainer)
|
||||
buttonLoad = activity.findViewById(R.id.loadButton)
|
||||
saveButton = activity.findViewById(R.id.saveButton)
|
||||
editButton = activity.findViewById(R.id.editButton)
|
||||
uploadButton = activity.findViewById(R.id.uploadButton)
|
||||
|
||||
downloadButton = activity.findViewById(R.id.downloadButton)
|
||||
@ -328,7 +325,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
dynamicButtonsProvider = { dynamicButtons },
|
||||
buttonPoints = buttonPoints,
|
||||
updateButtonTexts = { applyUpdateButtonTexts(force = false) },
|
||||
setButtonsEnabled = { list -> applySetButtonsEnabled(list, allowCompleted = false, force = false) },
|
||||
setButtonsEnabled = { list -> applySetButtonsEnabled(list, allowCompleted = true, force = false) },
|
||||
updateMainButtonsState = { updateMainButtonsState(it) },
|
||||
).setup()
|
||||
}
|
||||
@ -384,7 +381,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
buttonLoad.text = t("load")
|
||||
saveButton.text = t("save")
|
||||
editButton.text = t("edit")
|
||||
uploadButton.text = t("upload")
|
||||
downloadButton.text = t("download")
|
||||
val hintTag = editText.tag as? String ?: ""
|
||||
@ -451,23 +447,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
).setup()
|
||||
}
|
||||
|
||||
private fun setupEditButtonHandler() {
|
||||
EditButtonHandler(
|
||||
activity = activity,
|
||||
editButton = editButton,
|
||||
editText = editText,
|
||||
languageIDProvider = { languageID },
|
||||
questionnaireFiles = questionnaireFiles,
|
||||
buttonPoints = buttonPoints,
|
||||
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 = t("upload")
|
||||
uploadButton.setOnClickListener {
|
||||
@ -530,7 +509,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
|
||||
private fun updateMainButtonsState(isDatabaseAvailable: Boolean) {
|
||||
listOf(buttonLoad, saveButton, editButton).forEach { b ->
|
||||
listOf(buttonLoad, saveButton).forEach { b ->
|
||||
b.isEnabled = isDatabaseAvailable
|
||||
b.alpha = if (isDatabaseAvailable) 1.0f else 0.5f
|
||||
}
|
||||
|
||||
@ -160,10 +160,9 @@ class LoadButtonHandler(
|
||||
(completedNorm.contains(targetNorm) || targetNorm.contains(completedNorm)) && completed.isDone
|
||||
}
|
||||
}
|
||||
if (isCompleted) continue
|
||||
|
||||
val condMet = evaluateCondition(entry.condition, clientCode, completedEntries)
|
||||
if (condMet) enabledButtons.add(button)
|
||||
if (condMet || isCompleted) enabledButtons.add(button)
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
@ -195,21 +195,6 @@
|
||||
app:cornerRadius="@dimen/pill_radius"
|
||||
app:backgroundTint="@color/brand_purple"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/editButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/pill_height"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/white"
|
||||
app:icon="@drawable/ic_dot_16"
|
||||
app:iconTint="@android:color/white"
|
||||
app:iconPadding="8dp"
|
||||
app:iconGravity="textStart"
|
||||
app:cornerRadius="@dimen/pill_radius"
|
||||
app:backgroundTint="@color/brand_purple"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/saveButton"
|
||||
android:layout_width="0dp"
|
||||
|
||||
Reference in New Issue
Block a user