Skip to content

Commit

Permalink
Addressing small change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
FelberMartin committed Nov 26, 2024
1 parent f9935f9 commit c0473c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.tum.informatics.www1.artemis.native_app.feature.metis.shared.ui.profile_picture

import android.graphics.drawable.Drawable
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -29,13 +28,17 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.remote_images.ProfileP
const val TEST_TAG_PROFILE_PICTURE_IMAGE = "TEST_TAG_PROFILE_PICTURE_IMAGE"
const val TEST_TAG_PROFILE_PICTURE_INITIALS = "TEST_TAG_PROFILE_PICTURE_INITIALS"

private const val BoxSizeToFontSizeMultiplier = 0.16f


@Composable
fun ProfilePicture(
modifier: Modifier,
profilePictureData: ProfilePictureData,
profilePictureImageProvider: ProfilePictureImageProvider?,
) {
// TODO: Add onClick that opens a dialog with info about the user, see iOS
// https://github.com/ls1intum/artemis-android/issues/154
when(profilePictureData) {
is ProfilePictureData.Image -> {
if (profilePictureImageProvider != null) {
Expand Down Expand Up @@ -75,9 +78,7 @@ fun ProfilePictureImage(
)
}

val resultData = loadAsyncImageDrawable(request = request)

when (resultData.dataState) {
when (val resultDataState = loadAsyncImageDrawable(request = request).dataState) {
is DataState.Failure -> {
InitialsPlaceholder(
modifier = modifier,
Expand All @@ -91,7 +92,7 @@ fun ProfilePictureImage(
)
}
is DataState.Success -> {
val loadedDrawable = (resultData.dataState as DataState.Success<Drawable>).data
val loadedDrawable = resultDataState.data

val painter = remember(loadedDrawable) {
val bitmap = loadedDrawable.toBitmap().asImageBitmap()
Expand Down Expand Up @@ -129,7 +130,7 @@ fun InitialsPlaceholder(
Text(
text = profilePictureData.initials,
color = Color.White,
fontSize = boxSize.intValue.sp.nonScaledSp * 0.16f,
fontSize = boxSize.intValue.sp.nonScaledSp * BoxSizeToFontSizeMultiplier,
fontWeight = FontWeight.Bold
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ sealed class ProfilePictureData {
}

// The following util functions are copied from the Artemis webapp implementation.
// Sources:
// https://github.com/ls1intum/Artemis/blob/fa32c243b568c92aa5e075e8176abdc7c7452444/src/main/webapp/app/utils/text.utils.ts
// https://github.com/ls1intum/Artemis/blob/fa32c243b568c92aa5e075e8176abdc7c7452444/src/main/webapp/app/utils/color.utils.ts

/**
* Returns 2 capitalized initials of a given string.
Expand Down

0 comments on commit c0473c4

Please sign in to comment.