Skip to content

Commit 649b56a

Browse files
committed
hotfix. take photo with external camera [#89]
- external camera 촬영 UseCase 복구 - external camera 촬영 실패 시, preview 화면 캡쳐 사용
1 parent 5d57ded commit 649b56a

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

domain/src/main/java/com/foke/together/domain/interactor/CaptureWithExternalCameraUseCase.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
package com.foke.together.domain.interactor
22

3-
import android.content.Context
43
import com.foke.together.domain.output.ExternalCameraRepositoryInterface
54
import com.foke.together.domain.output.ImageRepositoryInterface
65
import com.foke.together.util.AppLog
7-
import com.foke.together.util.ImageFileUtil
8-
import com.foke.together.util.TimeUtil
9-
import dagger.hilt.android.qualifiers.ApplicationContext
106
import javax.inject.Inject
117

128
class CaptureWithExternalCameraUseCase @Inject constructor(
13-
@ApplicationContext private val context: Context,
149
private val externalCameraRepository: ExternalCameraRepositoryInterface,
1510
private val imageRepository: ImageRepositoryInterface
1611
) {
1712
suspend operator fun invoke(fileName: String): Result<Unit> {
1813
externalCameraRepository.capture()
1914
.onSuccess {
20-
// TODO: save Bitmap to internal storage
2115
AppLog.i(TAG, "capture", "success: $it")
22-
if(it == null) {
23-
return Result.failure(Exception("Bitmap is null"))
24-
}
25-
imageRepository.saveToStorage(it, fileName)
16+
imageRepository.cachingImage(it, fileName)
2617
return Result.success(Unit)
2718
}
2819
.onFailure {

presenter/src/main/java/com/foke/together/presenter/viewmodel/CameraViewModel.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ import com.foke.together.util.AppPolicy
1717
import com.foke.together.util.AppPolicy.CAPTURE_INTERVAL
1818
import com.foke.together.util.AppPolicy.COUNTDOWN_INTERVAL
1919
import com.foke.together.util.SoundUtil
20-
import com.foke.together.util.TimeUtil
2120
import dagger.hilt.android.lifecycle.HiltViewModel
2221
import dagger.hilt.android.qualifiers.ApplicationContext
23-
import kotlinx.coroutines.delay
2422
import kotlinx.coroutines.launch
2523
import javax.inject.Inject
2624

2725
@HiltViewModel
2826
class 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

Comments
 (0)