Skip to content

Commit f8c974d

Browse files
authored
[patch] make RoundTripDetailView scrollable (#3)
Wraps in a lazycolumn with items so that it is scrollable. On large payloads you couldnt see the whole thing which is annyoing Additionally, pretty prints the json so that it is easier to read
1 parent 4e3769c commit f8c974d

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

app/src/main/java/io/branch/branchlinksimulator/RoundTripStore.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.content.SharedPreferences
55
import io.branch.interfaces.IBranchLoggingCallbacks
66
import kotlinx.coroutines.CoroutineScope
77
import kotlinx.coroutines.Dispatchers
8-
import kotlinx.coroutines.GlobalScope
8+
import kotlinx.serialization.json.*
99
import kotlinx.coroutines.SupervisorJob
1010
import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.flow.StateFlow
@@ -25,6 +25,8 @@ class RoundTripStore(context: Context) : IBranchLoggingCallbacks {
2525

2626
private val FAILED = "failed to parse"
2727

28+
private val json = Json { prettyPrint = true }
29+
2830
override fun onBranchLog(logMessage: String?, severityConstantName: String?) {
2931
scope.launch(Dispatchers.Main) {
3032
processLog(logMessage)
@@ -89,10 +91,15 @@ class RoundTripStore(context: Context) : IBranchLoggingCallbacks {
8991
return regex.find(log)?.value
9092
}
9193

94+
private fun String.prettyPrint(): String {
95+
val jsonElement = json.parseToJsonElement(this)
96+
return json.encodeToString(jsonElement)
97+
}
98+
9299
private fun parseBody(log: String, identifier: String): String? {
93100
val bodyStart = log.indexOf(identifier).takeIf { it != -1 }?.let { it + identifier.length }
94101
return bodyStart?.let {
95-
log.substring(it).trim()
102+
log.substring(it).trim().prettyPrint()
96103
}
97104
}
98105

app/src/main/java/io/branch/branchlinksimulator/RoundTripsView.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,34 @@ fun RoundTripDetailView(roundTrip: RoundTrip) {
9999
.fillMaxSize()
100100
.padding(16.dp)
101101
) {
102-
VariableView(label = "URL", value = roundTrip.url)
103-
Spacer(modifier = Modifier.height(8.dp))
104-
Text("Request", style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
105-
VariableView(label = "Body", value = roundTrip.request?.body ?: "FAILED")
106-
Spacer(modifier = Modifier.height(16.dp))
107-
roundTrip.response?.let {
108-
Text("Response", style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
109-
Text("Status Code: ${it.statusCode}", style = MaterialTheme.typography.titleSmall, color = Color.White)
110-
VariableView(label = "Body", value = it.body)
102+
LazyColumn(
103+
modifier = Modifier
104+
.fillMaxSize()
105+
) {
106+
item {
107+
VariableView(label = "URL", value = roundTrip.url)
108+
}
109+
item {
110+
Spacer(modifier = Modifier.height(8.dp))
111+
}
112+
item {
113+
Text("Request", style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
114+
}
115+
item {
116+
VariableView(label = "Body", value = roundTrip.request?.body ?: "FAILED")
117+
}
118+
item {
119+
Spacer(modifier = Modifier.height(16.dp))
120+
}
121+
item {
122+
roundTrip.response?.let {
123+
Text("Response", style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
124+
Text("Status Code: ${it.statusCode}", style = MaterialTheme.typography.titleSmall, color = Color.White)
125+
VariableView(label = "Body", value = it.body)
126+
}
127+
}
111128
}
129+
112130
}
113131
}
114132

0 commit comments

Comments
 (0)