From fbe548c8d8cec651c9d8a023459345eea723a4af Mon Sep 17 00:00:00 2001 From: oxidiert Date: Fri, 8 Aug 2025 12:01:30 +0200 Subject: [PATCH] Added Upload feature. Database will be uploaded to Hetzner Server. Database already encrypted with AES256. Database will be deleted from the app after uploading database. --- .idea/vcs.xml | 6 ++ app/build.gradle.kts | 9 ++ app/src/main/AndroidManifest.xml | 3 + .../java/com/dano/test1/DatabaseUploader.kt | 88 +++++++++++++++++++ .../com/dano/test1/HandlerOpeningScreen.kt | 39 ++++---- app/src/main/res/layout/opening_screen.xml | 10 ++- .../main/res/xml/network_security_config.xml | 6 ++ 7 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/com/dano/test1/DatabaseUploader.kt create mode 100644 app/src/main/res/xml/network_security_config.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8c5f749..4d31e21 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,4 +53,13 @@ dependencies { implementation("androidx.room:room-ktx:$room_version") implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") + + // SQLCipher + implementation ("net.zetetic:android-database-sqlcipher:4.5.3@aar") + implementation ("androidx.sqlite:sqlite:2.1.0") + implementation ("androidx.sqlite:sqlite-framework:2.1.0") + + // Server Upload + implementation("com.squareup.okhttp3:okhttp:4.12.0") + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5dcd779..b08ffec 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + + () private val questionnaireFiles = mutableMapOf() @@ -40,6 +42,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) { setupLoadButton() setupSaveButton() setupEditButton() + setupUploadButton() if (!editText.text.isNullOrBlank()) { buttonLoad.performClick() @@ -54,6 +57,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) { buttonLoad = activity.findViewById(R.id.loadButton) saveButton = activity.findViewById(R.id.saveButton) editButton = activity.findViewById(R.id.editButton) + uploadButton = activity.findViewById(R.id.uploadButton) val tag = editText.tag as? String ?: "" editText.hint = LanguageManager.getText(languageID, tag) @@ -233,7 +237,7 @@ class HandlerOpeningScreen(private val activity: MainActivity) { val conditionMet = when (condition.operator) { "!=" -> answerValue != condition.value "==" -> answerValue == condition.value - else -> true // fallback: zeige Fragebogen + else -> true } if (conditionMet) break @@ -488,26 +492,6 @@ class HandlerOpeningScreen(private val activity: MainActivity) { 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 - } - } - } - } - } - private fun setupSaveButton() { saveButton.text = LanguageManager.getText(languageID, "save") saveButton.setOnClickListener { @@ -560,4 +544,17 @@ class HandlerOpeningScreen(private val activity: MainActivity) { } } + private fun setupUploadButton() { + uploadButton.text = "Upload" + uploadButton.setOnClickListener { + val clientCode = editText.text.toString().trim() + + GlobalValues.LAST_CLIENT_CODE = clientCode + + Toast.makeText(activity, "Datenbank wird verschlüsselt...", Toast.LENGTH_SHORT).show() + DatabaseUploader.uploadEncryptedDatabase(activity) + } + } + + } \ No newline at end of file diff --git a/app/src/main/res/layout/opening_screen.xml b/app/src/main/res/layout/opening_screen.xml index 17a4c24..ee4bbdd 100644 --- a/app/src/main/res/layout/opening_screen.xml +++ b/app/src/main/res/layout/opening_screen.xml @@ -44,7 +44,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/textView" /> -