diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 9c03c05..c827308 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -123,7 +123,7 @@ class MainActivity : AppCompatActivity() { showSettings() }) findViewById(R.id.button_no_connection_retry).setOnClickListener({ - loadLogbook(logbook.name) + loadLogbookList() }) findViewById(R.id.button_sync).setOnClickListener({ loadLogbook(logbook.name) @@ -375,15 +375,35 @@ class MainActivity : AppCompatActivity() { } override fun onIOError(error: IOException) { - TODO("Not yet implemented") + Log.e(TAG, "Unable to load logbooks list (IOError): $error") + runOnUiThread({ + setLoading(false) + onRepoError(getString(R.string.settings_network_error) + error.toString()) + }) } override fun onWebDAVError(error: SardineException) { - TODO("Not yet implemented") + Log.e(TAG, "Unable to load logbooks list (SardineException): $error") + runOnUiThread({ + setLoading(false) + onRepoError( + if(error.toString().contains("401")) { + getString(R.string.settings_webdav_error_denied) + } else if(error.toString().contains("503")) { + getString(R.string.settings_webdav_error_server_offline) + } else { + getString(R.string.settings_webdav_error_generic) + error.toString() + } + ) + }) } override fun onError(error: Exception) { - TODO("Not yet implemented") + Log.e(TAG, "Unable to load logbooks list: $error") + runOnUiThread({ + setLoading(false) + onRepoError(getString(R.string.settings_generic_error) + error.toString()) + }) } }) } @@ -412,6 +432,8 @@ class MainActivity : AppCompatActivity() { onRepoError( if(error.toString().contains("401")) { getString(R.string.settings_webdav_error_denied) + } else if(error.toString().contains("503")) { + getString(R.string.settings_webdav_error_server_offline) } else { getString(R.string.settings_webdav_error_generic) + error.toString() } @@ -475,6 +497,8 @@ class MainActivity : AppCompatActivity() { onRepoError( if(error.toString().contains("401")) { getString(R.string.settings_webdav_error_denied) + } else if(error.toString().contains("503")) { + getString(R.string.settings_webdav_error_server_offline) } else { getString(R.string.settings_webdav_error_generic) + error.toString() } @@ -573,6 +597,8 @@ class MainActivity : AppCompatActivity() { onRepoError( if(error.toString().contains("401")) { getString(R.string.settings_webdav_error_denied) + } else if(error.toString().contains("503")) { + getString(R.string.settings_webdav_error_server_offline) } else { getString(R.string.settings_webdav_error_generic) + error.toString() } diff --git a/app/src/main/java/it/danieleverducci/lunatracker/repository/WebDAVLogbookRepository.kt b/app/src/main/java/it/danieleverducci/lunatracker/repository/WebDAVLogbookRepository.kt index f861bee..6bb5b41 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/repository/WebDAVLogbookRepository.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/repository/WebDAVLogbookRepository.kt @@ -103,19 +103,32 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p listener: LogbookListObtainedListener ) { Thread(Runnable { - val logbooksNames = arrayListOf() - for (dr: DavResource in sardine.list(webDavURL)){ - if(!dr.name.startsWith(FILE_NAME_START)) - continue - if(!dr.name.endsWith(FILE_NAME_END)) - continue - logbooksNames.add( - dr.name.replace("${FILE_NAME_START}_", "") - .replace(FILE_NAME_START, "") - .replace(FILE_NAME_END, "") - ) + try { + val logbooksNames = arrayListOf() + for (dr: DavResource in sardine.list(webDavURL)){ + if(!dr.name.startsWith(FILE_NAME_START)) + continue + if(!dr.name.endsWith(FILE_NAME_END)) + continue + logbooksNames.add( + dr.name.replace("${FILE_NAME_START}_", "") + .replace(FILE_NAME_START, "") + .replace(FILE_NAME_END, "") + ) + } + listener.onLogbookListObtained(logbooksNames) + } catch (e: SardineException) { + Log.e(TAG, e.toString()) + listener.onWebDAVError(e) + } catch (e: IOException) { + Log.e(TAG, e.toString()) + listener.onIOError(e) + } catch (e: SocketTimeoutException) { + Log.e(TAG, e.toString()) + listener.onIOError(e) + } catch (e: Exception) { + listener.onError(e) } - listener.onLogbookListObtained(logbooksNames) }).start() } diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index f510c13..37df3c2 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -61,6 +61,7 @@ Password Impossibile raggiungere il server: Nome utente o password WebDAV sbagliati + Il server WebDAV non è al momento disponibile Si è verificato un errore tentando di accedere al server WebDAV: Impossibile creare un file di salvataggio sul server WebDAV: Connessione al server WebDAV avvenuta con successo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f99d7c9..6bfaa28 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -75,6 +75,7 @@ Password Unable to reach server: Wrong WebDAV user or password + WebDAV server is currently unavailable Error while trying to access WebDAV: Unable to save a file on the WebDAV server: Successfully connected with WebDAV server