[Errors] Add showing errors details.

This commit is contained in:
Kacper Ziubryniewicz 2019-12-26 23:44:24 +01:00
parent e472d34f4d
commit c65872b29b
3 changed files with 28 additions and 0 deletions

View File

@ -43,6 +43,8 @@ import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
import pl.szczodrzynski.edziennik.utils.models.Time import pl.szczodrzynski.edziennik.utils.models.Time
import pl.szczodrzynski.navlib.getColorFromRes import pl.szczodrzynski.navlib.getColorFromRes
import java.io.PrintWriter
import java.io.StringWriter
import java.math.BigInteger import java.math.BigInteger
import java.security.MessageDigest import java.security.MessageDigest
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -682,3 +684,10 @@ val String.firstLettersName: String
} }
return nameShort return nameShort
} }
val Throwable.stackTraceString: String
get() {
val sw = StringWriter()
printStackTrace(PrintWriter(sw))
return sw.toString()
}

View File

@ -8,9 +8,12 @@ import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.api.models.ApiError import pl.szczodrzynski.edziennik.data.api.models.ApiError
import pl.szczodrzynski.edziennik.stackTraceString
import pl.szczodrzynski.navlib.getColorFromAttr import pl.szczodrzynski.navlib.getColorFromAttr
class ErrorSnackbar(val activity: AppCompatActivity) { class ErrorSnackbar(val activity: AppCompatActivity) {
@ -26,7 +29,22 @@ class ErrorSnackbar(val activity: AppCompatActivity) {
this.coordinator = coordinatorLayout this.coordinator = coordinatorLayout
snackbar = Snackbar.make(coordinator, R.string.snackbar_error_text, Snackbar.LENGTH_INDEFINITE) snackbar = Snackbar.make(coordinator, R.string.snackbar_error_text, Snackbar.LENGTH_INDEFINITE)
snackbar?.setAction(R.string.more) { snackbar?.setAction(R.string.more) {
if (errors.isNotEmpty()) {
val message = errors.map {
if (App.devMode) it.throwable?.stackTraceString
?: it.throwable?.localizedMessage ?: ""
else it.throwable?.localizedMessage
}.joinToString("\n")
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.dialog_error_details_title)
.setMessage(message)
.setPositiveButton(R.string.ok) { dialog, _ ->
errors.clear()
dialog.dismiss()
}
.show()
}
} }
val bgColor = ColorUtils.compositeColors( val bgColor = ColorUtils.compositeColors(
getColorFromAttr(activity, R.attr.colorOnSurface) and 0xcfffffff.toInt(), getColorFromAttr(activity, R.attr.colorOnSurface) and 0xcfffffff.toInt(),

View File

@ -1130,4 +1130,5 @@
<string name="login_edudziennik_title">Zaloguj się - Edudziennik</string> <string name="login_edudziennik_title">Zaloguj się - Edudziennik</string>
<string name="login_edudziennik_subtitle">Użyj danych, którymi logujesz się do wersji komputerowej Edudziennika.</string> <string name="login_edudziennik_subtitle">Użyj danych, którymi logujesz się do wersji komputerowej Edudziennika.</string>
<string name="edziennik_progress_login_edudziennik_web">Logowanie do Edudziennika</string> <string name="edziennik_progress_login_edudziennik_web">Logowanie do Edudziennika</string>
<string name="dialog_error_details_title">Szczegóły błędu</string>
</resources> </resources>