-
Notifications
You must be signed in to change notification settings - Fork 110
Move Toast invocations out of Camera/VideoEdit ViewModels. #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package com.google.android.samples.socialite.ui.videoedit | |
import android.media.MediaMetadataRetriever | ||
import android.net.Uri | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
|
@@ -59,6 +60,7 @@ import androidx.compose.material3.TextFieldDefaults | |
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
|
@@ -71,6 +73,7 @@ import androidx.compose.ui.graphics.asImageBitmap | |
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalInspectionMode | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
@@ -92,6 +95,7 @@ fun VideoEditScreen( | |
onCloseButtonClicked: () -> Unit, | ||
navController: NavController, | ||
) { | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
val context = LocalContext.current | ||
|
||
val viewModel: VideoEditScreenViewModel = hiltViewModel() | ||
|
@@ -104,6 +108,19 @@ fun VideoEditScreen( | |
|
||
val isProcessing = viewModel.isProcessing.collectAsState() | ||
|
||
LaunchedEffect(lifecycleOwner, context) { | ||
viewModel.videoSaveState.collect { state -> | ||
when (state) { | ||
VideoSaveState.VIDEO_SAVE_SUCCESS -> | ||
Toast.makeText(context, "Edited video saved", Toast.LENGTH_LONG).show() | ||
VideoSaveState.VIDEO_SAVE_FAIL -> | ||
Toast.makeText(context, "Error applying edits on video", Toast.LENGTH_LONG) | ||
.show() | ||
VideoSaveState.PENDING -> Unit | ||
} | ||
} | ||
} | ||
Comment on lines
+111
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoc081098 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yongsuk44 nice, but val scope = rememberCoroutineScope()
LifecycleResumeEffect(scope, viewModel) {
// ON_RESUME code is executed here
val job = viewModel.videoSaveState
.onEach{ /*handler*/}
.launchIn(scope)
onPauseOrDispose {
// do any needed clean up here
job.cancel()
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoc081098 Considering the link I provided, collectAsStateWithLifecycle is designed to simplify the task of activating Flow collection when the app is in the foreground, making it easier for developers to manage state. So, why use LifecycleResumeEffect?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yongsuk44 👉 we only collect the flow 👍, we don't need a returned Compose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoc081098 😀 I understand, thanks |
||
|
||
var removeAudioEnabled by rememberSaveable { mutableStateOf(false) } | ||
var overlayText by rememberSaveable { mutableStateOf("") } | ||
var redOverlayTextEnabled by rememberSaveable { mutableStateOf(false) } | ||
|
Uh oh!
There was an error while loading. Please reload this page.