-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from Devendra34/feature/onboarding_compose
Migrate onboarding feature from XML to Jetpack Compose
- Loading branch information
Showing
10 changed files
with
260 additions
and
100 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/hieuwu/groceriesstore/presentation/core/widgets/PrimaryButton.kt
This file contains 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,52 @@ | ||
package com.hieuwu.groceriesstore.presentation.core.widgets | ||
|
||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.hieuwu.groceriesstore.R | ||
|
||
@Composable | ||
fun PrimaryButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
content: @Composable RowScope.() -> Unit | ||
) { | ||
|
||
Button( | ||
modifier = modifier.defaultMinSize(minHeight = 48.dp), | ||
enabled = enabled, | ||
onClick = onClick, | ||
shape = RoundedCornerShape(8.dp), | ||
colors = ButtonDefaults.buttonColors( | ||
containerColor = colorResource(id = R.color.colorPrimaryDark), | ||
disabledContainerColor = colorResource(id = R.color.light_gray), | ||
contentColor = Color.White, | ||
), | ||
content = content | ||
) | ||
} | ||
@Preview | ||
@Composable | ||
private fun EnabledPrimaryButtonPreview() { | ||
PrimaryButton(onClick = {}) { | ||
Text(text = "Enabled") | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun DisabledPrimaryButtonPreview() { | ||
PrimaryButton(onClick = {}, enabled = false) { | ||
Text(text = "Disabled") | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/hieuwu/groceriesstore/presentation/core/widgets/SecondaryButton.kt
This file contains 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,65 @@ | ||
package com.hieuwu.groceriesstore.presentation.core.widgets | ||
|
||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.OutlinedButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.hieuwu.groceriesstore.R | ||
|
||
@Composable | ||
fun SecondaryButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
content: @Composable RowScope.() -> Unit | ||
) { | ||
|
||
OutlinedButton( | ||
modifier = modifier.defaultMinSize(minHeight = 48.dp), | ||
enabled = enabled, | ||
onClick = onClick, | ||
shape = RoundedCornerShape(8.dp), | ||
colors = ButtonDefaults.outlinedButtonColors( | ||
contentColor = colorResource(id = R.color.colorPrimary), | ||
disabledContentColor = colorResource(id = R.color.colorPrimary).copy( | ||
alpha = SecondaryButtonTokens.DisabledLabelTextOpacity | ||
), | ||
), | ||
border = BorderStroke( | ||
width = 1.dp, | ||
color = colorResource(id = R.color.colorPrimary).copy( | ||
alpha = if (!enabled) SecondaryButtonTokens.DisabledContainerOpacity else 1f | ||
) | ||
), | ||
content = content | ||
) | ||
} | ||
|
||
internal object SecondaryButtonTokens { | ||
const val DisabledContainerOpacity = 0.12f | ||
const val DisabledLabelTextOpacity = 0.38f | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun EnabledSecondaryButtonPreview() { | ||
SecondaryButton(onClick = {}) { | ||
Text(text = "Enabled") | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun DisabledSecondaryButtonPreview() { | ||
SecondaryButton(onClick = {}, enabled = false) { | ||
Text(text = "Disabled") | ||
} | ||
} |
This file contains 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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/hieuwu/groceriesstore/presentation/onboarding/OnboardingScreen.kt
This file contains 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,31 @@ | ||
package com.hieuwu.groceriesstore.presentation.onboarding | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import com.hieuwu.groceriesstore.presentation.onboarding.widgets.OnboardingScreenBackground | ||
import com.hieuwu.groceriesstore.presentation.onboarding.widgets.OnboardingScreenContent | ||
|
||
@Composable | ||
fun OnboardingScreen( | ||
modifier: Modifier = Modifier, | ||
navigateToMainInitialScreen: () -> Unit | ||
) { | ||
Scaffold { paddingValues -> | ||
Box( | ||
modifier = modifier.padding(paddingValues) | ||
) { | ||
OnboardingScreenBackground( | ||
modifier = modifier.fillMaxSize(), | ||
) | ||
OnboardingScreenContent( | ||
modifier = Modifier.align(Alignment.BottomCenter), | ||
navigateToMainInitialScreen, | ||
) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...a/com/hieuwu/groceriesstore/presentation/onboarding/widgets/OnboardingGetStartedButton.kt
This file contains 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,27 @@ | ||
package com.hieuwu.groceriesstore.presentation.onboarding.widgets | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.hieuwu.groceriesstore.R | ||
import com.hieuwu.groceriesstore.presentation.core.widgets.PrimaryButton | ||
import com.hieuwu.groceriesstore.presentation.onboarding.OnboardingViewModel | ||
|
||
@Composable | ||
fun OnboardingGetStartedButton( | ||
modifier: Modifier = Modifier, | ||
viewModel: OnboardingViewModel = hiltViewModel(), | ||
navigateToMainInitialScreen: () -> Unit | ||
) { | ||
val enabled = viewModel.isSyncedSuccessful.collectAsState() | ||
PrimaryButton( | ||
modifier = modifier, | ||
onClick = navigateToMainInitialScreen, | ||
enabled = enabled.value, | ||
) { | ||
Text(text = stringResource(id = R.string.get_started)) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...a/com/hieuwu/groceriesstore/presentation/onboarding/widgets/OnboardingScreenBackground.kt
This file contains 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,28 @@ | ||
package com.hieuwu.groceriesstore.presentation.onboarding.widgets | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.hieuwu.groceriesstore.R | ||
|
||
@Composable | ||
fun OnboardingScreenBackground(modifier: Modifier = Modifier) { | ||
Image( | ||
modifier = modifier, | ||
painter = painterResource(id = R.drawable.onboarding_background), | ||
contentScale = ContentScale.FillBounds, | ||
contentDescription = null | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun OnboardingScreenBackgroundPreview() { | ||
OnboardingScreenBackground( | ||
modifier = Modifier.fillMaxSize() | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
...java/com/hieuwu/groceriesstore/presentation/onboarding/widgets/OnboardingScreenContent.kt
This file contains 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,51 @@ | ||
package com.hieuwu.groceriesstore.presentation.onboarding.widgets | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.hieuwu.groceriesstore.R | ||
|
||
@Composable | ||
fun OnboardingScreenContent( | ||
modifier: Modifier = Modifier, | ||
navigateToMainInitialScreen: () -> Unit | ||
) { | ||
Column( | ||
modifier = modifier.padding(start = 16.dp, end = 16.dp, bottom = 120.dp), | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Image( | ||
modifier = Modifier.size(64.dp), | ||
painter = painterResource(id = R.drawable.ic_carrot_icon), | ||
contentDescription = null, | ||
) | ||
Text( | ||
text = stringResource(R.string.welcome_to_our_store), | ||
fontSize = 22.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = Color.White, | ||
) | ||
Text( | ||
text = stringResource(R.string.get_your_gorceries_in_as_fast_as_one_hour), | ||
color = Color.White, | ||
) | ||
OnboardingGetStartedButton( | ||
modifier = Modifier.fillMaxWidth(), | ||
navigateToMainInitialScreen = navigateToMainInitialScreen | ||
) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.