Error messages content wrap in error dialog
MODIFY
app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt
app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt
@@ -11,6 +11,7 @@ import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import androidx.appcompat.app.AlertDialog
import androidx.core.content.getSystemService
+import androidx.core.view.isGone
import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.R
import io.github.wulkanowy.databinding.DialogErrorBinding
@@ -24,8 +25,6 @@ import io.github.wulkanowy.utils.openEmailClient
import io.github.wulkanowy.utils.openInternetBrowser
import okhttp3.internal.http2.StreamResetException
import java.io.InterruptedIOException
-import java.io.PrintWriter
-import java.io.StringWriter
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
@@ -64,26 +63,26 @@ class ErrorDialog : BaseDialogFragment<DialogErrorBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- val stringWriter = StringWriter().apply {
- error.printStackTrace(PrintWriter(this))
- }
+ val errorStacktrace = error.stackTraceToString()
with(binding) {
- errorDialogContent.text = stringWriter.toString()
+ errorDialogContent.text = errorStacktrace.replace(": ${error.localizedMessage}", "")
with(errorDialogHorizontalScroll) {
post { fullScroll(HorizontalScrollView.FOCUS_LEFT) }
}
errorDialogCopy.setOnClickListener {
- val clip = ClipData.newPlainText("wulkanowy", stringWriter.toString())
+ val clip = ClipData.newPlainText("Error details", errorStacktrace)
activity?.getSystemService<ClipboardManager>()?.setPrimaryClip(clip)
Toast.makeText(context, R.string.all_copied, LENGTH_LONG).show()
}
errorDialogCancel.setOnClickListener { dismiss() }
errorDialogReport.setOnClickListener {
- openConfirmDialog { openEmailClient(stringWriter.toString()) }
+ openConfirmDialog { openEmailClient(errorStacktrace) }
}
- errorDialogMessage.text = resources.getString(error)
+ errorDialogHumanizedMessage.text = resources.getString(error)
+ errorDialogErrorMessage.text = error.localizedMessage
+ errorDialogErrorMessage.isGone = error.localizedMessage.isNullOrBlank()
errorDialogReport.isEnabled = when (error) {
is UnknownHostException,
is InterruptedIOException,

MODIFY
app/src/main/res/layout/dialog_error.xml
app/src/main/res/layout/dialog_error.xml
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="300dp"
- android:orientation="vertical">
+ android:orientation="vertical"
+ tools:context=".ui.base.ErrorDialog">
<TextView
android:layout_width="match_parent"
android:textStyle="bold" />
<TextView
- android:id="@+id/errorDialogMessage"
+ android:id="@+id/errorDialogHumanizedMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="20dp"
android:textSize="21sp"
tools:text="@tools:sample/lorem" />
+ <TextView
+ android:id="@+id/errorDialogErrorMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="5dp"
+ android:paddingHorizontal="20dp"
+ android:paddingTop="10dp"
+ android:textColor="?android:textColorSecondary"
+ tools:text="@tools:sample/lorem" />
+
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
+ android:textColor="?android:textColorTertiary"
android:textIsSelectable="true"
android:textSize="12sp"
tools:text="@tools:sample/lorem/random" />

Error messages content wrap in error dialog (#1577)