You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.9 KiB
95 lines
2.9 KiB
package com.gyf.lib.uikit
|
|
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.border
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.Card
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.ImageBitmap
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.unit.dp
|
|
import com.gyf.lib.util.ImageUtil
|
|
|
|
|
|
abstract class PersonInfoVo {
|
|
abstract val name: String
|
|
abstract val duty: String
|
|
abstract val headImg: String
|
|
abstract val desc: String
|
|
}
|
|
|
|
@Composable
|
|
fun Profile(
|
|
modifier: Modifier,
|
|
personInfoVo: PersonInfoVo,
|
|
duty: @Composable () -> Unit = { Text(text = personInfoVo.duty) }
|
|
) {
|
|
var headImg: ImageBitmap? by remember {
|
|
mutableStateOf(null)
|
|
}
|
|
val context = LocalContext.current
|
|
LaunchedEffect(personInfoVo.headImg) {
|
|
headImg = ImageUtil.getImage(context = context, personInfoVo.headImg)
|
|
}
|
|
Column(
|
|
modifier = modifier,
|
|
) {
|
|
Row(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(0.7F)
|
|
.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
) {
|
|
headImg.let {
|
|
if (it != null) {
|
|
Image(
|
|
bitmap = it,
|
|
contentDescription = null,
|
|
modifier = Modifier
|
|
.weight(0.4F)
|
|
.fillMaxHeight()
|
|
)
|
|
} else {
|
|
Box(
|
|
modifier = Modifier
|
|
.weight(0.4F)
|
|
.fillMaxHeight(),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Text(text = "头像加载失败")
|
|
}
|
|
}
|
|
}
|
|
Column(
|
|
modifier = Modifier
|
|
.weight(0.4F)
|
|
.fillMaxHeight()
|
|
.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
|
|
verticalArrangement = Arrangement.SpaceEvenly,
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
Text(text = personInfoVo.name)
|
|
duty()
|
|
}
|
|
}
|
|
|
|
Spacer(modifier = Modifier.weight(0.05F))
|
|
|
|
Card(
|
|
backgroundColor = MaterialTheme.colors.background,
|
|
modifier = Modifier.weight(0.15F)
|
|
) {
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.Center
|
|
) {
|
|
Text(text = personInfoVo.desc)
|
|
}
|
|
}
|
|
}
|
|
} |