-
Notifications
You must be signed in to change notification settings - Fork 157
Migrate ResultsScreen to use Nav3 #95
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 |
---|---|---|
|
@@ -32,15 +32,18 @@ import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.IntOffset | ||
import androidx.core.net.toUri | ||
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator | ||
import androidx.navigation3.runtime.entry | ||
import androidx.navigation3.runtime.entryProvider | ||
import androidx.navigation3.runtime.rememberSavedStateNavEntryDecorator | ||
import androidx.navigation3.ui.NavDisplay | ||
import com.android.developers.androidify.camera.CameraPreviewScreen | ||
import com.android.developers.androidify.creation.CreationScreen | ||
import com.android.developers.androidify.customize.CustomizeAndExportScreen | ||
import com.android.developers.androidify.home.AboutScreen | ||
import com.android.developers.androidify.home.HomeScreen | ||
import com.android.developers.androidify.results.ResultsScreen | ||
import com.android.developers.androidify.theme.transitions.ColorSplashTransitionScreen | ||
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity | ||
|
||
|
@@ -110,6 +113,51 @@ fun MainNavigation() { | |
onAboutPressed = { | ||
backStack.add(About) | ||
}, | ||
onImageCreated = { resultImageUri, prompt, originalImageUri -> | ||
backStack.removeAll{ it is ImageResult} | ||
backStack.add( | ||
ImageResult( | ||
result = resultImageUri.toString(), | ||
prompt = prompt, | ||
originalImageUri = originalImageUri?.toString() | ||
) | ||
) | ||
} | ||
Comment on lines
+116
to
+125
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. The current implementation of To fix this, you should replace the onImageCreated = { resultImageUri, prompt, originalImageUri ->
backStack.removeAll { it is ImageResult }
// Replace the current entry (Create) with ImageResult to ensure a correct back stack
if (backStack.isNotEmpty()) {
backStack[backStack.lastIndex] = ImageResult(
result = resultImageUri.toString(),
prompt = prompt,
originalImageUri = originalImageUri?.toString()
)
} else {
backStack.add(
ImageResult(
result = resultImageUri.toString(),
prompt = prompt,
originalImageUri = originalImageUri?.toString()
)
)
}
} |
||
) | ||
} | ||
entry<ImageResult> { resultKey -> | ||
ResultsScreen( | ||
resultImageUri = resultKey.result.toUri(), | ||
srikrishnasakunia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
originalImageUri = resultKey.originalImageUri?.toUri(), | ||
onNextPress = { resultImageUri, originalImageUri -> | ||
backStack.removeAll{ it is ImageResult} | ||
backStack.add( | ||
ShareResult( | ||
resultUri = resultImageUri.toString(), | ||
originalImageUri = originalImageUri?.toString() | ||
) | ||
) | ||
}, | ||
promptText = resultKey.prompt, | ||
onAboutPress = { | ||
backStack.add(About) | ||
}, | ||
onBackPress = { | ||
backStack.removeLastOrNull() | ||
backStack.add(Create(fileName = resultKey.originalImageUri, prompt = resultKey.prompt)) | ||
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. As far as I understand, we shouldn't need to do this as the Create() entry should already be on the backstack after removing the last one? |
||
} | ||
) | ||
} | ||
entry<ShareResult> { shareKey -> | ||
CustomizeAndExportScreen( | ||
resultImageUri = shareKey.resultUri.toUri(), | ||
originalImageUri = shareKey.originalImageUri?.toUri(), | ||
onBackPress = { | ||
backStack.removeLastOrNull() | ||
}, | ||
onInfoPress = { | ||
backStack.add(About) | ||
} | ||
) | ||
} | ||
entry<About> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,7 @@ fun CreationScreen( | |
onCameraPressed: () -> Unit = {}, | ||
onBackPressed: () -> Unit, | ||
onAboutPressed: () -> Unit, | ||
onImageCreated: (resultImageUri: Uri, prompt: String?, originalImageUri: Uri?) -> Unit, | ||
) { | ||
val uiState by creationViewModel.uiState.collectAsStateWithLifecycle() | ||
BackHandler( | ||
|
@@ -213,44 +214,16 @@ fun CreationScreen( | |
} | ||
|
||
ScreenState.RESULT -> { | ||
val prompt = uiState.descriptionText.text.toString() | ||
val key = if (uiState.descriptionText.text.isBlank()) { | ||
uiState.imageUri.toString() | ||
} else { | ||
prompt | ||
} | ||
ResultsScreen( | ||
uiState.resultBitmap!!, | ||
onImageCreated( | ||
uiState.resultBitmapUri!!, | ||
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. Use of |
||
uiState.descriptionText.text.toString(), | ||
if (uiState.selectedPromptOption == PromptType.PHOTO) { | ||
uiState.imageUri | ||
} else { | ||
null | ||
}, | ||
promptText = prompt, | ||
viewModel = hiltViewModel(key = key), | ||
onAboutPress = onAboutPressed, | ||
onBackPress = onBackPressed, | ||
onNextPress = creationViewModel::customizeExportClicked, | ||
} | ||
Comment on lines
216
to
+224
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. We should likely be able to remove this state now as the Result screen state is handled by Nav3 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. So we should only have here, Edit and Loading. |
||
) | ||
} | ||
|
||
ScreenState.CUSTOMIZE -> { | ||
val prompt = uiState.descriptionText.text.toString() | ||
val key = if (uiState.descriptionText.text.isBlank()) { | ||
uiState.imageUri.toString() | ||
} else { | ||
prompt | ||
} | ||
uiState.resultBitmap?.let { bitmap -> | ||
CustomizeAndExportScreen( | ||
resultImage = bitmap, | ||
originalImageUri = uiState.imageUri, | ||
onBackPress = onBackPressed, | ||
onInfoPress = onAboutPressed, | ||
viewModel = hiltViewModel<CustomizeExportViewModel>(key = key), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.