Using proper error screen
This commit is contained in:
parent
308092415b
commit
484a4698fa
@ -49,12 +49,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val localSettings = LocalSettingsRepository(this)
|
|
||||||
val webDavCredentials = localSettings.loadWebdavCredentials()
|
|
||||||
if (webDavCredentials == null) {
|
|
||||||
TODO("Not supported ATM (TODO: apply settings)")
|
|
||||||
}
|
|
||||||
|
|
||||||
handler = Handler(mainLooper)
|
handler = Handler(mainLooper)
|
||||||
adapter = LunaEventRecyclerAdapter(this)
|
adapter = LunaEventRecyclerAdapter(this)
|
||||||
|
|
||||||
@ -214,46 +208,45 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onIOError(error: IOException) {
|
override fun onIOError(error: IOException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_network_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWebDAVError(error: SardineException) {
|
override fun onWebDAVError(error: SardineException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
if(error.toString().contains("401")) {
|
onRepoError(
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_webdav_error_denied), Toast.LENGTH_SHORT).show()
|
if(error.toString().contains("401")) {
|
||||||
} else {
|
getString(R.string.settings_webdav_error_denied)
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_webdav_error_generic) + error.toString(), Toast.LENGTH_SHORT).show()
|
} else {
|
||||||
}
|
getString(R.string.settings_webdav_error_generic) + error.toString()
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onJSONError(error: JSONException) {
|
override fun onJSONError(error: JSONException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_json_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(error: Exception) {
|
override fun onError(error: Exception) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_generic_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRepoError(e: Exception){
|
fun onRepoError(message: String){
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
findViewById<View>(R.id.no_connection_screen).visibility = View.VISIBLE
|
findViewById<View>(R.id.no_connection_screen).visibility = View.VISIBLE
|
||||||
|
findViewById<TextView>(R.id.no_connection_screen_message).text = message
|
||||||
Log.e(TAG, "Unable to load logbook: ${e.toString()} . Created a new one.")
|
|
||||||
logbook = Logbook()
|
|
||||||
showLogbook()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +272,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onIOError(error: IOException) {
|
override fun onIOError(error: IOException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_network_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -287,20 +280,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onWebDAVError(error: SardineException) {
|
override fun onWebDAVError(error: SardineException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
if(error.toString().contains("401")) {
|
onRepoError(
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_webdav_error_denied), Toast.LENGTH_SHORT).show()
|
if(error.toString().contains("401")) {
|
||||||
onAddError(event, error.toString())
|
getString(R.string.settings_webdav_error_denied)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_webdav_error_generic) + error.toString(), Toast.LENGTH_SHORT).show()
|
getString(R.string.settings_webdav_error_generic) + error.toString()
|
||||||
onAddError(event, error.toString())
|
}
|
||||||
}
|
)
|
||||||
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onJSONError(error: JSONException) {
|
override fun onJSONError(error: JSONException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_json_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -308,7 +302,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onError(error: Exception) {
|
override fun onError(error: Exception) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
Toast.makeText(this@MainActivity, getString(R.string.settings_generic_error) + error.toString(), Toast.LENGTH_SHORT).show()
|
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -316,7 +310,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onAddError(event: LunaEvent, error: String) {
|
private fun onAddError(event: LunaEvent, error: String) {
|
||||||
Log.e(TAG, "Logbook was NOT saved!")
|
Log.e(TAG, "Logbook was NOT saved! $error")
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@ class FileLogbookRepository: LogbookRepository {
|
|||||||
try {
|
try {
|
||||||
listener.onLogbookLoaded(loadLogbook(context))
|
listener.onLogbookLoaded(loadLogbook(context))
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
Log.d(TAG, "No logbook file found")
|
Log.d(TAG, "No logbook file found, will be created at first save")
|
||||||
listener.onIOError(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +191,7 @@
|
|||||||
android:text="@string/no_connection"/>
|
android:text="@string/no_connection"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/no_connection_screen_message"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
|
Loading…
Reference in New Issue
Block a user