From ab1a06c8893c996dd9858af87bc121b0bfc8c69a Mon Sep 17 00:00:00 2001 From: SuLG-k Date: Mon, 11 Mar 2024 01:24:49 +0700 Subject: [PATCH] run spotlessKotlinCheckApply to pass spotless check --- .../ui/camera/PeekabooCamera.android.kt | 57 ++++++++++--------- .../ui/camera/PeekabooCameraState.android.kt | 19 +++++-- .../preat/peekaboo/ui/camera/CameraMode.kt | 3 +- .../peekaboo/ui/camera/PeekabooCameraState.kt | 21 +++++-- .../peekaboo/ui/camera/PeekabooCamera.ios.kt | 51 +++++++++-------- .../ui/camera/PeekabooCameraState.ios.kt | 19 +++++-- .../common/component/PeekabooCameraView.kt | 32 +++++------ 7 files changed, 119 insertions(+), 83 deletions(-) diff --git a/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.android.kt b/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.android.kt index 22877ae..ade1d73 100644 --- a/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.android.kt +++ b/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.android.kt @@ -87,8 +87,9 @@ private fun CompatOverlay( Box { captureIcon(state::capture) convertIcon(state::toggleCamera) - if (state.isCapturing) + if (state.isCapturing) { progressIndicator() + } } } @@ -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 { @@ -153,17 +156,18 @@ private fun CameraWithGrantedPermission( } LaunchedEffect(state.cameraMode) { - cameraProvider = suspendCoroutine { continuation -> - ProcessCameraProvider.getInstance(context).also { cameraProvider -> - cameraProvider.addListener( - { - continuation.resume(cameraProvider.get()) - state.onCameraReady() - }, - executor, - ) + cameraProvider = + suspendCoroutine { continuation -> + ProcessCameraProvider.getInstance(context).also { cameraProvider -> + cameraProvider.addListener( + { + continuation.resume(cameraProvider.get()) + state.onCameraReady() + }, + executor, + ) + } } - } cameraProvider?.unbindAll() cameraProvider?.bindToLifecycle( lifecycleOwner, @@ -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() diff --git a/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.android.kt b/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.android.kt index 2e0a694..6d8d8c0 100644 --- a/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.android.kt +++ b/peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.android.kt @@ -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 @@ -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) @@ -45,7 +58,6 @@ actual class PeekabooCameraState( } companion object { - fun saver(onCapture: (ByteArray?) -> Unit): Saver { return Saver( save = { @@ -60,7 +72,6 @@ actual class PeekabooCameraState( ) } } - } @Composable diff --git a/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/CameraMode.kt b/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/CameraMode.kt index 85d3512..a8a0738 100644 --- a/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/CameraMode.kt +++ b/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/CameraMode.kt @@ -35,7 +35,6 @@ sealed class CameraMode { data object Back : CameraMode() } - internal fun CameraMode.inverse(): CameraMode { return when (this) { CameraMode.Back -> CameraMode.Front @@ -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") } } diff --git a/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.kt b/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.kt index 4501f0a..7386c67 100644 --- a/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.kt +++ b/peekaboo-ui/src/commonMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.kt @@ -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] @@ -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 @@ -37,5 +47,4 @@ expect class PeekabooCameraState { fun toggleCamera() fun capture() - } diff --git a/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.ios.kt b/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.ios.kt index d55e44e..e6d0569 100644 --- a/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.ios.kt +++ b/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCamera.ios.kt @@ -139,9 +139,9 @@ actual fun PeekabooCamera( } Box( modifier = - modifier - .fillMaxSize() - .background(Color.Black), + modifier + .fillMaxSize() + .background(Color.Black), contentAlignment = Alignment.Center, ) { when (cameraAccess) { @@ -202,8 +202,9 @@ private fun CompatOverlay( Box { captureIcon(state::capture) convertIcon(state::toggleCamera) - if (state.isCapturing) + if (state.isCapturing) { progressIndicator() + } } } @@ -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 } @@ -248,9 +249,9 @@ private fun BoxScope.AuthorizedCamera( if (!cameraReady) { Box( modifier = - Modifier - .fillMaxSize() - .background(Color.Black), + Modifier + .fillMaxSize() + .background(Color.Black), ) } } @@ -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 } @@ -288,9 +290,9 @@ private fun AuthorizedCamera( if (!state.isCameraReady) { Box( modifier = - Modifier - .fillMaxSize() - .background(Color.Black), + Modifier + .fillMaxSize() + .background(Color.Black), ) } } @@ -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, ) @@ -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, ) @@ -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, diff --git a/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.ios.kt b/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.ios.kt index 64819bc..bb8cceb 100644 --- a/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.ios.kt +++ b/peekaboo-ui/src/iosMain/kotlin/com/preat/peekaboo/ui/camera/PeekabooCameraState.ios.kt @@ -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 @@ -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 @@ -27,7 +41,6 @@ actual class PeekabooCameraState( } actual fun capture() { - } internal fun stopCapturing() { @@ -43,7 +56,6 @@ actual class PeekabooCameraState( } companion object { - fun saver(onCapture: (ByteArray?) -> Unit): Saver { return Saver( save = { @@ -58,7 +70,6 @@ actual class PeekabooCameraState( ) } } - } @Composable diff --git a/sample/common/src/commonMain/kotlin/com/preat/peekaboo/common/component/PeekabooCameraView.kt b/sample/common/src/commonMain/kotlin/com/preat/peekaboo/common/component/PeekabooCameraView.kt index 2b3b1df..dd8a9ec 100644 --- a/sample/common/src/commonMain/kotlin/com/preat/peekaboo/common/component/PeekabooCameraView.kt +++ b/sample/common/src/commonMain/kotlin/com/preat/peekaboo/common/component/PeekabooCameraView.kt @@ -69,9 +69,7 @@ internal fun PeekabooCameraView( } @Composable -fun PermissionDenied( - modifier: Modifier = Modifier, -) { +fun PermissionDenied(modifier: Modifier = Modifier) { Column( modifier = modifier.background(color = MaterialTheme.colors.background), horizontalAlignment = Alignment.CenterHorizontally, @@ -104,9 +102,10 @@ private fun CameraOverlay( ) { IconButton( onClick = onBack, - modifier = Modifier - .align(Alignment.TopStart) - .padding(top = 16.dp, start = 16.dp), + modifier = + Modifier + .align(Alignment.TopStart) + .padding(top = 16.dp, start = 16.dp), ) { Icon( imageVector = IconClose, @@ -114,28 +113,29 @@ private fun CameraOverlay( tint = Color.White, ) } - if (isCapturing) + if (isCapturing) { CircularProgressIndicator( modifier = - Modifier - .size(80.dp) - .align(Alignment.Center), + Modifier + .size(80.dp) + .align(Alignment.Center), color = Color.White.copy(alpha = 0.7f), strokeWidth = 8.dp, ) + } CircularButton( imageVector = IconCached, modifier = - Modifier - .align(Alignment.BottomEnd) - .padding(bottom = 16.dp, end = 16.dp), + Modifier + .align(Alignment.BottomEnd) + .padding(bottom = 16.dp, end = 16.dp), onClick = onConvert, ) InstagramCameraButton( modifier = - Modifier - .align(Alignment.BottomCenter) - .padding(bottom = 16.dp), + Modifier + .align(Alignment.BottomCenter) + .padding(bottom = 16.dp), onClick = onCapture, ) }