File tree Expand file tree Collapse file tree 4 files changed +21
-10
lines changed
app/src/main/java/com/android/developers/androidify/navigation
camera/src/main/java/com/android/developers/androidify/camera
creation/src/main/java/com/android/developers/androidify/creation Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,6 @@ fun MainNavigation() {
8989 fadeIn(motionScheme.defaultEffectsSpec()),
9090 scaleOut(
9191 targetScale = 0.7f ,
92- transformOrigin = TransformOrigin (pivotFractionX = 0.5f , pivotFractionY = 0.5f ),
9392 ),
9493 )
9594 },
@@ -108,14 +107,17 @@ fun MainNavigation() {
108107 entry<Camera > {
109108 CameraPreviewScreen (
110109 onImageCaptured = { uri ->
110+ backStack.removeAll { it is Create }
111111 backStack.add(Create (uri.toString()))
112+ backStack.removeAll { it is Camera }
112113 },
113114 )
114115 }
115116 entry<Create > { createKey ->
116117 CreationScreen (
117118 createKey.fileName,
118119 onCameraPressed = {
120+ backStack.removeAll { it is Camera }
119121 backStack.add(Camera )
120122 },
121123 onBackPressed = {
@@ -142,7 +144,7 @@ fun MainNavigation() {
142144 showSplash = false
143145 },
144146 onTransitionMidpoint = {
145- backStack.add(Create ())
147+ backStack.add(Create (fileName = null ))
146148 },
147149 )
148150 }
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ fun CameraPreviewScreen(
137137 // so CameraX can retrieve the new Surface.
138138 LaunchedEffect (surface) {
139139 val oldIsTableTop = isTableTopPosture(foldingFeature)
140+
140141 snapshotFlow { foldingFeature }
141142 .takeWhile {
142143 val newIsTableTop = isTableTopPosture(it)
Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ fun CreationScreen(
169169 }
170170 LaunchedEffect (Unit ) {
171171 if (fileName != null ) creationViewModel.onImageSelected(fileName.toUri())
172+ else creationViewModel.onImageSelected(null )
172173 }
173174 val pickMedia = rememberLauncherForActivityResult(PickVisualMedia ()) { uri ->
174175 if (uri != null ) {
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ class CreationViewModel @Inject constructor(
8989 val snackbarHostState: StateFlow <SnackbarHostState >
9090 get() = _snackbarHostState
9191
92- fun onImageSelected (uri : Uri ) {
92+ fun onImageSelected (uri : Uri ? ) {
9393 _uiState .update {
9494 it.copy(
9595 imageUri = uri,
@@ -116,14 +116,21 @@ class CreationViewModel @Inject constructor(
116116 _uiState .update {
117117 it.copy(promptGenerationInProgress = true )
118118 }
119- val prompt = textGenerationRepository.getNextGeneratedBotPrompt()
120- Log .d(" CreationViewModel" , " Prompt: $prompt " )
121- if (prompt != null ) {
119+ try {
120+ val prompt = textGenerationRepository.getNextGeneratedBotPrompt()
121+ Log .d(" CreationViewModel" , " Prompt: $prompt " )
122+ if (prompt != null ) {
123+ _uiState .update {
124+ it.copy(
125+ generatedPrompt = prompt,
126+ promptGenerationInProgress = false ,
127+ )
128+ }
129+ }
130+ } catch (exception: Exception ) {
131+ Log .e(" CreationViewModel" , " Error generating prompt" , exception)
122132 _uiState .update {
123- it.copy(
124- generatedPrompt = prompt,
125- promptGenerationInProgress = false ,
126- )
133+ it.copy(promptGenerationInProgress = false )
127134 }
128135 }
129136 }
You can’t perform that action at this time.
0 commit comments