-
-
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 #187 from Devendra34/feature/update_profile_compose
Migrate update profile feature from XML to Jetpack Compose
- Loading branch information
Showing
8 changed files
with
345 additions
and
184 deletions.
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
...src/main/java/com/hieuwu/groceriesstore/presentation/updateprofile/UpdateProfileScreen.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,74 @@ | ||
package com.hieuwu.groceriesstore.presentation.updateprofile | ||
|
||
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.runtime.collectAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.hieuwu.groceriesstore.domain.models.UserModel | ||
import com.hieuwu.groceriesstore.presentation.account.DemoUser | ||
import com.hieuwu.groceriesstore.presentation.updateprofile.widgets.UpdateProfileAppBar | ||
import com.hieuwu.groceriesstore.presentation.updateprofile.widgets.UpdateProfileScreenContent | ||
|
||
@Composable | ||
fun UpdateProfileScreen( | ||
modifier: Modifier = Modifier, | ||
onBackClick: () -> Unit = {}, | ||
viewModel: UpdateProfileViewModel = hiltViewModel(), | ||
) { | ||
val user = viewModel.user.collectAsState() | ||
|
||
UpdateProfileScreenView( | ||
modifier = modifier, | ||
user = user.value, | ||
onBackClick = onBackClick, | ||
onSaveClick = { viewModel.updateUserProfile() }, | ||
onNameChanged = { viewModel.name = it }, | ||
onPhoneChanged = { viewModel.phoneNumber = it }, | ||
onEmailChanged = { viewModel.email = it }, | ||
onAddressChanged = { viewModel.address = it }, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun UpdateProfileScreenView( | ||
modifier: Modifier = Modifier, | ||
user: UserModel?, | ||
onBackClick: () -> Unit = {}, | ||
onSaveClick: () -> Unit = {}, | ||
onNameChanged: (String) -> Unit = {}, | ||
onPhoneChanged: (String) -> Unit = {}, | ||
onEmailChanged: (String) -> Unit = {}, | ||
onAddressChanged: (String) -> Unit = {}, | ||
) { | ||
|
||
Scaffold( | ||
modifier = modifier, | ||
topBar = { | ||
UpdateProfileAppBar( | ||
onBackClick = onBackClick, | ||
onSaveClick = onSaveClick, | ||
) | ||
} | ||
) { contentPadding -> | ||
UpdateProfileScreenContent( | ||
modifier = Modifier.padding(contentPadding), | ||
user = user, | ||
onNameChanged = onNameChanged, | ||
onPhoneChanged = onPhoneChanged, | ||
onEmailChanged = onEmailChanged, | ||
onAddressChanged = onAddressChanged, | ||
) | ||
} | ||
} | ||
|
||
@Preview(showSystemUi = true) | ||
@Composable | ||
private fun UpdateProfileScreenPreview() { | ||
UpdateProfileScreenView( | ||
user = DemoUser, | ||
) | ||
} |
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
70 changes: 70 additions & 0 deletions
70
.../java/com/hieuwu/groceriesstore/presentation/updateprofile/widgets/UpdateProfileAppBar.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,70 @@ | ||
package com.hieuwu.groceriesstore.presentation.updateprofile.widgets | ||
|
||
import androidx.compose.material3.CenterAlignedTopAppBar | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.material3.TopAppBarDefaults | ||
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.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.hieuwu.groceriesstore.R | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun UpdateProfileAppBar( | ||
modifier: Modifier = Modifier, | ||
onBackClick: () -> Unit, | ||
onSaveClick: () -> Unit | ||
) { | ||
CenterAlignedTopAppBar( | ||
modifier = modifier, | ||
navigationIcon = { | ||
IconButton(onClick = onBackClick) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_detail_back), | ||
tint = Color.Unspecified, | ||
contentDescription = null, | ||
) | ||
} | ||
}, | ||
title = { | ||
Text( | ||
text = stringResource(R.string.update_profile), | ||
maxLines = 1, | ||
overflow = TextOverflow.Ellipsis, | ||
color = Color.White, | ||
style = MaterialTheme.typography.titleLarge | ||
) | ||
}, | ||
actions = { | ||
TextButton(onClick = onSaveClick) { | ||
Text( | ||
text = stringResource(R.string.save).uppercase(), | ||
style = MaterialTheme.typography.titleMedium, | ||
color = Color.White, | ||
) | ||
} | ||
}, | ||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors( | ||
containerColor = colorResource(id = R.color.colorPrimary) | ||
), | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun UpdateProfileAppBarPreview() { | ||
UpdateProfileAppBar( | ||
onBackClick = {}, | ||
onSaveClick = {}, | ||
) | ||
} |
Oops, something went wrong.