Displaying stacks in error messages if they are present
This commit is contained in:
@@ -33,11 +33,41 @@ import androidx.compose.material3.ButtonDefaults
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size16dp
|
import com.vitorpamplona.amethyst.ui.theme.Size16dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||||
|
import java.io.PrintWriter
|
||||||
|
import java.io.StringWriter
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InformationDialog(
|
||||||
|
title: String,
|
||||||
|
textContent: String?,
|
||||||
|
throwable: Throwable,
|
||||||
|
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
val stack = stringRes(id = R.string.stack)
|
||||||
|
val str =
|
||||||
|
remember(throwable) {
|
||||||
|
val writer = StringWriter()
|
||||||
|
textContent?.let {
|
||||||
|
writer.append(it)
|
||||||
|
writer.append("\n\n")
|
||||||
|
}
|
||||||
|
writer.append(stack)
|
||||||
|
writer.append("\n")
|
||||||
|
|
||||||
|
throwable.printStackTrace(PrintWriter(writer))
|
||||||
|
|
||||||
|
writer.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
InformationDialog(title = title, textContent = str, buttonColors, onDismiss)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun InformationDialog(
|
fun InformationDialog(
|
||||||
@@ -49,7 +79,11 @@ fun InformationDialog(
|
|||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
title = { Text(title) },
|
title = { Text(title) },
|
||||||
text = { SelectionContainer { Text(textContent) } },
|
text = {
|
||||||
|
SelectionContainer {
|
||||||
|
Text(textContent)
|
||||||
|
}
|
||||||
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(
|
Button(
|
||||||
onClick = onDismiss,
|
onClick = onDismiss,
|
||||||
|
|||||||
@@ -429,6 +429,15 @@ private fun DisplayErrorMessages(accountViewModel: AccountViewModel) {
|
|||||||
) {
|
) {
|
||||||
accountViewModel.clearToasts()
|
accountViewModel.clearToasts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is ThrowableToastMsg ->
|
||||||
|
InformationDialog(
|
||||||
|
stringRes(obj.titleResId),
|
||||||
|
obj.msg,
|
||||||
|
obj.throwable,
|
||||||
|
) {
|
||||||
|
accountViewModel.clearToasts()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -957,5 +957,6 @@
|
|||||||
<string name="add_a_nip96_server">Add a NIP-96 Server</string>
|
<string name="add_a_nip96_server">Add a NIP-96 Server</string>
|
||||||
<string name="delete_all">Delete all</string>
|
<string name="delete_all">Delete all</string>
|
||||||
<string name="delete_all_drafts_confirmation">Are you sure you want to delete all drafts?</string>
|
<string name="delete_all_drafts_confirmation">Are you sure you want to delete all drafts?</string>
|
||||||
<string name="and_more">" ... and %1$s more"</string>
|
<string name="and_more">" … and %1$s more"</string>
|
||||||
|
<string name="stack">Stack:</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user