diff --git a/presenter/src/main/java/com/foke/together/presenter/screen/CameraScreen.kt b/presenter/src/main/java/com/foke/together/presenter/screen/CameraScreen.kt index 49b7aa3..d97c046 100644 --- a/presenter/src/main/java/com/foke/together/presenter/screen/CameraScreen.kt +++ b/presenter/src/main/java/com/foke/together/presenter/screen/CameraScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -35,18 +36,7 @@ fun CameraScreen( viewModel: CameraViewModel = hiltViewModel() ) { val TAG = "CameraScreen" - LifecycleEventEffect(Lifecycle.Event.ON_START) { - viewModel.setCaptureTimer { navigateToShare() } - AppLog.d(TAG, "ON_START") - } - LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { - AppLog.d(TAG, "ON_RESUME") - viewModel.startCaptureTimer() - } - LifecycleEventEffect(Lifecycle.Event.ON_STOP) { - viewModel.stopCaptureTimer() - AppLog.d(TAG, "ON_STOP") - } + var mjpegView: MjpegView? = null ConstraintLayout( modifier = Modifier.fillMaxSize() ) { @@ -103,6 +93,7 @@ fun CameraScreen( .aspectRatio(1.5f), factory = { context -> MjpegView(context).apply { + mjpegView = this mode = MjpegView.MODE_BEST_FIT isAdjustHeight = true supportPinchZoomAndPan = false @@ -135,7 +126,6 @@ fun CameraScreen( // test url // TODO : change url in viewmodel setUrl("http://10.32.100.37:5000/preview") - startStream() } }, ) @@ -153,6 +143,21 @@ fun CameraScreen( fontSize = 24.sp, ) } + LifecycleEventEffect(Lifecycle.Event.ON_START) { + viewModel.setCaptureTimer { navigateToShare() } + AppLog.d(TAG, "ON_START") + } + LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { + AppLog.d(TAG, "ON_RESUME") + viewModel.startCaptureTimer() + mjpegView?.startStream() + } + LifecycleEventEffect(Lifecycle.Event.ON_STOP) { + viewModel.stopCaptureTimer() + AppLog.d(TAG, "ON_STOP") + mjpegView?.stopStream() + } + LocalContext } @Preview(showBackground = true) 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 86a82c4..78c8153 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 @@ -26,19 +26,16 @@ class CameraViewModel @Inject constructor( captureTimer = object : CountDownTimer(5000, 10) { override fun onTick(millisUntilFinished: Long) { _progressState.floatValue = 1f - (millisUntilFinished.toFloat() / 5000) - AppLog.d("CameraViewModel", "onTick: ${_progressState.floatValue}") } override fun onFinish() { _progressState.floatValue = 1f if(_captureCount.intValue < 4){ _captureCount.intValue += 1 startCaptureTimer() - AppLog.d("CameraViewModel", "onFinish: ${_captureCount.intValue}") } else { stopCaptureTimer() _captureCount.intValue = 1 - AppLog.d("CameraViewModel", "onFinish: ${_captureCount.intValue}") nextNavigate() } }