Skip to content

Commit

Permalink
add loading icon when saving video
Browse files Browse the repository at this point in the history
  • Loading branch information
calren committed Apr 15, 2024
1 parent fed17e3 commit aec7383
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Autorenew
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -76,6 +78,8 @@ fun Camera(
modifier: Modifier = Modifier,
viewModel: CameraViewModel = hiltViewModel(),
) {
val isSavingVideo = viewModel.isSavingVideo.collectAsState()

var surfaceProvider by remember { mutableStateOf<Preview.SurfaceProvider?>(null) }
var cameraSelector by remember { mutableStateOf(CameraSelector.DEFAULT_BACK_CAMERA) }
var captureMode by remember { mutableStateOf(CaptureMode.PHOTO) }
Expand Down Expand Up @@ -308,6 +312,14 @@ fun Camera(
}
}
}

if (isSavingVideo.value) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center)
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape)
.padding(8.dp),
)
}
}
} else {
CameraAndRecordAudioPermission(cameraAndRecordAudioPermissionState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import java.text.SimpleDateFormat
import java.util.Locale
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

@HiltViewModel
Expand All @@ -70,6 +71,9 @@ class CameraViewModel @Inject constructor(
private lateinit var camera: Camera
private lateinit var extensionsManager: ExtensionsManager

private val _isSavingVideo = MutableStateFlow(false)
val isSavingVideo: StateFlow<Boolean> = _isSavingVideo

val chatId: Long? = savedStateHandle.get("chatId")
var viewFinderState = MutableStateFlow(ViewFinderState())

Expand Down Expand Up @@ -231,6 +235,7 @@ class CameraViewModel @Inject constructor(
recordingState = event
if (event is VideoRecordEvent.Finalize) {
onMediaCaptured(Media(event.outputResults.outputUri, MediaType.VIDEO))
_isSavingVideo.value = false
}
}

Expand All @@ -255,6 +260,8 @@ class CameraViewModel @Inject constructor(
}

fun saveVideo() {
_isSavingVideo.value = true

if (currentRecording == null || recordingState is VideoRecordEvent.Finalize) {
return
}
Expand Down

0 comments on commit aec7383

Please sign in to comment.