Fix: Separate connection test from sync
- Add testConnection() method that only tests connectivity - Connection test no longer syncs notes automatically - Only 'Sync Now' button triggers actual synchronization
This commit is contained in:
@@ -97,10 +97,10 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
try {
|
try {
|
||||||
showToast("Teste Verbindung...")
|
showToast("Teste Verbindung...")
|
||||||
val syncService = WebDavSyncService(this@SettingsActivity)
|
val syncService = WebDavSyncService(this@SettingsActivity)
|
||||||
val result = syncService.syncNotes()
|
val result = syncService.testConnection()
|
||||||
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
showToast("Verbindung erfolgreich! ${result.syncedCount} Notizen synchronisiert")
|
showToast("Verbindung erfolgreich!")
|
||||||
} else {
|
} else {
|
||||||
showToast("Verbindung fehlgeschlagen: ${result.errorMessage}")
|
showToast("Verbindung fehlgeschlagen: ${result.errorMessage}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,52 @@ class WebDavSyncService(private val context: Context) {
|
|||||||
return prefs.getString(Constants.KEY_SERVER_URL, null)
|
return prefs.getString(Constants.KEY_SERVER_URL, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun testConnection(): SyncResult = withContext(Dispatchers.IO) {
|
||||||
|
return@withContext try {
|
||||||
|
val sardine = getSardine() ?: return@withContext SyncResult(
|
||||||
|
isSuccess = false,
|
||||||
|
errorMessage = "Server-Zugangsdaten nicht konfiguriert"
|
||||||
|
)
|
||||||
|
|
||||||
|
val serverUrl = getServerUrl() ?: return@withContext SyncResult(
|
||||||
|
isSuccess = false,
|
||||||
|
errorMessage = "Server-URL nicht konfiguriert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Only test if directory exists or can be created
|
||||||
|
val exists = sardine.exists(serverUrl)
|
||||||
|
if (!exists) {
|
||||||
|
sardine.createDirectory(serverUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncResult(
|
||||||
|
isSuccess = true,
|
||||||
|
syncedCount = 0,
|
||||||
|
errorMessage = null
|
||||||
|
)
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
SyncResult(
|
||||||
|
isSuccess = false,
|
||||||
|
errorMessage = when (e) {
|
||||||
|
is java.net.UnknownHostException -> "Server nicht erreichbar"
|
||||||
|
is java.net.SocketTimeoutException -> "Verbindungs-Timeout"
|
||||||
|
is javax.net.ssl.SSLException -> "SSL-Fehler"
|
||||||
|
is com.thegrizzlylabs.sardineandroid.impl.SardineException -> {
|
||||||
|
when (e.statusCode) {
|
||||||
|
401 -> "Authentifizierung fehlgeschlagen"
|
||||||
|
403 -> "Zugriff verweigert"
|
||||||
|
404 -> "Server-Pfad nicht gefunden"
|
||||||
|
500 -> "Server-Fehler"
|
||||||
|
else -> "HTTP-Fehler: ${e.statusCode}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> e.message ?: "Unbekannter Fehler"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun syncNotes(): SyncResult = withContext(Dispatchers.IO) {
|
suspend fun syncNotes(): SyncResult = withContext(Dispatchers.IO) {
|
||||||
return@withContext try {
|
return@withContext try {
|
||||||
val sardine = getSardine() ?: return@withContext SyncResult(
|
val sardine = getSardine() ?: return@withContext SyncResult(
|
||||||
|
|||||||
Reference in New Issue
Block a user