@@ -17,18 +17,16 @@ import com.foke.together.util.AppPolicy
1717import com.foke.together.util.AppPolicy.CAPTURE_INTERVAL
1818import com.foke.together.util.AppPolicy.COUNTDOWN_INTERVAL
1919import com.foke.together.util.SoundUtil
20- import com.foke.together.util.TimeUtil
2120import dagger.hilt.android.lifecycle.HiltViewModel
2221import dagger.hilt.android.qualifiers.ApplicationContext
23- import kotlinx.coroutines.delay
2422import kotlinx.coroutines.launch
2523import javax.inject.Inject
2624
2725@HiltViewModel
2826class CameraViewModel @Inject constructor(
2927 @ApplicationContext private val context : Context ,
3028 getExternalCameraPreviewUrlUseCase : GetExternalCameraPreviewUrlUseCase ,
31- // private val captureWithExternalCameraUseCase: CaptureWithExternalCameraUseCase,
29+ private val captureWithExternalCameraUseCase : CaptureWithExternalCameraUseCase ,
3230 private val generatePhotoFrameUseCase : GeneratePhotoFrameUseCase ,
3331 private val sessionKeyUseCase : SessionKeyUseCase
3432): ViewModel() {
@@ -56,7 +54,14 @@ class CameraViewModel @Inject constructor(
5654 viewModelScope.launch {
5755 SoundUtil .getCameraSound(context = context )
5856 val bitmap = graphicsLayer.toImageBitmap().asAndroidBitmap()
59- generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, " ${AppPolicy .CAPTURED_FOUR_CUT_IMAGE_NAME } _${_captureCount .value} " )
57+
58+ // TODO: 현재 External 실패 시, 스크린 캡쳐 화면을 사용하도록 구성함
59+ val fileName = " ${AppPolicy .CAPTURED_FOUR_CUT_IMAGE_NAME } _${_captureCount .value} "
60+ captureWithExternalCameraUseCase(fileName)
61+ .onFailure {
62+ generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, fileName)
63+ }
64+
6065 _progressState .floatValue = 1f
6166 if (_captureCount .intValue < AppPolicy .CAPTURE_COUNT ) {
6267 _captureCount .intValue + = 1
@@ -80,11 +85,11 @@ class CameraViewModel @Inject constructor(
8085 }
8186 }
8287 }
88+
8389 fun stopCaptureTimer () = viewModelScope.launch{
8490 if (captureTimer != null ){
8591 mTimerState = false
8692 captureTimer!! .cancel()
8793 }
8894 }
89-
9095}
0 commit comments