Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ import com.tomsksoft.videoeffectsrecorder.ui.entity.SecondaryFiltersMode
import com.tomsksoft.videoeffectsrecorder.ui.viewmodel.CameraViewModel
import com.tomsksoft.videoeffectsrecorder.ui.viewmodel.CameraViewModelImpl
import com.tomsksoft.videoeffectsrecorder.ui.viewmodel.CameraViewModelStub
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.max

private const val REQUEST_PICK_PHOTO_BACKGROUND = 1
private const val REQUEST_PICK_PHOTO_GRADING_SOURCE = 2
Expand Down Expand Up @@ -251,13 +253,17 @@ fun CameraUi(viewModel: CameraViewModel, onGalleryClick: () -> Unit) {
cameraUiState = cameraUiState,
onFlipCameraClick = viewModel::flipCamera,
onCaptureClick = {
val animDurMs = 200
val delayBeforeShotMs = viewModel.captureImage()
val delayBeforeAnimMs = max(0, delayBeforeShotMs - animDurMs)
scope.launch {
val durationMs = 200
if (delayBeforeAnimMs > 0)
delay(delayBeforeAnimMs.toLong())

alphaAnimation.animateTo(0f, snap())
alphaAnimation.animateTo(1f, tween(durationMs / 2))
alphaAnimation.animateTo(0f, tween(durationMs / 2))
alphaAnimation.animateTo(1f, tween(animDurMs / 2))
alphaAnimation.animateTo(0f, tween(animDurMs / 2))
}
viewModel.captureImage()
},
onLongPress = viewModel::startVideoRecording,
onRelease = viewModel::stopVideoRecording,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ interface CameraViewModel {
fun setBackground(bitmapStream: InputStream)
fun removeBackground()
fun flipCamera()
fun captureImage()

/**
* @return delay before actual shot
*/
fun captureImage(): Int
fun startVideoRecording()
fun stopVideoRecording()
fun setBlurPower(value: Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ class CameraViewModelImpl @Inject constructor(
}
}

override fun captureImage() {
override fun captureImage(): Int {
Log.d(TAG, "Capture image")
cameraRecordManager.takePhoto(camera!!.frame)
return cameraRecordManager.takePhoto(camera!!.frame)
}

override fun startVideoRecording() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ class CameraRecordManager(

val isRecording: Boolean get() = record != null

fun takePhoto(frameSource: Observable<Any>) {
fun takePhoto(frameSource: Observable<Any>): Int {
val flashDuration =
if (cameraManager.flashMode.blockingFirst() == FlashMode.AUTO)
1000
else
0

scope.launch {
val frame: Any
if (cameraManager.flashMode.blockingFirst() == FlashMode.AUTO) {

if (flashDuration > 0) {
cameraManager.setFlashEnabled(true)
delay(1000L)
delay(flashDuration.toLong())
frame = frameSource.blockingFirst()
cameraManager.setFlashEnabled(false)
} else {
} else
frame = frameSource.blockingFirst()
}

photoPicker.takePhoto(
frame,
cameraManager.orientation.blockingFirst(),
PHOTO_BASE_NAME,
PHOTO_MIME_TYPE
)
}

return flashDuration
}

fun startRecord(frameSource: Observable<Any>) {
Expand Down