完善个人中心

master
pan 4 years ago
parent cf254306cf
commit 589f19b69d
  1. 34
      app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt
  2. 186
      app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt

@ -9,6 +9,8 @@ import com.gyf.csams.R
import com.gyf.csams.uikit.ScrollList import com.gyf.csams.uikit.ScrollList
import com.gyf.csams.uikit.SendInterface import com.gyf.csams.uikit.SendInterface
import com.gyf.csams.uikit.StringForm import com.gyf.csams.uikit.StringForm
import com.gyf.csams.util.randomChinese
import com.gyf.csams.util.randomNum
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -192,10 +194,42 @@ class ListViewModel: ScrollList<AssociationDto>() {
} }
} }
/**
* 我的信息
*
* @property studentId 学号
* @property name 姓名
* @property duty 职务
* @property headImg 头像
* @property desc 个人简介
*/
data class InfoVo(val studentId:String,val name:String,val duty:String,val headImg:String,val desc:String)
/** /**
* 个人中心 * 个人中心
* *
*/ */
class CenterViewModel:ViewModel(){ class CenterViewModel:ViewModel(){
val myAssociationDesc="我的社团" val myAssociationDesc="我的社团"
val myJoinActivity="我参加的社团活动"
val myLikeActivity="我点赞的社团活动"
val myCollectActivity="我收藏的社团活动"
private val _info=MutableLiveData<InfoVo>()
val info:LiveData<InfoVo> = _info
init {
load()
}
private fun load(){
viewModelScope.launch {
_info.value= InfoVo(studentId = randomNum(),
name = randomChinese(3),
duty = randomChinese(3),
headImg = "",
desc = randomChinese(10))
}
}
} }

