-
Notifications
You must be signed in to change notification settings - Fork 263
Migrate sample to compose #173
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
Draft
cy245
wants to merge
4
commits into
main
Choose a base branch
from
migrate-sample-to-compose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
CredentialManager/app/src/main/java/com/google/credentialmanager/sample/AppNavigation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.google.credentialmanager.sample | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
|
||
// 1. Define navigation routes | ||
sealed class Screen(val route: String) { | ||
object Main : Screen("main") | ||
object SignUp : Screen("signup") | ||
object SignIn : Screen("signin") | ||
object Home : Screen("home") | ||
} | ||
|
||
// 2. Create a Composable function for the navigation host | ||
@Composable | ||
fun AppNavHost( | ||
startDestination: String = Screen.Main.route | ||
) { | ||
val navController = rememberNavController() | ||
|
||
NavHost( | ||
navController = navController, | ||
startDestination = startDestination | ||
) { | ||
composable(Screen.Main.route) { | ||
MainScreen(navController = navController) | ||
} | ||
composable(Screen.SignUp.route) { | ||
SignUpScreen(navController = navController) | ||
} | ||
composable(Screen.SignIn.route) { | ||
SignInScreen(navController = navController) | ||
} | ||
composable(Screen.Home.route) { | ||
HomeScreen(navController = navController) | ||
} | ||
} | ||
} |
74 changes: 0 additions & 74 deletions
74
CredentialManager/app/src/main/java/com/google/credentialmanager/sample/HomeFragment.kt
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
CredentialManager/app/src/main/java/com/google/credentialmanager/sample/HomeScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.google.credentialmanager.sample | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.navigation.NavController | ||
import androidx.navigation.compose.rememberNavController | ||
import com.google.credentialmanager.sample.ui.theme.CredentialManagerSampleTheme | ||
|
||
@Composable | ||
fun HomeScreen(navController: NavController) { | ||
CredentialManagerSampleTheme { | ||
val isSignedInThroughPasskeys = DataProvider.isSignedInThroughPasskeys() | ||
val message = if (isSignedInThroughPasskeys) { | ||
"Logged in successfully through passkeys" | ||
} else { | ||
"Logged in successfully through password" | ||
} | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(20.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text( | ||
text = message, | ||
modifier = Modifier.padding(16.dp), | ||
textAlign = TextAlign.Center, | ||
fontSize = 24.sp, | ||
fontWeight = FontWeight.Bold | ||
) | ||
Button( | ||
onClick = { | ||
DataProvider.configureSignedInPref(false) | ||
navController.navigate(Screen.Main.route) { | ||
popUpTo(Screen.Home.route) { inclusive = true } | ||
launchSingleTop = true | ||
} | ||
}, | ||
shape = RoundedCornerShape(4.dp), | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 20.dp) | ||
) { | ||
Text("Sign out and try again") | ||
} | ||
cy245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun HomeScreenPreview() { | ||
CredentialManagerSampleTheme { | ||
val context = LocalContext.current | ||
DataProvider.initSharedPref(context) | ||
HomeScreen(navController = rememberNavController()) | ||
cy245 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.