Skip to content

Commit

Permalink
Made some changes in the Profile Image
Browse files Browse the repository at this point in the history
  • Loading branch information
aritra-tech committed May 17, 2024
1 parent fad7f47 commit b6f2de4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.geekymusketeers.uncrack.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.size
Expand All @@ -10,7 +11,12 @@ import androidx.compose.material.icons.outlined.Add
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -19,30 +25,54 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.geekymusketeers.uncrack.R
import com.geekymusketeers.uncrack.sharedViewModel.UserViewModel
import com.geekymusketeers.uncrack.ui.theme.BackgroundLight
import com.geekymusketeers.uncrack.ui.theme.OnPrimaryContainerLight
import com.geekymusketeers.uncrack.ui.theme.PrimaryLight
import com.geekymusketeers.uncrack.ui.theme.SurfaceLight
import com.geekymusketeers.uncrack.ui.theme.bold22
import com.geekymusketeers.uncrack.ui.theme.bold24

@Composable
fun ProfileContainer(
modifier: Modifier = Modifier,
onEditButtonClick: () -> Unit
userViewModel: UserViewModel,
modifier: Modifier = Modifier
) {
Box(contentAlignment = Alignment.BottomEnd) {
Image(
painter = painterResource(id = R.drawable.no_user_profile_picture),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier
.size(100.dp)
.clip(CircleShape)
)

Button(
modifier = Modifier.size(25.dp),
shape = CircleShape,
colors = ButtonDefaults.buttonColors(containerColor = Color.Blue),
contentPadding = PaddingValues(0.dp),
onClick = { onEditButtonClick() }
) {
Icon(imageVector = Icons.Outlined.Add, contentDescription = null, tint = Color.White)
var initials by remember { mutableStateOf("") }
val userData = userViewModel.state.value
initials = getInitials(userData.name)


Box(
contentAlignment = Alignment.Center,
modifier = modifier
.size(100.dp)
.clip(CircleShape)
.background(PrimaryLight)
) {
if (initials.isEmpty()) {
Image(
painter = painterResource(id = R.drawable.no_user_profile_picture),
contentDescription = null,
contentScale = ContentScale.Crop
)
} else {
Text(
text = initials,
style = bold24.copy(SurfaceLight)
)
}
}
}

fun getInitials(name: String): String {
val nameParts = name.trim().split(' ')
var initials = nameParts[0].first().uppercaseChar().toString()
if (nameParts.size > 1) {
initials += nameParts[1].first()
} else if (nameParts[0].length > 1) {
initials += nameParts[0][1]
}
return initials
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ fun ProfileScreen(
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
ProfileContainer {
}
ProfileContainer(
userViewModel
)

Spacer(modifier = Modifier.height(22.dp))

Text(
text = userData.email,
text = userData.name,
style = medium22.copy(color = OnSurfaceLight)
)
}
Expand Down

0 comments on commit b6f2de4

Please sign in to comment.