-
Notifications
You must be signed in to change notification settings - Fork 119
Fruittie screen and ios designs #78
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b9635fb
Update material3 to prevent recompositions
mlykotom d3abf2a
Add FruittieScreen + connect cart actions
mlykotom 0b43489
ios: Fix toolbar
mlykotom 6851493
ios: design cart with +- actions
mlykotom 2e349c8
Fix typo
mlykotom ea1bde8
Design frutttie + list + cart screens
mlykotom a2761d6
Merge branch 'main' into mlykotom/fruittie-screen-and-ios-designs
mlykotom b5b9ee5
Revert "Merge branch 'main' into mlykotom/fruittie-screen-and-ios-des…
mlykotom a1dfdf7
Update Fruitties/androidApp/src/main/java/com/example/fruitties/andro…
mlykotom 3cafda5
Add previews to CartScreen
mlykotom 33aa359
TotalItemCounts is calculated from state
mlykotom f802fed
String res for cart has items
mlykotom 7b61df5
Handle paddings on list screen
mlykotom d107f53
Format: Spotless
mlykotom 6ad9957
Merge branch 'main' into mlykotom/fruittie-screen-and-ios-designs
mlykotom 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
130 changes: 130 additions & 0 deletions
130
Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/FruittieScreen.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,130 @@ | ||
| package com.example.fruitties.android.ui | ||
|
|
||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
| import androidx.compose.material.icons.filled.ShoppingCart | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.FloatingActionButton | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TopAppBar | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.lifecycle.viewmodel.compose.viewModel | ||
| import com.example.fruitties.android.R | ||
| import com.example.fruitties.android.di.App | ||
| import com.example.fruitties.model.Fruittie | ||
| import com.example.fruitties.viewmodel.FruittieViewModel | ||
| import com.example.fruitties.viewmodel.FruittieViewModel.Companion.FRUITTIE_ID_KEY | ||
| import com.example.fruitties.viewmodel.creationExtras | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun FruittieScreen( | ||
| fruittieId: Long, | ||
| onNavBarBack: () -> Unit | ||
| ) { | ||
| val app = LocalContext.current.applicationContext as App | ||
|
|
||
| val viewModel: FruittieViewModel = viewModel( | ||
bentrengrove marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| factory = FruittieViewModel.Factory, | ||
| extras = creationExtras(app.container) { | ||
| set(FRUITTIE_ID_KEY, fruittieId) | ||
| }, | ||
| ) | ||
|
|
||
| val state = viewModel.state.collectAsState().value | ||
|
|
||
| FruittieScreen( | ||
| state = state, | ||
| onNavBarBack = onNavBarBack, | ||
| addToCart = { viewModel.addToCart(it) } | ||
| ) | ||
| } | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun FruittieScreen( | ||
| state: FruittieViewModel.State, | ||
| addToCart: (Fruittie) -> Unit, | ||
| onNavBarBack: () -> Unit | ||
| ) { | ||
| Scaffold( | ||
| topBar = { | ||
| TopAppBar( | ||
| title = { | ||
| Text( | ||
| (state as? FruittieViewModel.State.Content)?.fruittie?.name | ||
| ?: stringResource(R.string.loading) | ||
| ) | ||
| }, | ||
| actions = { | ||
| val inCart = (state as? FruittieViewModel.State.Content)?.inCart ?: 0 | ||
| Text(stringResource(R.string.in_cart, inCart)) | ||
| Spacer(Modifier.width(8.dp)) | ||
| }, | ||
mlykotom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| navigationIcon = { | ||
| IconButton(onClick = onNavBarBack) { | ||
| Icon( | ||
| imageVector = Icons.AutoMirrored.Filled.ArrowBack, | ||
| contentDescription = stringResource(R.string.navigate_back), | ||
| ) | ||
| } | ||
| }, | ||
| ) | ||
| }, | ||
| floatingActionButton = { | ||
| // Check if state is loaded | ||
| if (state !is FruittieViewModel.State.Content) return@Scaffold | ||
|
|
||
| FloatingActionButton( | ||
| shape = MaterialTheme.shapes.extraLarge, | ||
| onClick = { addToCart(state.fruittie) } | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.padding( | ||
| horizontal = 16.dp | ||
| ), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Icon( | ||
| Icons.Filled.ShoppingCart, | ||
| contentDescription = null | ||
| ) | ||
| Spacer(Modifier.width(8.dp)) | ||
| Text(text = stringResource(R.string.add_to_cart)) | ||
| } | ||
| } | ||
| } | ||
| ) { | ||
| Column( | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| modifier = Modifier | ||
| .padding(it) | ||
| .fillMaxSize() | ||
| ) { | ||
| when (state) { | ||
| FruittieViewModel.State.Loading -> CircularProgressIndicator() | ||
| is FruittieViewModel.State.Content -> { | ||
| Text(state.fruittie.fullName) | ||
| Text(state.fruittie.calories) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.