From 649b56a57275fec3d88c819cba8fd94d6ce276f2 Mon Sep 17 00:00:00 2001 From: Tony Dokyoon Kim Date: Sat, 12 Oct 2024 07:51:30 +0900 Subject: [PATCH] hotfix. take photo with external camera [#89] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - external camera 촬영 UseCase 복구 - external camera 촬영 실패 시, preview 화면 캡쳐 사용 --- .../CaptureWithExternalCameraUseCase.kt | 11 +---------- .../presenter/viewmodel/CameraViewModel.kt | 15 ++++++++++----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/domain/src/main/java/com/foke/together/domain/interactor/CaptureWithExternalCameraUseCase.kt b/domain/src/main/java/com/foke/together/domain/interactor/CaptureWithExternalCameraUseCase.kt index 4fc4b81..a9c1e9a 100644 --- a/domain/src/main/java/com/foke/together/domain/interactor/CaptureWithExternalCameraUseCase.kt +++ b/domain/src/main/java/com/foke/together/domain/interactor/CaptureWithExternalCameraUseCase.kt @@ -1,28 +1,19 @@ package com.foke.together.domain.interactor -import android.content.Context import com.foke.together.domain.output.ExternalCameraRepositoryInterface import com.foke.together.domain.output.ImageRepositoryInterface import com.foke.together.util.AppLog -import com.foke.together.util.ImageFileUtil -import com.foke.together.util.TimeUtil -import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject class CaptureWithExternalCameraUseCase @Inject constructor( - @ApplicationContext private val context: Context, private val externalCameraRepository: ExternalCameraRepositoryInterface, private val imageRepository: ImageRepositoryInterface ) { suspend operator fun invoke(fileName: String): Result { externalCameraRepository.capture() .onSuccess { - // TODO: save Bitmap to internal storage AppLog.i(TAG, "capture", "success: $it") - if(it == null) { - return Result.failure(Exception("Bitmap is null")) - } - imageRepository.saveToStorage(it, fileName) + imageRepository.cachingImage(it, fileName) return Result.success(Unit) } .onFailure { diff --git a/presenter/src/main/java/com/foke/together/presenter/viewmodel/CameraViewModel.kt b/presenter/src/main/java/com/foke/together/presenter/viewmodel/CameraViewModel.kt index 898c2c4..b67edda 100644 --- a/presenter/src/main/java/com/foke/together/presenter/viewmodel/CameraViewModel.kt +++ b/presenter/src/main/java/com/foke/together/presenter/viewmodel/CameraViewModel.kt @@ -17,10 +17,8 @@ import com.foke.together.util.AppPolicy import com.foke.together.util.AppPolicy.CAPTURE_INTERVAL import com.foke.together.util.AppPolicy.COUNTDOWN_INTERVAL import com.foke.together.util.SoundUtil -import com.foke.together.util.TimeUtil import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import javax.inject.Inject @@ -28,7 +26,7 @@ import javax.inject.Inject class CameraViewModel @Inject constructor( @ApplicationContext private val context: Context, getExternalCameraPreviewUrlUseCase: GetExternalCameraPreviewUrlUseCase, -// private val captureWithExternalCameraUseCase: CaptureWithExternalCameraUseCase, + private val captureWithExternalCameraUseCase: CaptureWithExternalCameraUseCase, private val generatePhotoFrameUseCase: GeneratePhotoFrameUseCase, private val sessionKeyUseCase: SessionKeyUseCase ): ViewModel() { @@ -56,7 +54,14 @@ class CameraViewModel @Inject constructor( viewModelScope.launch { SoundUtil.getCameraSound(context = context ) val bitmap = graphicsLayer.toImageBitmap().asAndroidBitmap() - generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, "${AppPolicy.CAPTURED_FOUR_CUT_IMAGE_NAME}_${_captureCount.value}") + + // TODO: 현재 External 실패 시, 스크린 캡쳐 화면을 사용하도록 구성함 + val fileName = "${AppPolicy.CAPTURED_FOUR_CUT_IMAGE_NAME}_${_captureCount.value}" + captureWithExternalCameraUseCase(fileName) + .onFailure { + generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, fileName) + } + _progressState.floatValue = 1f if (_captureCount.intValue < AppPolicy.CAPTURE_COUNT) { _captureCount.intValue += 1 @@ -80,11 +85,11 @@ class CameraViewModel @Inject constructor( } } } + fun stopCaptureTimer() = viewModelScope.launch{ if(captureTimer != null){ mTimerState = false captureTimer!!.cancel() } } - } \ No newline at end of file