mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Add a copy button to the SQLite Playground.
This commit is contained in:
@@ -53,6 +53,7 @@ import org.signal.libsignal.protocol.util.Hex
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.settings.app.internal.sqlite.InternalSqlitePlaygroundViewModel.QueryResult
|
||||
import org.thoughtcrime.securesms.compose.ComposeFragment
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
|
||||
class InternalSqlitePlaygroundFragment : ComposeFragment() {
|
||||
|
||||
@@ -130,12 +131,18 @@ private fun QueryBox(onQuerySubmitted: (String) -> Unit = {}) {
|
||||
private fun QueryResults(results: QueryResult?) {
|
||||
val columnWidth = LocalConfiguration.current.screenWidthDp.dp / 2
|
||||
val horizontalScrollState = rememberScrollState()
|
||||
val context = LocalContext.current
|
||||
|
||||
if (results == null) {
|
||||
Text("Waiting on query results.")
|
||||
return
|
||||
}
|
||||
Text("${results.rows.size} rows in ${results.totalTimeString} ms", modifier = Modifier.padding(4.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("${results.rows.size} rows in ${results.totalTimeString} ms", modifier = Modifier.padding(4.dp).weight(1f))
|
||||
Buttons.Small(onClick = { Util.copyToClipboard(context, results.toCopyString()) }) {
|
||||
Text("Copy results")
|
||||
}
|
||||
}
|
||||
QueryRow(data = results.columns, columnWidth = columnWidth, scrollState = horizontalScrollState, fontWeight = FontWeight.Bold)
|
||||
|
||||
LazyColumn {
|
||||
@@ -180,6 +187,22 @@ private fun Any?.toDisplayString(): String {
|
||||
}
|
||||
}
|
||||
|
||||
private fun QueryResult.toCopyString(): String {
|
||||
val builder = StringBuilder()
|
||||
|
||||
builder.append(this.columns.toCsv()).append("\n")
|
||||
|
||||
for (row in this.rows) {
|
||||
builder.append(row.toCsv()).append("\n")
|
||||
}
|
||||
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
private fun List<Any?>.toCsv(): String {
|
||||
return this.joinToString(separator = ", ", transform = { it.toDisplayString() })
|
||||
}
|
||||
|
||||
@SignalPreview
|
||||
@Composable
|
||||
private fun ScreenPreview() {
|
||||
|
||||
Reference in New Issue
Block a user