Skip to content

Commit 747ed3c

Browse files
committed
Review comments
1 parent 3664222 commit 747ed3c

4 files changed

Lines changed: 27 additions & 36 deletions

File tree

app/src/main/java/de/berlindroid/zepatch/ui/BitmapToStitches.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.ui.graphics.asAndroidBitmap
2929
import androidx.compose.ui.graphics.asImageBitmap
3030
import androidx.compose.ui.platform.LocalContext
3131
import androidx.compose.ui.res.painterResource
32+
import androidx.compose.ui.tooling.preview.Preview
3233
import androidx.core.graphics.scale
3334
import de.berlindroid.zepatch.stiches.StitchToPES
3435
import de.berlindroid.zepatch.stiches.StitchToPES.createEmbroideryFromBitmap
@@ -162,21 +163,10 @@ private fun savePesAfterSelection(context: Context, result: ActivityResult, byte
162163
}
163164
}
164165

165-
//@Preview(showBackground = true)
166-
//@Composable
167-
//private fun BitmapToStitchesPreview() {
168-
// BitmapToStitches(Modifier, "Demo") {
169-
// Box(
170-
// modifier = Modifier
171-
// .fillMaxWidth()
172-
// .background(Color.Blue)
173-
// ) {
174-
// Text(
175-
// "Preview Content",
176-
// modifier = Modifier.padding(16.dp),
177-
// color = Color.White
178-
// )
179-
// }
180-
// }
181-
//}
166+
@Preview
167+
@Composable
168+
fun BitmapToStitchesPreview() {
169+
val imageBitmap = ImageBitmap(width = 100, height = 100) // Replace with a real ImageBitmap if needed
170+
BitmapToStitches(reducedImageBitmap = imageBitmap, name = "MyPatch")
171+
}
182172

app/src/main/java/de/berlindroid/zepatch/ui/PatchableToBitmap.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ fun PatchableToBitmap(
2626
patchable: @Composable () -> Unit,
2727
) {
2828
var image by remember { mutableStateOf<ImageBitmap?>(null) }
29-
var capture by remember { mutableStateOf(false) }
29+
var shouldCapture by remember { mutableStateOf(false) }
3030

3131
Column(modifier = modifier.fillMaxWidth()) {
3232
Button(onClick = {
3333
image = null
34-
capture = true
34+
shouldCapture = true
3535
}) { Text("Do it") }
3636
// Compose the content through the composable utility; it will invoke the callback when ready.
3737
CaptureToBitmap(
3838
modifier = Modifier.fillMaxWidth(),
39-
capture = capture,
39+
shouldCapture = shouldCapture,
4040
onBitmap = { img ->
4141
image = img
42-
capture = false
42+
shouldCapture = false
4343
},
4444
content = patchable
4545
)

app/src/main/java/de/berlindroid/zepatch/ui/PatchableToReducedBitmap.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.ui.text.input.ImeAction
2323
import androidx.compose.ui.text.input.KeyboardType
2424
import androidx.core.graphics.scale
2525
import androidx.core.text.isDigitsOnly
26+
import androidx.compose.ui.tooling.preview.Preview
2627
import com.embroidermodder.punching.reduceColors
2728
import kotlinx.coroutines.launch
2829

@@ -88,10 +89,15 @@ fun PatchableToReducedBitmap(
8889
}
8990
}
9091

92+
@Preview
93+
@Composable
94+
fun PatchableToReducedBitmapPreview() {
95+
PatchableToReducedBitmap(
96+
image = ImageBitmap(width = 100, height = 100), // Example ImageBitmap
97+
colorCount = 5,
98+
onReducedBitmap = {},
99+
onColorCountChanged = {}
100+
)
101+
}
102+
91103

92-
//@Preview(showBackground = true)
93-
//@Composable
94-
//private fun PatchableToReducedBitmapPreview() {
95-
// PatchableToReducedBitmap()
96-
//
97-
//}

app/src/main/java/de/berlindroid/zepatch/utils/CaptureToBitmap.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package de.berlindroid.zepatch.utils
22

33
import androidx.compose.foundation.background
4-
import androidx.compose.foundation.clickable
54
import androidx.compose.foundation.layout.Box
65
import androidx.compose.runtime.Composable
76
import androidx.compose.runtime.LaunchedEffect
8-
import androidx.compose.runtime.getValue
9-
import androidx.compose.runtime.mutableStateOf
10-
import androidx.compose.runtime.remember
117
import androidx.compose.runtime.rememberCoroutineScope
12-
import androidx.compose.runtime.setValue
138
import androidx.compose.ui.Modifier
149
import androidx.compose.ui.draw.drawWithContent
1510
import androidx.compose.ui.graphics.Color
@@ -23,7 +18,7 @@ import kotlinx.coroutines.launch
2318
* from the rendered UI content.
2419
*
2520
* @param modifier A [Modifier] instance to apply to this composable for layout or styling configurations.
26-
* @param capture A flag to trigger the capture process when set to `true`. The content will be converted
21+
* @param shouldCapture A flag to trigger the capture process when set to `true`. The content will be converted
2722
* to a bitmap and passed to the `onBitmap` callback.
2823
* @param onBitmap A callback triggered with the generated [ImageBitmap] once the content has been
2924
* successfully captured.
@@ -33,7 +28,7 @@ import kotlinx.coroutines.launch
3328
@Composable
3429
fun CaptureToBitmap(
3530
modifier: Modifier = Modifier,
36-
capture: Boolean = false,
31+
shouldCapture: Boolean = false,
3732
onBitmap: (ImageBitmap) -> Unit,
3833
content: @Composable () -> Unit,
3934
) {
@@ -49,8 +44,8 @@ fun CaptureToBitmap(
4944
}
5045
.background(Color.Transparent)
5146
) {
52-
LaunchedEffect(capture) {
53-
if (capture) {
47+
LaunchedEffect(shouldCapture) {
48+
if (shouldCapture) {
5449
coroutineScope.launch {
5550
val bitmap = graphicsLayer.toImageBitmap()
5651
onBitmap(bitmap)

0 commit comments

Comments
 (0)