added database feature, to check entries
This commit is contained in:
@ -22,6 +22,7 @@ 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 val dynamicButtons = mutableListOf<Button>()
|
||||
private val questionnaireFiles = mutableMapOf<Button, String>()
|
||||
@ -43,6 +44,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
setupEditButtonHandler()
|
||||
setupUploadButton()
|
||||
setupDownloadButton()
|
||||
setupDatabaseButtonHandler() // <-- NEU
|
||||
|
||||
val dbPath = "/data/data/com.dano.test1/databases/questionnaire_database"
|
||||
val pathExists = File(dbPath).exists()
|
||||
@ -63,6 +65,7 @@ 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
|
||||
|
||||
val tag = editText.tag as? String ?: ""
|
||||
editText.hint = LanguageManager.getText(languageID, tag)
|
||||
@ -90,7 +93,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
}
|
||||
|
||||
// Parser: erzeugt ein QuestionItem.Condition? (sehr robust gegenüber verschiedenen JSON-Formaten)
|
||||
private fun parseCondition(conditionObj: JSONObject?): QuestionItem.Condition? {
|
||||
if (conditionObj == null) return null
|
||||
if (conditionObj.has("anyOf")) {
|
||||
@ -163,17 +165,13 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
|
||||
dynamicButtons.forEach { button ->
|
||||
button.setOnClickListener {
|
||||
|
||||
// Optional: LAST_CLIENT_CODE synchronisieren (rein informativ)
|
||||
GlobalValues.LAST_CLIENT_CODE = GlobalValues.LOADED_CLIENT_CODE
|
||||
|
||||
startQuestionnaireForButton(button)
|
||||
setButtonsEnabled(dynamicButtons.filter { it == button })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun restorePreviousClientCode() {
|
||||
GlobalValues.LAST_CLIENT_CODE?.let { editText.setText(it) }
|
||||
}
|
||||
@ -213,13 +211,9 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
|
||||
private fun updateButtonTexts() {
|
||||
questionnaireFiles.forEach { (button, fileName) ->
|
||||
|
||||
val entry = questionnaireEntries.firstOrNull { it.file == fileName }
|
||||
|
||||
// key ableiten
|
||||
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
|
||||
|
||||
@ -231,10 +225,10 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
|
||||
if (entry?.showPoints == true && pointsAvailable != null) {
|
||||
when {
|
||||
points in 0..12 -> button.setBackgroundColor(Color.parseColor("#4CAF50")) // Grün
|
||||
points in 13..36 -> button.setBackgroundColor(Color.parseColor("#FFEB3B")) // Gelb
|
||||
points in 37..100 -> button.setBackgroundColor(Color.parseColor("#F44336")) // Rot
|
||||
else -> button.setBackgroundColor(Color.parseColor("#E0E0E0")) // Grau bei 0 Punkten
|
||||
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"))
|
||||
}
|
||||
} else {
|
||||
button.setBackgroundColor(Color.parseColor("#E0E0E0"))
|
||||
@ -242,6 +236,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
|
||||
buttonLoad.text = LanguageManager.getText(languageID, "load")
|
||||
databaseButton.text = "Datenbank" // fixierter Text gewünscht
|
||||
}
|
||||
|
||||
private fun setButtonsEnabled(enabledButtons: List<Button>) {
|
||||
@ -282,12 +277,10 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
buttonPoints = buttonPoints,
|
||||
updateButtonTexts = { updateButtonTexts() },
|
||||
setButtonsEnabled = { setButtonsEnabled(it) },
|
||||
// Vor "Bearbeiten" ggf. den Load-Button ausführen
|
||||
triggerLoad = { buttonLoad.performClick() }
|
||||
).setup()
|
||||
}
|
||||
|
||||
|
||||
private fun setupUploadButton() {
|
||||
uploadButton.text = "Upload"
|
||||
uploadButton.setOnClickListener {
|
||||
@ -295,10 +288,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
// Passwort-Eingabe-Popup
|
||||
val input = EditText(activity).apply {
|
||||
hint = "Server-Passwort"
|
||||
}
|
||||
val input = EditText(activity).apply { hint = "Server-Passwort" }
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
@ -307,7 +297,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
val password = input.text.toString()
|
||||
if (password.isNotBlank()) {
|
||||
Toast.makeText(activity, "Login wird überprüft...", Toast.LENGTH_SHORT).show()
|
||||
// Login + Upload starten
|
||||
DatabaseUploader.uploadDatabaseWithLogin(activity, password)
|
||||
} else {
|
||||
Toast.makeText(activity, "Bitte Passwort eingeben", Toast.LENGTH_SHORT).show()
|
||||
@ -324,10 +313,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
val clientCode = editText.text.toString().trim()
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
// Eingabe-Popup für Passwort anzeigen
|
||||
val input = EditText(activity).apply {
|
||||
hint = "Server-Passwort"
|
||||
}
|
||||
val input = EditText(activity).apply { hint = "Server-Passwort" }
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
@ -335,7 +321,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
val password = input.text.toString()
|
||||
if (password.isNotBlank()) {
|
||||
// Login starten
|
||||
LoginManager.loginUser(
|
||||
context = activity,
|
||||
password = password,
|
||||
@ -357,8 +342,18 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDatabaseButtonHandler() {
|
||||
DatabaseButtonHandler(
|
||||
activity = activity,
|
||||
databaseButton = databaseButton
|
||||
) {
|
||||
// zurück zum Opening-Screen
|
||||
init()
|
||||
}.setup()
|
||||
}
|
||||
|
||||
private fun updateMainButtonsState(isDatabaseAvailable: Boolean) {
|
||||
val buttons = listOf(buttonLoad, saveButton, editButton)
|
||||
val buttons = listOf(buttonLoad, saveButton, editButton, databaseButton) // <-- NEU dabei
|
||||
buttons.forEach { button ->
|
||||
button.isEnabled = isDatabaseAvailable
|
||||
button.alpha = if (isDatabaseAvailable) 1.0f else 0.5f
|
||||
|
||||
Reference in New Issue
Block a user