Skip to content

Instantly share code, notes, and snippets.

View catalinghita8's full-sized avatar

Catalin Ghita catalinghita8

View GitHub Profile
@Composable
fun ProfileCardComposable() {
Card(
modifier = Modifier
.wrapContentSize()
.clip(RoundedCornerShape(4.dp))
.background(color = Helper.getWhiteColor())
.padding(16.dp),
) {
Row(modifier = Modifier.height(intrinsicSize = IntrinsicSize.Max)) {
data class UserProfile constructor(val name: String, val status: Boolean, val pictureUrl: String)
val userProfileList = arrayListOf(
UserProfile(
name = "Michaela Runnings",
status = true,
"https://images.unsplash.com/photo-1485290334039-a3c69043e517?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80"
),
UserProfile(
name = "John Pestridge",
@Composable
fun ProfileCardComposable(userProfile: UserProfile) {
val onlineStatus = remember { mutableStateOf(userProfile.isOnline) }
Card(
Modifier.
...
.background(color = Helper.getWhiteColor())
.clickable(onClick = { onlineStatus.value = onlineStatus.value.not() })
.padding(16.dp)
) {
@Composable
fun ProfileContentComposable(onlineStatus: MutableState<Boolean>,
name: String,
lastActivityMinutes: Int) {
Column( ... )
) { ...
Text(
text = if (onlineStatus.value)
"Active now"
else
@Composable
fun ProfilePictureComposable(onlineStatus: MutableState<Boolean>,
pictureDrawableId: Int) {
Card( ...
border = BorderStroke(
2.dp,
color = if (onlineStatus.value)
Helper.getGreenColor()
else
Helper.getRedColor()
@Composable
fun ProfileCardComposable(userProfile: UserProfile) {
val onlineStatus = remember { mutableStateOf(userProfile.isOnline) }
Card(...) {
Row(...) {
ProfilePictureComposable(onlineStatus, userProfile.profilePictureDrawableId)
ProfileContentComposable(onlineStatus, userProfile.name, userProfile.lastActivityMinutes)
}
}
}
@Composable
fun ProfilePictureComposable(pictureDrawableId: Int) {
Card( ... ) {
Image(
painter = painterResource(id = pictureDrawableId),
...
)
}
}
@Composable
fun ProfileCardComposable(userProfile: UserProfile) {
Card(...) {
Row(...) {
ProfilePictureComposable(userProfile.profilePictureDrawableId)
ProfileContentComposable(userProfile.name, userProfile.lastActivityMinutes)
}
}
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val mockUserProfile = UserProfile.getMockProfileUser()
setContent { MainActivityComposable(mockUserProfile) }
}
}
@Composable
fun MainActivityComposable(userProfile: UserProfile) {
data class UserProfile(
val name: String,
val profilePictureDrawableId: Int,
val lastActivityMinutes: Int,
val isOnline: Boolean
) {
companion object {
fun getMockProfileUser() = UserProfile("Catalin Ghita",
R.drawable.profile_pic,
2,