Better error management, check Webdav instance unavailable, fixed crash on refresh when webdav instance was unavailable
This commit is contained in:
parent
34ca6c1cd6
commit
744bfef62b
@ -123,7 +123,7 @@ class MainActivity : AppCompatActivity() {
|
||||
showSettings()
|
||||
})
|
||||
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
|
||||
loadLogbook(logbook.name)
|
||||
loadLogbookList()
|
||||
})
|
||||
findViewById<View>(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()
|
||||
}
|
||||
|
@ -103,19 +103,32 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
|
||||
listener: LogbookListObtainedListener
|
||||
) {
|
||||
Thread(Runnable {
|
||||
val logbooksNames = arrayListOf<String>()
|
||||
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<String>()
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@
|
||||
<string name="settings_storage_dav_pass">Password</string>
|
||||
<string name="settings_network_error">Impossibile raggiungere il server: </string>
|
||||
<string name="settings_webdav_error_denied">Nome utente o password WebDAV sbagliati</string>
|
||||
<string name="settings_webdav_error_server_offline">Il server WebDAV non è al momento disponibile</string>
|
||||
<string name="settings_webdav_error_generic">Si è verificato un errore tentando di accedere al server WebDAV:</string>
|
||||
<string name="settings_webdav_creation_error_generic">Impossibile creare un file di salvataggio sul server WebDAV:</string>
|
||||
<string name="settings_webdav_creation_ok">Connessione al server WebDAV avvenuta con successo</string>
|
||||
|
@ -75,6 +75,7 @@
|
||||
<string name="settings_storage_dav_pass">Password</string>
|
||||
<string name="settings_network_error">Unable to reach server: </string>
|
||||
<string name="settings_webdav_error_denied">Wrong WebDAV user or password</string>
|
||||
<string name="settings_webdav_error_server_offline">WebDAV server is currently unavailable</string>
|
||||
<string name="settings_webdav_error_generic">Error while trying to access WebDAV:</string>
|
||||
<string name="settings_webdav_creation_error_generic">Unable to save a file on the WebDAV server:</string>
|
||||
<string name="settings_webdav_creation_ok">Successfully connected with WebDAV server</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user