完善个人中心

master
pan 4 years ago
parent cf254306cf
commit 589f19b69d
  1. 34
      app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt
  2. 208
      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(
val context= LocalContext.current background = { Background(image = BackgroundImage.Center, alpha = 0.5F) },
mainMenu = MainMenu.Center,
nav = navController
) {
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()
@ -151,7 +222,7 @@ class MainActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun RegisterAssociation() { private fun RegisterAssociation() {
val context= LocalContext.current val context = LocalContext.current
Row( Row(
horizontalArrangement = Arrangement.End, horizontalArrangement = Arrangement.End,
modifier = Modifier modifier = Modifier
@ -175,52 +246,68 @@ 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()
LazyColumn(state = listState) { LazyColumn(state = listState) {
associationList?.chunked(2)?.forEach { associationList?.chunked(2)?.forEach {
item{ item {
Row { Row {
Spacer(modifier = Modifier.weight(0.1F)) Spacer(modifier = Modifier.weight(0.1F))
Box(modifier = Modifier.weight(0.35F)) { Box(modifier = Modifier.weight(0.35F)) {
Association(associationDto = it[0]) Association(associationDto = it[0])
} }
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
if(it.size==2) { if (it.size == 2) {
Box(modifier = Modifier.weight(0.35F)) { Box(modifier = Modifier.weight(0.35F)) {
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)
)
} }
} }
} }
if(listState.layoutInfo.totalItemsCount-listState.firstVisibleItemIndex==model.associationListSize/2-1){ if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.associationListSize / 2 - 1) {
model.loadMore { scaffoldModel.update(message=it) } model.loadMore { scaffoldModel.update(message = it) }
} }
} }
@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
@ -270,7 +377,7 @@ class MainActivity : ComponentActivity() {
.padding(10.dp) .padding(10.dp)
) { ) {
IconButton(onClick = { IconButton(onClick = {
mainViewModel.openNotification { scaffoldModel.update(message=it) } mainViewModel.openNotification { scaffoldModel.update(message = it) }
}) { }) {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_notification), painter = painterResource(id = R.drawable.ic_notification),
@ -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
@ -370,14 +481,15 @@ class MainActivity : ComponentActivity() {
@Composable @Composable
private fun PosterWithDesc(model: CarouselViewModel = viewModel()) { private fun PosterWithDesc(model: CarouselViewModel = viewModel()) {
Carousel(model = model) { Carousel(model = model) {
val context= LocalContext.current val context = LocalContext.current
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