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.
334 lines
11 KiB
334 lines
11 KiB
package com.gyf.csams.association.ui
|
|
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.border
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
import androidx.compose.material.*
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.layout.ContentScale
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.res.painterResource
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import androidx.navigation.compose.NavHost
|
|
import androidx.navigation.compose.composable
|
|
import com.gyf.csams.R
|
|
import com.gyf.csams.association.model.*
|
|
import com.gyf.csams.uikit.*
|
|
import com.gyf.csams.uikit.theme.CSAMSTheme
|
|
|
|
/**
|
|
* 社团界面
|
|
*
|
|
*/
|
|
class AssociationActivity: ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContent {
|
|
CSAMSTheme {
|
|
Body {
|
|
nav, scaffoldState ->
|
|
val context= LocalContext.current as AssociationActivity
|
|
val model:AssociationViewModel= viewModel()
|
|
val startMenu=AssociationMenu.main
|
|
val menu:AssociationMenu by model.currentMenu.observeAsState(startMenu)
|
|
|
|
Column {
|
|
AssociationAppBar(menu = menu,nav = nav,back = { context.onBackPressed() }){
|
|
//TODO 显示下拉菜单
|
|
}
|
|
NavHost(navController = nav, startDestination = startMenu.name) {
|
|
composable(AssociationMenu.member.name){
|
|
model.clickMenu(AssociationMenu.member)
|
|
Member()
|
|
ShowSnackbar(scaffoldState = scaffoldState)
|
|
}
|
|
composable(AssociationMenu.main.name){
|
|
model.clickMenu(AssociationMenu.main)
|
|
Main()
|
|
ShowSnackbar(scaffoldState = scaffoldState)
|
|
}
|
|
composable(AssociationMenu.list.name){
|
|
model.clickMenu(AssociationMenu.list)
|
|
AssociationList()
|
|
ShowSnackbar(scaffoldState = scaffoldState)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 社团成员
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun Member(){
|
|
MainFrame(background = { Background(image = BackgroundImage.association_main) }) {
|
|
val searchWeight=0.2F
|
|
Search(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(searchWeight))
|
|
MemberList(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(1 - searchWeight))
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 检索成员
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun Search(modifier:Modifier=Modifier, model: MemberViewModel= viewModel(), scaffoldModel: ScaffoldModel= viewModel()){
|
|
Column(modifier = modifier.fillMaxSize()) {
|
|
Spacer(modifier = Modifier.weight(0.5F))
|
|
Row(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(0.5F),verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
val textFieldWeight=0.4F
|
|
val buttonWeight=0.2F
|
|
val spaceWeight=(1-textFieldWeight-buttonWeight)/3
|
|
Spacer(modifier = Modifier.weight((spaceWeight)))
|
|
BaseTextField(modifier = Modifier.weight(textFieldWeight),form = model.name,singeLine = true)
|
|
Spacer(modifier = Modifier.weight(spaceWeight))
|
|
OutlinedButton(onClick = { model.search { scaffoldModel.update(message=it) } },modifier = Modifier.weight(buttonWeight)) {
|
|
Text(text = model.search)
|
|
}
|
|
Spacer(modifier = Modifier.weight(spaceWeight))
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 成员列表
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun MemberList(modifier: Modifier=Modifier, model: MemberViewModel=viewModel(), scaffoldModel: ScaffoldModel= viewModel()){
|
|
val list:MutableList<MemberVo>? by model.memberList.observeAsState()
|
|
val listState= rememberLazyListState()
|
|
LazyColumn(state = listState,modifier = modifier) {
|
|
list?.forEach {
|
|
item {
|
|
Column {
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
Row{
|
|
val weight = 1F / 3
|
|
Spacer(modifier = Modifier.weight(weight))
|
|
Card(
|
|
modifier = Modifier.weight(weight),
|
|
backgroundColor = MaterialTheme.colors.background
|
|
) {
|
|
Text(text = it.name)
|
|
}
|
|
Spacer(modifier = Modifier.weight(weight))
|
|
}
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
Divider(color = MaterialTheme.colors.background)
|
|
}
|
|
}
|
|
}
|
|
item {
|
|
Row(horizontalArrangement = Arrangement.Center,modifier = Modifier.fillMaxWidth()) {
|
|
IconButton(onClick = { model.loadMore{
|
|
scaffoldModel.update(message=it)
|
|
} }) {
|
|
Icon(painter = painterResource(id = R.drawable.ic_arrow_down), contentDescription = null)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 社团主页
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun Main(){
|
|
MainFrame(background = {
|
|
Background(image = BackgroundImage.association_main,alpha = 0.7F)
|
|
}) {
|
|
val nameW=0.1F
|
|
val cardW=0.66F*0.4F
|
|
Name(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(nameW))
|
|
DescCard(
|
|
modifier = Modifier
|
|
.weight(cardW)
|
|
.fillMaxWidth()
|
|
)
|
|
Commander(
|
|
modifier = Modifier.weight(cardW)
|
|
)
|
|
Showcase(modifier = Modifier.weight(1F-nameW-cardW-cardW))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 社团名字
|
|
*
|
|
* @param modifier
|
|
*/
|
|
@Composable
|
|
private fun Name(modifier: Modifier){
|
|
Box(modifier = modifier) {
|
|
Image(
|
|
painter = painterResource(id = R.drawable.association_name_border),
|
|
contentDescription = null,
|
|
contentScale = ContentScale.FillBounds,
|
|
modifier=Modifier.fillMaxSize()
|
|
)
|
|
Column{
|
|
Spacer(modifier = Modifier.weight(1.7F / 3))
|
|
Row(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(1F / 3),
|
|
horizontalArrangement = Arrangement.Center) {
|
|
Text(text = "社团名字")
|
|
}
|
|
Spacer(modifier = Modifier.weight(0.3F / 3))
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 团长名字
|
|
*
|
|
* @param modifier
|
|
*/
|
|
@Composable
|
|
private fun Commander(modifier: Modifier){
|
|
Box(modifier=modifier,contentAlignment = Alignment.Center){
|
|
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.Center) {
|
|
|
|
Image(painter = painterResource(id = R.drawable.association_persion_name_border),
|
|
contentDescription = null
|
|
)
|
|
}
|
|
Text(text = "团长")
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 风采展示区
|
|
*
|
|
* @param modifier
|
|
*/
|
|
@Composable
|
|
private fun Showcase(modifier: Modifier){
|
|
Box(modifier = modifier,contentAlignment = Alignment.Center) {
|
|
Image(painter = painterResource(id = R.drawable.showcase_border),
|
|
contentDescription = null,
|
|
modifier=Modifier.fillMaxSize())
|
|
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = null)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 活动列表
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun AssociationList(){
|
|
MainFrame(background = { Background(image = BackgroundImage.association_main,alpha = 07F) }) {
|
|
val onGoWeight=0.3F
|
|
OngoingActivity(modifier = Modifier
|
|
.weight(onGoWeight)
|
|
.fillMaxWidth())
|
|
HistoryActivityList(modifier = Modifier
|
|
.fillMaxWidth()
|
|
.weight(1 - onGoWeight)
|
|
.border(width = 1.dp, color = MaterialTheme.colors.onBackground))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 进行中的活动
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun OngoingActivity(modifier: Modifier=Modifier){
|
|
Row(modifier = modifier,horizontalArrangement = Arrangement.Center) {
|
|
val weight=0.5F
|
|
val spaceWeight=(1-0.5F)/2
|
|
Spacer(modifier = Modifier.weight(spaceWeight))
|
|
Poster(id = R.drawable.ic_launcher_foreground,modifier = Modifier.weight(weight))
|
|
Spacer(modifier = Modifier.weight(spaceWeight))
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 历史活动列表
|
|
*
|
|
* @param modifier
|
|
*/
|
|
@Composable
|
|
private fun HistoryActivityList(modifier: Modifier,model:HistoryActViewModel= viewModel(),scaffoldModel: ScaffoldModel= viewModel()){
|
|
val listState= rememberLazyListState()
|
|
val list by model.data.observeAsState()
|
|
LazyColumn(state = listState,modifier = modifier) {
|
|
list?.chunked(2)?.forEach {
|
|
item {
|
|
Row(modifier=Modifier.fillMaxWidth()) {
|
|
HistoryActivity(modifier = Modifier.weight(0.4F),it[0])
|
|
Spacer(modifier = Modifier.weight(0.2F))
|
|
if (it.size==2) HistoryActivity(modifier = Modifier.weight(0.4F),it[1])
|
|
else Box(modifier = Modifier.weight(0.4F))
|
|
}
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
Divider(color = MaterialTheme.colors.background)
|
|
}
|
|
}
|
|
}
|
|
if(listState.layoutInfo.totalItemsCount-listState.firstVisibleItemIndex==model.initSize/2-1){
|
|
model.loadMore { scaffoldModel.update(message=it) }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 历史活动
|
|
*
|
|
* @param modifier
|
|
*/
|
|
@Composable
|
|
private fun HistoryActivity(modifier: Modifier,historyActVo: HistoryActVo){
|
|
Box(modifier=modifier,contentAlignment = Alignment.Center){
|
|
Image(painter = painterResource(id = R.drawable.history_activity_border),
|
|
contentDescription = null,
|
|
modifier = Modifier.fillMaxSize())
|
|
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground),
|
|
contentDescription = null,
|
|
modifier = Modifier.fillMaxSize())
|
|
Text(text = historyActVo.name)
|
|
|
|
}
|
|
}
|
|
|
|
@Preview
|
|
@Composable
|
|
fun NamePreview(){
|
|
Divider(color = MaterialTheme.colors.background)
|
|
}
|
|
|
|
|
|
|