Skip to content

Commit

Permalink
hotfix. take photo with external camera [FoKE-Developers#89]
Browse files Browse the repository at this point in the history
- external camera 촬영 UseCase 복구
- external camera 촬영 실패 시, preview 화면 캡쳐 사용
  • Loading branch information
DokySp committed Oct 11, 2024
1 parent 5d57ded commit 10b24a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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<Unit> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ 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

@HiltViewModel
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() {
Expand Down Expand Up @@ -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
Expand All @@ -80,11 +85,11 @@ class CameraViewModel @Inject constructor(
}
}
}

fun stopCaptureTimer() = viewModelScope.launch{
if(captureTimer != null){
mTimerState = false
captureTimer!!.cancel()
}
}

}

0 comments on commit 10b24a5

Please sign in to comment.