Pretty-print event JSON in debug view (#2771)
* Pretty-print event JSON in debug view Significantly improves readability Signed-off-by: Joe Groocock <me@frebib.net> * Update screenshots Signed-off-by: Joe Groocock <me@frebib.net> --------- Signed-off-by: Joe Groocock <me@frebib.net> Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
1
changelog.d/2771.feature
Normal file
1
changelog.d/2771.feature
Normal file
@@ -0,0 +1 @@
|
||||
Pretty-print event JSON in debug viewer
|
||||
@@ -59,6 +59,8 @@ import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* Screen used to display debug info for events.
|
||||
@@ -109,18 +111,27 @@ fun EventDebugInfoView(
|
||||
}
|
||||
if (originalJson != null) {
|
||||
item {
|
||||
CollapsibleSection(title = "Original JSON:", text = originalJson, initiallyExpanded = sectionsInitiallyExpanded)
|
||||
CollapsibleSection(title = "Original JSON:", text = prettyJSON(originalJson), initiallyExpanded = sectionsInitiallyExpanded)
|
||||
}
|
||||
}
|
||||
if (latestEditedJson != null) {
|
||||
item {
|
||||
CollapsibleSection(title = "Latest edited JSON:", text = latestEditedJson, initiallyExpanded = sectionsInitiallyExpanded)
|
||||
CollapsibleSection(title = "Latest edited JSON:", text = prettyJSON(latestEditedJson), initiallyExpanded = sectionsInitiallyExpanded)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun prettyJSON(maybeJSON: String): String {
|
||||
return try {
|
||||
JSONObject(maybeJSON).toString(2)
|
||||
} catch (e: JSONException) {
|
||||
// Prefer not pretty-printing over crashing if the data is not actually JSON
|
||||
maybeJSON
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CollapsibleSection(
|
||||
title: String,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user