forked from github/wulkanowy-mirror
Error messages content wrap in error dialog (#1577)
This commit is contained in:
parent
26c749c219
commit
8ed8b5a33c
@ -11,6 +11,7 @@ import android.widget.Toast
|
|||||||
import android.widget.Toast.LENGTH_LONG
|
import android.widget.Toast.LENGTH_LONG
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
|
import androidx.core.view.isGone
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.databinding.DialogErrorBinding
|
import io.github.wulkanowy.databinding.DialogErrorBinding
|
||||||
@ -24,8 +25,6 @@ import io.github.wulkanowy.utils.openEmailClient
|
|||||||
import io.github.wulkanowy.utils.openInternetBrowser
|
import io.github.wulkanowy.utils.openInternetBrowser
|
||||||
import okhttp3.internal.http2.StreamResetException
|
import okhttp3.internal.http2.StreamResetException
|
||||||
import java.io.InterruptedIOException
|
import java.io.InterruptedIOException
|
||||||
import java.io.PrintWriter
|
|
||||||
import java.io.StringWriter
|
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
@ -64,26 +63,26 @@ class ErrorDialog : BaseDialogFragment<DialogErrorBinding>() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val stringWriter = StringWriter().apply {
|
val errorStacktrace = error.stackTraceToString()
|
||||||
error.printStackTrace(PrintWriter(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
with(binding) {
|
with(binding) {
|
||||||
errorDialogContent.text = stringWriter.toString()
|
errorDialogContent.text = errorStacktrace.replace(": ${error.localizedMessage}", "")
|
||||||
with(errorDialogHorizontalScroll) {
|
with(errorDialogHorizontalScroll) {
|
||||||
post { fullScroll(HorizontalScrollView.FOCUS_LEFT) }
|
post { fullScroll(HorizontalScrollView.FOCUS_LEFT) }
|
||||||
}
|
}
|
||||||
errorDialogCopy.setOnClickListener {
|
errorDialogCopy.setOnClickListener {
|
||||||
val clip = ClipData.newPlainText("wulkanowy", stringWriter.toString())
|
val clip = ClipData.newPlainText("Error details", errorStacktrace)
|
||||||
activity?.getSystemService<ClipboardManager>()?.setPrimaryClip(clip)
|
activity?.getSystemService<ClipboardManager>()?.setPrimaryClip(clip)
|
||||||
|
|
||||||
Toast.makeText(context, R.string.all_copied, LENGTH_LONG).show()
|
Toast.makeText(context, R.string.all_copied, LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
errorDialogCancel.setOnClickListener { dismiss() }
|
errorDialogCancel.setOnClickListener { dismiss() }
|
||||||
errorDialogReport.setOnClickListener {
|
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) {
|
errorDialogReport.isEnabled = when (error) {
|
||||||
is UnknownHostException,
|
is UnknownHostException,
|
||||||
is InterruptedIOException,
|
is InterruptedIOException,
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minWidth="300dp"
|
android:minWidth="300dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
tools:context=".ui.base.ErrorDialog">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -16,7 +17,7 @@
|
|||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/errorDialogMessage"
|
android:id="@+id/errorDialogHumanizedMessage"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="20dp"
|
android:paddingHorizontal="20dp"
|
||||||
@ -24,6 +25,16 @@
|
|||||||
android:textSize="21sp"
|
android:textSize="21sp"
|
||||||
tools:text="@tools:sample/lorem" />
|
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
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
@ -51,6 +62,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
|
android:textColor="?android:textColorTertiary"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user