Skip to content

Commit 673d709

Browse files
committed
response copying now is available
1 parent 9ed5f67 commit 673d709

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdk 21
1212
targetSdk 33
1313
versionCode 1
14-
versionName "0.2.1"
14+
versionName "0.2.2"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
vectorDrawables {
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package com.avocat.http_wizard.ui.bottomsheet
22

3+
import android.widget.Toast
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.layout.padding
37
import androidx.compose.foundation.lazy.LazyColumn
4-
import androidx.compose.material.Text
8+
import androidx.compose.material.*
9+
import androidx.compose.material.icons.Icons
10+
import androidx.compose.material.icons.outlined.ContentCopy
511
import androidx.compose.runtime.Composable
612
import androidx.compose.runtime.MutableState
713
import androidx.compose.runtime.mutableStateOf
814
import com.fasterxml.jackson.databind.ObjectMapper
915
import androidx.compose.runtime.remember
16+
import androidx.compose.ui.Alignment
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.platform.LocalClipboardManager
19+
import androidx.compose.ui.platform.LocalContext
20+
import androidx.compose.ui.text.AnnotatedString
21+
import androidx.compose.ui.unit.dp
1022
import okhttp3.Response
1123

1224

@@ -15,11 +27,36 @@ fun Response(res: MutableState<Response?>) {
1527
val body = remember { mutableStateOf(res.value?.body) }
1628
val data = remember { mutableStateOf(body.value!!.string()) }
1729

30+
val clipboardManager = LocalClipboardManager.current
31+
val ctx = LocalContext.current
32+
1833
val prettyJsonString = ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data)
1934

2035
LazyColumn {
2136
item {
2237
Text(prettyJsonString)
2338
}
2439
}
40+
41+
Box(
42+
contentAlignment = Alignment.BottomEnd,
43+
modifier = Modifier
44+
.padding(8.dp)
45+
.fillMaxSize()
46+
) {
47+
Surface(
48+
color = MaterialTheme.colors.background,
49+
shape = MaterialTheme.shapes.small,
50+
) {
51+
IconButton(
52+
onClick = {
53+
clipboardManager.setText(AnnotatedString(prettyJsonString))
54+
Toast.makeText(ctx, "Response was copied", Toast.LENGTH_SHORT).show()
55+
},
56+
modifier = Modifier.padding(2.dp)
57+
) {
58+
Icon(Icons.Outlined.ContentCopy, null)
59+
}
60+
}
61+
}
2562
}

0 commit comments

Comments
 (0)