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:
Joe Groocock 2024-04-30 15:08:04 +01:00 committed by GitHub
parent c690b38b0f
commit 06a519ef98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 18 additions and 12 deletions

1
changelog.d/2771.feature Normal file
View file

@ -0,0 +1 @@
Pretty-print event JSON in debug viewer

View file

@ -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,

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6b5fe193d680293c89c5faad9e74e4f887d1202f2f58ba9e145529c9d3a21fab
size 10022

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:80ee405fc93dfc1074e840a078b71d270058e75d7913ceeefe7883698ff8134c
size 9869

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c94e99fe54698aa18a4a3ee30bb193362b12fb0c623f3e504353cc178bfdec58
size 34906
oid sha256:8c593dbd3d2a92933748bebe3f4e28ca3ec225777b48bd3838e6bf0b3773eae3
size 35489

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bb484133292d510161f8b8d9e1c67325394bb837f85f37b8ac5b91e4a60d69fa
size 32838
oid sha256:556a71042cfb952822072718d394de7236a4eee709b4a91133471567d79a19ae
size 33718