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.
135 lines
4.5 KiB
135 lines
4.5 KiB
package com.gyf.csams.message.ui
|
|
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
import androidx.compose.material.Card
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.text.SpanStyle
|
|
import androidx.compose.ui.text.buildAnnotatedString
|
|
import androidx.compose.ui.text.withStyle
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.gyf.csams.message.model.*
|
|
import com.gyf.csams.uikit.*
|
|
import com.gyf.csams.util.format
|
|
|
|
/**
|
|
* 系统通知
|
|
*
|
|
*/
|
|
class SysMessageActivity : ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContent {
|
|
Body { _ ->
|
|
MainFrame(background = {
|
|
Background(
|
|
image = BackgroundImage.ActivityMessage,
|
|
alpha = 0.6F
|
|
)
|
|
}) {
|
|
TextTopAppBar(modifier = Modifier.weight(0.1F), title = MessageType.System.desc)
|
|
Spacer(modifier = Modifier.weight(0.05F))
|
|
MessageList(modifier = Modifier.weight(0.8F))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun MessageList(
|
|
modifier: Modifier = Modifier,
|
|
model: SysMessageViewModel = viewModel()
|
|
) {
|
|
val listState = rememberLazyListState()
|
|
val list by model.data.observeAsState()
|
|
Box(modifier = modifier.padding(10.dp)) {
|
|
LazyColumn(state = listState) {
|
|
list?.forEach {
|
|
item {
|
|
MessageItem(content = it)
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun MessageItem(modifier: Modifier = Modifier, content: MessageContent) {
|
|
Card(modifier = modifier, backgroundColor = MaterialTheme.colors.background) {
|
|
Column(modifier = Modifier.padding(10.dp)) {
|
|
Text(text = content.type.desc, style = MaterialTheme.typography.h5)
|
|
Spacer(modifier = Modifier.height(5.dp))
|
|
|
|
Card(
|
|
backgroundColor = MaterialTheme.colors.background,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(10.dp)
|
|
) {
|
|
when (content) {
|
|
is JoinContent -> JoinMessage(content = content)
|
|
is ActCheckContent -> ActCheckMessage(content = content)
|
|
is RenameContent -> RenameMessage(content = content)
|
|
}
|
|
}
|
|
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
|
Text(text = content.createTime.format())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun JoinMessage(content: JoinContent) {
|
|
Text(buildAnnotatedString {
|
|
withStyle(
|
|
style = MaterialTheme.typography.subtitle1.toSpanStyle()
|
|
.copy(color = MaterialTheme.colors.primary)
|
|
) {
|
|
append(content.studentName)
|
|
}
|
|
append("申请进入社团")
|
|
})
|
|
}
|
|
|
|
@Composable
|
|
private fun ActCheckMessage(content: ActCheckContent) {
|
|
Text(buildAnnotatedString {
|
|
append("\"")
|
|
withStyle(style = SpanStyle(color = MaterialTheme.colors.primary)) {
|
|
append(content.activityName)
|
|
}
|
|
append("\"活动审核不通过")
|
|
})
|
|
}
|
|
|
|
@Composable
|
|
private fun RenameMessage(content: RenameContent) {
|
|
Text(buildAnnotatedString {
|
|
withStyle(style = SpanStyle(color = MaterialTheme.colors.primary)) {
|
|
append(content.oldAssociationName)
|
|
}
|
|
append("重命名为")
|
|
withStyle(style = SpanStyle(color = MaterialTheme.colors.secondary)) {
|
|
append(content.newAssociationName)
|
|
}
|
|
append("审核通过")
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
|