Skip to content

Commit

Permalink
run spotlessKotlinCheckApply to pass spotless check
Browse files Browse the repository at this point in the history
  • Loading branch information
SuLG-ik committed Mar 10, 2024
1 parent f4c1fd5 commit ab1a06c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ private fun CompatOverlay(
Box {
captureIcon(state::capture)
convertIcon(state::toggleCamera)
if (state.isCapturing)
if (state.isCapturing) {
progressIndicator()
}
}
}

Expand Down Expand Up @@ -134,17 +135,19 @@ private fun CameraWithGrantedPermission(
val preview = Preview.Builder().build()
val previewView = remember { PreviewView(context) }
val imageCapture: ImageCapture = remember { ImageCapture.Builder().build() }
val cameraSelector = remember(state.cameraMode) {
val lensFacing = when (state.cameraMode) {
CameraMode.Front -> {
CameraSelector.LENS_FACING_FRONT
}
CameraMode.Back -> {
CameraSelector.LENS_FACING_BACK
}
val cameraSelector =
remember(state.cameraMode) {
val lensFacing =
when (state.cameraMode) {
CameraMode.Front -> {
CameraSelector.LENS_FACING_FRONT
}
CameraMode.Back -> {
CameraSelector.LENS_FACING_BACK
}
}
CameraSelector.Builder().requireLensFacing(lensFacing).build()
}
CameraSelector.Builder().requireLensFacing(lensFacing).build()
}

DisposableEffect(Unit) {
onDispose {
Expand All @@ -153,17 +156,18 @@ private fun CameraWithGrantedPermission(
}

LaunchedEffect(state.cameraMode) {
cameraProvider = suspendCoroutine<ProcessCameraProvider> { continuation ->
ProcessCameraProvider.getInstance(context).also { cameraProvider ->
cameraProvider.addListener(
{
continuation.resume(cameraProvider.get())
state.onCameraReady()
},
executor,
)
cameraProvider =
suspendCoroutine<ProcessCameraProvider> { continuation ->
ProcessCameraProvider.getInstance(context).also { cameraProvider ->
cameraProvider.addListener(
{
continuation.resume(cameraProvider.get())
state.onCameraReady()
},
executor,
)
}
}
}
cameraProvider?.unbindAll()
cameraProvider?.bindToLifecycle(
lifecycleOwner,
Expand Down Expand Up @@ -205,11 +209,12 @@ class ImageCaptureCallback(
val data = buffer.toByteArray()

// Rotate the image if necessary
val rotatedData = if (rotationDegrees != 0) {
rotateImage(data, rotationDegrees)
} else {
data
}
val rotatedData =
if (rotationDegrees != 0) {
rotateImage(data, rotationDegrees)
} else {
data
}
image.close()
onCapture(rotatedData)
stopCapturing()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 onseok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.preat.peekaboo.ui.camera

import androidx.compose.runtime.Composable
Expand All @@ -13,8 +28,6 @@ actual class PeekabooCameraState(
cameraMode: CameraMode,
private val onCapture: (ByteArray?) -> Unit,
) {


actual var isCameraReady: Boolean by mutableStateOf(false)

actual var isCapturing: Boolean by mutableStateOf(false)
Expand Down Expand Up @@ -45,7 +58,6 @@ actual class PeekabooCameraState(
}

companion object {

fun saver(onCapture: (ByteArray?) -> Unit): Saver<PeekabooCameraState, Int> {
return Saver(
save = {
Expand All @@ -60,7 +72,6 @@ actual class PeekabooCameraState(
)
}
}

}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ sealed class CameraMode {
data object Back : CameraMode()
}


internal fun CameraMode.inverse(): CameraMode {
return when (this) {
CameraMode.Back -> CameraMode.Front
Expand All @@ -54,6 +53,6 @@ internal fun cameraModeFromId(id: Int): CameraMode {
return when (id) {
0 -> CameraMode.Back
1 -> CameraMode.Front
else -> throw IllegalArgumentException("CameraMode with id=${id} does not exists")
else -> throw IllegalArgumentException("CameraMode with id=$id does not exists")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/*
* Copyright 2024 onseok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.preat.peekaboo.ui.camera

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.Saver


/**
* Create and [remember] a [PeekabooCameraState]
Expand All @@ -18,13 +30,11 @@ expect fun rememberPeekabooCameraState(
onCapture: (ByteArray?) -> Unit,
): PeekabooCameraState


/**
* State of [PeekabooCamera]. Contains states relating to camera control.
*/
@Stable
expect class PeekabooCameraState {

var isCameraReady: Boolean
internal set

Expand All @@ -37,5 +47,4 @@ expect class PeekabooCameraState {
fun toggleCamera()

fun capture()

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ actual fun PeekabooCamera(
}
Box(
modifier =
modifier
.fillMaxSize()
.background(Color.Black),
modifier
.fillMaxSize()
.background(Color.Black),
contentAlignment = Alignment.Center,
) {
when (cameraAccess) {
Expand Down Expand Up @@ -202,8 +202,9 @@ private fun CompatOverlay(
Box {
captureIcon(state::capture)
convertIcon(state::toggleCamera)
if (state.isCapturing)
if (state.isCapturing) {
progressIndicator()
}
}
}

Expand All @@ -222,10 +223,10 @@ private fun BoxScope.AuthorizedCamera(
deviceTypes = deviceTypes,
mediaType = AVMediaTypeVideo,
position =
when (cameraMode) {
CameraMode.Front -> AVCaptureDevicePositionFront
CameraMode.Back -> AVCaptureDevicePositionBack
},
when (cameraMode) {
CameraMode.Front -> AVCaptureDevicePositionFront
CameraMode.Back -> AVCaptureDevicePositionBack
},
).devices.firstOrNull() as? AVCaptureDevice
}

Expand All @@ -248,9 +249,9 @@ private fun BoxScope.AuthorizedCamera(
if (!cameraReady) {
Box(
modifier =
Modifier
.fillMaxSize()
.background(Color.Black),
Modifier
.fillMaxSize()
.background(Color.Black),
)
}
}
Expand All @@ -265,10 +266,11 @@ private fun AuthorizedCamera(
discoverySessionWithDeviceTypes(
deviceTypes = deviceTypes,
mediaType = AVMediaTypeVideo,
position = when (state.cameraMode) {
CameraMode.Front -> AVCaptureDevicePositionFront
CameraMode.Back -> AVCaptureDevicePositionBack
},
position =
when (state.cameraMode) {
CameraMode.Front -> AVCaptureDevicePositionFront
CameraMode.Back -> AVCaptureDevicePositionBack
},
).devices.firstOrNull() as? AVCaptureDevice
}

Expand All @@ -288,9 +290,9 @@ private fun AuthorizedCamera(
if (!state.isCameraReady) {
Box(
modifier =
Modifier
.fillMaxSize()
.background(Color.Black),
Modifier
.fillMaxSize()
.background(Color.Black),
)
}
}
Expand Down Expand Up @@ -457,9 +459,9 @@ private fun BoxScope.RealDeviceCamera(
NSNotificationCenter.defaultCenter.addObserver(
observer = listener,
selector =
NSSelectorFromString(
OrientationListener::orientationDidChange.name + ":",
),
NSSelectorFromString(
OrientationListener::orientationDidChange.name + ":",
),
name = notificationName,
`object` = null,
)
Expand Down Expand Up @@ -599,9 +601,9 @@ private fun RealDeviceCamera(
NSNotificationCenter.defaultCenter.addObserver(
observer = listener,
selector =
NSSelectorFromString(
OrientationListener::orientationDidChange.name + ":",
),
NSSelectorFromString(
OrientationListener::orientationDidChange.name + ":",
),
name = notificationName,
`object` = null,
)
Expand Down Expand Up @@ -685,7 +687,6 @@ class PhotoCaptureDelegate(
private val onCaptureEnd: () -> Unit,
private val onCapture: (byteArray: ByteArray?) -> Unit,
) : NSObject(), AVCapturePhotoCaptureDelegateProtocol {

@OptIn(ExperimentalForeignApi::class)
override fun captureOutput(
output: AVCapturePhotoOutput,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 onseok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.preat.peekaboo.ui.camera

import androidx.compose.runtime.Composable
Expand All @@ -13,7 +28,6 @@ actual class PeekabooCameraState(
cameraMode: CameraMode,
private val onCapture: (ByteArray?) -> Unit,
) {

actual var isCameraReady: Boolean by mutableStateOf(false)

internal var triggerCaptureAnchor: (() -> Unit)? = null
Expand All @@ -27,7 +41,6 @@ actual class PeekabooCameraState(
}

actual fun capture() {

}

internal fun stopCapturing() {
Expand All @@ -43,7 +56,6 @@ actual class PeekabooCameraState(
}

companion object {

fun saver(onCapture: (ByteArray?) -> Unit): Saver<PeekabooCameraState, Int> {
return Saver(
save = {
Expand All @@ -58,7 +70,6 @@ actual class PeekabooCameraState(
)
}
}

}

@Composable
Expand Down
Loading

0 comments on commit ab1a06c

Please sign in to comment.