added passwort for login and download, token-system
This commit is contained in:
@ -13,7 +13,7 @@ import android.util.Log
|
||||
import com.dano.test1.data.CompletedQuestionnaire
|
||||
import java.io.File
|
||||
|
||||
var INTEGRATION_INDEX_POINTS: Int? = null
|
||||
var RHS_POINTS: Int? = null
|
||||
|
||||
class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
|
||||
@ -342,13 +342,12 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
MyApp.database.completedQuestionnaireDao().getAllForClient(clientCode)
|
||||
}
|
||||
|
||||
// fülle buttonPoints & INTEGRATION_INDEX_POINTS
|
||||
buttonPoints.clear()
|
||||
for (entry in completedEntries) {
|
||||
if (entry.isDone) {
|
||||
buttonPoints[entry.questionnaireId] = entry.sumPoints ?: 0
|
||||
if (entry.questionnaireId.contains("questionnaire_3_integration_index", ignoreCase = true)) {
|
||||
INTEGRATION_INDEX_POINTS = entry.sumPoints
|
||||
if (entry.questionnaireId.contains("questionnaire_2_rhs", ignoreCase = true)) {
|
||||
RHS_POINTS = entry.sumPoints
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -682,39 +681,79 @@ class HandlerOpeningScreen(private val activity: MainActivity) {
|
||||
uploadButton.setOnClickListener {
|
||||
val clientCode = editText.text.toString().trim()
|
||||
|
||||
if (clientCode.isBlank()) {
|
||||
val message = LanguageManager.getText(languageID, "please_client_code")
|
||||
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
Toast.makeText(activity, "Datenbank wird hochgeladen...", Toast.LENGTH_SHORT).show()
|
||||
DatabaseUploader.uploadDatabase(activity)
|
||||
// Passwort-Eingabe-Popup
|
||||
val input = EditText(activity).apply {
|
||||
hint = "Server-Passwort"
|
||||
}
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
.setView(input)
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
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()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Abbrechen", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
// --- Füge diese Funktion in deine Klasse ein ---
|
||||
private fun isDatabasePopulated(): Boolean {
|
||||
return try {
|
||||
val db = MyApp.database.openHelper.readableDatabase
|
||||
val cursor = db.query(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != 'room_master_table'"
|
||||
)
|
||||
cursor.use { it.count > 0 }
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun setupDownloadButton() {
|
||||
downloadButton.text = "Download"
|
||||
downloadButton.setOnClickListener {
|
||||
val clientCode = editText.text.toString().trim()
|
||||
|
||||
GlobalValues.LAST_CLIENT_CODE = clientCode
|
||||
|
||||
Toast.makeText(activity, "Datenbank wird heruntergeladen...", Toast.LENGTH_SHORT).show()
|
||||
DatabaseDownloader.downloadAndReplaceDatabase(activity)
|
||||
updateMainButtonsState(true)
|
||||
// Eingabe-Popup für Passwort anzeigen
|
||||
val input = EditText(activity).apply {
|
||||
hint = "Server-Passwort"
|
||||
}
|
||||
|
||||
android.app.AlertDialog.Builder(activity)
|
||||
.setTitle("Login erforderlich")
|
||||
.setView(input)
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
val password = input.text.toString()
|
||||
if (password.isNotBlank()) {
|
||||
// Login starten
|
||||
LoginManager.loginUser(
|
||||
context = activity,
|
||||
password = password,
|
||||
onSuccess = { token ->
|
||||
Toast.makeText(activity, "Login erfolgreich", Toast.LENGTH_SHORT).show()
|
||||
DatabaseDownloader.downloadAndReplaceDatabase(activity, token)
|
||||
updateMainButtonsState(true)
|
||||
},
|
||||
onError = { error ->
|
||||
Toast.makeText(activity, error, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Toast.makeText(activity, "Bitte Passwort eingeben", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Abbrechen", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateMainButtonsState(isDatabaseAvailable: Boolean) {
|
||||
val buttons = listOf(buttonLoad, saveButton, editButton)
|
||||
buttons.forEach { button ->
|
||||
|
||||
Reference in New Issue
Block a user