@ -74,23 +74,96 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun Center(model:CenterViewModel= viewModel(), scaffoldModel: ScaffoldModel= viewModel(), navController: NavHostController){ private fun Center(
MainFrame(background = { Background(image = BackgroundImage.Center,alpha = 0.5F) }, mainMenu = MainMenu.Center, nav = navController) { model: CenterViewModel = viewModel(),
Column(modifier = Modifier scaffoldModel: ScaffoldModel = viewModel(),
.weight(0.33F) navController: NavHostController
.fillMaxWidth(),verticalArrangement = Arrangement.Bottom) { ) {
Card(backgroundColor = MaterialTheme.colors.background) { MainFrame(
background = { Background(image = BackgroundImage.Center, alpha = 0.5F) },
mainMenu = MainMenu.Center,
nav = navController
) {
val context = LocalContext.current val context = LocalContext.current
val info by model.info.observeAsState()
Column(
modifier = Modifier.weight(0.3F).padding(10.dp),
) {
info?.let {
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable(onClick = { .weight(0.7F)
.border(width = 1.dp, color = MaterialTheme.colors.background),
horizontalArrangement = Arrangement.SpaceBetween) {
Image(
painter = painterResource(
id = R.drawable.ic_launcher_foreground
),
contentDescription = null,
modifier = Modifier
.weight(0.4F)
.fillMaxHeight()
)
Column(
modifier = Modifier
.weight(0.4F)
.fillMaxHeight()
.border(width = 1.dp, color = MaterialTheme.colors.background),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = it.name)
Text(text = it.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 = it.desc)
}
}
}
}
Column(
modifier = Modifier.weight(0.7F),
verticalArrangement = Arrangement.SpaceEvenly
) {
CenterMenuItem(text = model.myAssociationDesc) {
context.startActivity(Intent(context, AssociationActivity::class.java)) context.startActivity(Intent(context, AssociationActivity::class.java))
}),verticalAlignment = Alignment.CenterVertically) {
Spacer(modifier = Modifier.weight(0.33F))
Row(modifier = Modifier.weight(0.33F),horizontalArrangement = Arrangement.Center) {
Text(text = model.myAssociationDesc)
} }
Row(modifier = Modifier.weight(0.33F),horizontalArrangement = Arrangement.End) { CenterMenuItem(text = model.myJoinActivity)
CenterMenuItem(text = model.myLikeActivity)
CenterMenuItem(text = model.myCollectActivity)
}
}
}
@Composable
private fun CenterMenuItem(text: String, onClick: () -> Unit = {}) {
Card(backgroundColor = MaterialTheme.colors.background) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onClick),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier)
Row {
Text(text = text)
}
Row {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_arrow_right), painter = painterResource(id = R.drawable.ic_arrow_right),
contentDescription = null, contentDescription = null,
@ -98,12 +171,6 @@ class MainActivity : ComponentActivity() {
) )
} }
} }
}
}
Spacer(modifier = Modifier
.weight(0.66F)
.fillMaxWidth())
} }
} }
@ -112,7 +179,11 @@ class MainActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun Main(navController: NavHostController) { private fun Main(navController: NavHostController) {
MainFrame(background = { Background(image = BackgroundImage.Main) }, mainMenu = MainMenu.Main, nav = navController) { MainFrame(
background = { Background(image = BackgroundImage.Main) },
mainMenu = MainMenu.Main,
nav = navController
) {
Column(modifier = Modifier.weight(0.33F)) { Column(modifier = Modifier.weight(0.33F)) {
Notification() Notification()
MessageBoard() MessageBoard()
@ -175,7 +246,10 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun AssociationListBody(model: ListViewModel = viewModel(),scaffoldModel: ScaffoldModel= viewModel()) { private fun AssociationListBody(
model: ListViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel()
) {
val associationList: MutableList<AssociationDto>? by model.associationDto.observeAsState() val associationList: MutableList<AssociationDto>? by model.associationDto.observeAsState()
val listState = rememberLazyListState() val listState = rememberLazyListState()
@ -193,15 +267,19 @@ class MainActivity : ComponentActivity() {
Association(associationDto = it[1]) Association(associationDto = it[1])
} }
} else { } else {
Box(modifier = Modifier Box(
modifier = Modifier
.weight(0.35F) .weight(0.35F)
.border(width = 1.dp, color = MaterialTheme.colors.onBackground)) .border(width = 1.dp, color = MaterialTheme.colors.onBackground)
)
} }
Spacer(modifier = Modifier.weight(0.1F)) Spacer(modifier = Modifier.weight(0.1F))
} }
Spacer(modifier = Modifier Spacer(
modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(10.dp)) .height(10.dp)
)
} }
} }
} }
@ -214,13 +292,22 @@ class MainActivity : ComponentActivity() {
@Composable @Composable
private fun Association(associationDto: AssociationDto) { private fun Association(associationDto: AssociationDto) {
val context = LocalContext.current val context = LocalContext.current
Card(modifier = Modifier.clickable(onClick = { context.startActivity(Intent(context,AssociationActivity::class.java)) })) { Card(modifier = Modifier.clickable(onClick = {
context.startActivity(
Intent(
context,
AssociationActivity::class.java
)
)
})) {
Image( Image(
painter = painterResource(id = R.drawable.association_list_border), painter = painterResource(id = R.drawable.association_list_border),
contentDescription = null contentDescription = null
) )
Row(modifier = Modifier.fillMaxWidth(), Row(
horizontalArrangement = Arrangement.Center) { modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(text = associationDto.name) Text(text = associationDto.name)
} }
@ -233,18 +320,35 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun AssociationSearch(model: ListViewModel = viewModel(),scaffoldModel: ScaffoldModel= viewModel()) { private fun AssociationSearch(
model: ListViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel()
) {
Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) { Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) {
Column { Column {
BaseTextField(form = model.name,singeLine = true,modifier = Modifier.padding(horizontal = 10.dp)) BaseTextField(
BaseTextField(form = model.desc,singeLine = true,modifier = Modifier.padding(horizontal = 10.dp)) form = model.name,
singeLine = true,
modifier = Modifier.padding(horizontal = 10.dp)
)
BaseTextField(
form = model.desc,
singeLine = true,
modifier = Modifier.padding(horizontal = 10.dp)
)
Spacer( Spacer(
modifier = Modifier.height(10.dp) modifier = Modifier.height(10.dp)
) )
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) { Row(
OutlinedButton(onClick = { model.search { scaffoldModel.update(message=it) } }, modifier = Modifier.width(100.dp)) { horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth()
) {
OutlinedButton(
onClick = { model.search { scaffoldModel.update(message = it) } },
modifier = Modifier.width(100.dp)
) {
Text(text = model.searchDesc) Text(text = model.searchDesc)
} }
} }
@ -262,7 +366,10 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun Notification(mainViewModel: MainViewModel= viewModel(),scaffoldModel: ScaffoldModel= viewModel()) { private fun Notification(
mainViewModel: MainViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel()
) {
Row( Row(
horizontalArrangement = Arrangement.End, horizontalArrangement = Arrangement.End,
modifier = Modifier modifier = Modifier
@ -306,7 +413,11 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun MessageBoard(model: MarqueeViewModel = viewModel(),mainViewModel:MainViewModel= viewModel(),scaffoldModel: ScaffoldModel= viewModel()) { private fun MessageBoard(
model: MarqueeViewModel = viewModel(),
mainViewModel: MainViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel()
) {
MyBorder { MyBorder {
Row( Row(
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
@ -374,10 +485,11 @@ class MainActivity : ComponentActivity() {
Column(modifier = Modifier.clickable(onClick = { Column(modifier = Modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java)) context.startActivity(Intent(context, ActivityDetailActivity::class.java))
})) { })) {
Poster(modifier = Modifier Poster(
modifier = Modifier
.weight(0.6F) .weight(0.6F)
.fillMaxWidth() .fillMaxWidth(), id = it
,id = it) )
DescCard( DescCard(
modifier = Modifier modifier = Modifier

Loading…
Cancel
Save