|
|
|
@ -6,22 +6,35 @@ 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.foundation.shape.RoundedCornerShape |
|
|
|
|
import androidx.compose.foundation.text.KeyboardActions |
|
|
|
|
import androidx.compose.foundation.text.KeyboardOptions |
|
|
|
|
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.draw.rotate |
|
|
|
|
import androidx.compose.ui.graphics.Color |
|
|
|
|
import androidx.compose.ui.layout.ContentScale |
|
|
|
|
import androidx.compose.ui.platform.LocalFocusManager |
|
|
|
|
import androidx.compose.ui.res.painterResource |
|
|
|
|
import androidx.compose.ui.text.input.ImeAction |
|
|
|
|
import androidx.compose.ui.text.style.TextOverflow |
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview |
|
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel |
|
|
|
|
import androidx.navigation.NavController |
|
|
|
|
import androidx.navigation.compose.NavHost |
|
|
|
|
import androidx.navigation.compose.composable |
|
|
|
|
import androidx.navigation.compose.rememberNavController |
|
|
|
|
import com.gyf.csams.R |
|
|
|
|
import com.gyf.csams.ui.model.CarouselViewModel |
|
|
|
|
import com.gyf.csams.ui.model.CommunityDto |
|
|
|
|
import com.gyf.csams.ui.model.ListViewModel |
|
|
|
|
import com.gyf.csams.ui.model.MarqueeViewModel |
|
|
|
|
import com.gyf.csams.ui.theme.CSAMSTheme |
|
|
|
|
|
|
|
|
@ -51,39 +64,10 @@ fun Body() { |
|
|
|
|
Scaffold(scaffoldState = scaffoldState) { |
|
|
|
|
NavHost(navController, startDestination = MainMenu.Main.name) { |
|
|
|
|
composable(MainMenu.Main.name) { |
|
|
|
|
Box(modifier = Modifier.fillMaxSize()) { |
|
|
|
|
Column { |
|
|
|
|
Notification() |
|
|
|
|
MessageBoard() |
|
|
|
|
Spacer(modifier = Modifier.height(10.dp)) |
|
|
|
|
ClubActivitiesTitle() |
|
|
|
|
Spacer(modifier = Modifier.height(10.dp)) |
|
|
|
|
Column(Modifier.rotate(180F)) { |
|
|
|
|
MainBottomAppBar( |
|
|
|
|
MainMenu.Main, |
|
|
|
|
navController, |
|
|
|
|
Modifier.rotate(180F) |
|
|
|
|
) |
|
|
|
|
ClubActivitiesImage() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Main(navController = navController) |
|
|
|
|
} |
|
|
|
|
composable(MainMenu.List.name) { |
|
|
|
|
Box(modifier = Modifier.fillMaxSize()) { |
|
|
|
|
Column(Modifier.rotate(180F)) { |
|
|
|
|
MainBottomAppBar(MainMenu.List, navController, Modifier.rotate(180F)) |
|
|
|
|
Row( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.fillMaxSize() |
|
|
|
|
.rotate(180F), |
|
|
|
|
horizontalArrangement = Arrangement.Center, |
|
|
|
|
verticalAlignment = Alignment.CenterVertically |
|
|
|
|
) { |
|
|
|
|
AnimationText(text = "社团列表") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CommunityList(navController = navController) |
|
|
|
|
} |
|
|
|
|
composable(MainMenu.Center.name) { |
|
|
|
|
Box(modifier = Modifier.fillMaxSize()) { |
|
|
|
@ -107,6 +91,204 @@ fun Body() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 主界面 |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun Main(navController: NavController) { |
|
|
|
|
MainFrame(background = { MainBackground() }, mainMenu = MainMenu.Main, nav = navController) { |
|
|
|
|
Column(modifier = Modifier.weight(0.33F)) { |
|
|
|
|
Notification() |
|
|
|
|
MessageBoard() |
|
|
|
|
Spacer(modifier = Modifier.height(10.dp)) |
|
|
|
|
ClubActivitiesTitle() |
|
|
|
|
Spacer(modifier = Modifier.height(10.dp)) |
|
|
|
|
} |
|
|
|
|
Column(modifier = Modifier.weight(0.66F)) { |
|
|
|
|
ClubActivitiesImage() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 主界面背景 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun MainBackground() { |
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = R.drawable.mb_bg_fb_08), |
|
|
|
|
contentDescription = null, |
|
|
|
|
contentScale = ContentScale.FillHeight, |
|
|
|
|
modifier = Modifier.fillMaxSize() |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 社团列表 |
|
|
|
|
* |
|
|
|
|
* @param navController |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun CommunityList(navController: NavController) { |
|
|
|
|
MainFrame( |
|
|
|
|
background = { |
|
|
|
|
CommunityListBackground() |
|
|
|
|
}, |
|
|
|
|
mainMenu = MainMenu.List, |
|
|
|
|
nav = navController |
|
|
|
|
) { |
|
|
|
|
RegisterCommunity() |
|
|
|
|
CommunitySearch() |
|
|
|
|
CommunityListBody() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加社团按钮 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun RegisterCommunity() { |
|
|
|
|
Row( |
|
|
|
|
horizontalArrangement = Arrangement.End, |
|
|
|
|
modifier = Modifier |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.padding(10.dp) |
|
|
|
|
) { |
|
|
|
|
Icon( |
|
|
|
|
painter = painterResource(id = R.drawable.ic_add_fill), |
|
|
|
|
contentDescription = null, |
|
|
|
|
modifier = Modifier.size(50.dp) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 社团列表背景 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun CommunityListBackground() { |
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = R.drawable.mb_bg_fb_07), |
|
|
|
|
contentDescription = null, |
|
|
|
|
contentScale = ContentScale.FillHeight, |
|
|
|
|
modifier = Modifier.fillMaxSize() |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 社团列表 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun CommunityListBody(model: ListViewModel = viewModel()) { |
|
|
|
|
val communityList: MutableList<CommunityDto>? by model.communityDto.observeAsState() |
|
|
|
|
val listState = rememberLazyListState() |
|
|
|
|
|
|
|
|
|
LazyColumn(state = listState) { |
|
|
|
|
communityList?.chunked(2)?.forEach { |
|
|
|
|
item{ |
|
|
|
|
Row { |
|
|
|
|
Spacer(modifier = Modifier.weight(0.1F)) |
|
|
|
|
Box(modifier = Modifier.weight(0.35F)) { |
|
|
|
|
Community(communityDto = it[0]) |
|
|
|
|
} |
|
|
|
|
Spacer(modifier = Modifier.weight(0.05F)) |
|
|
|
|
if(it.size==2) { |
|
|
|
|
Box(modifier = Modifier.weight(0.35F)) { |
|
|
|
|
Community(communityDto = it[1]) |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
Box(modifier = Modifier |
|
|
|
|
.weight(0.35F) |
|
|
|
|
.border(width = 1.dp, color = Color.Black)) |
|
|
|
|
} |
|
|
|
|
Spacer(modifier = Modifier.weight(0.1F)) |
|
|
|
|
} |
|
|
|
|
Spacer(modifier = Modifier |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.height(10.dp)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if(listState.firstVisibleItemIndex>0){ |
|
|
|
|
model.addMore() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
|
fun Community(communityDto: CommunityDto) { |
|
|
|
|
Card { |
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = R.drawable.community_list_border), |
|
|
|
|
contentDescription = null |
|
|
|
|
) |
|
|
|
|
Row(modifier = Modifier.fillMaxWidth(), |
|
|
|
|
horizontalArrangement = Arrangement.Center) { |
|
|
|
|
Text(text = communityDto.name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 社团检索 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Composable |
|
|
|
|
fun CommunitySearch(model: ListViewModel = viewModel()) { |
|
|
|
|
val name: String by model.name.observeAsState("") |
|
|
|
|
Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) { |
|
|
|
|
Column { |
|
|
|
|
Row { |
|
|
|
|
val focusManager = LocalFocusManager.current |
|
|
|
|
Spacer(modifier = Modifier.weight(0.05F)) |
|
|
|
|
OutlinedTextField( |
|
|
|
|
modifier = Modifier.weight(0.4F), value = name, |
|
|
|
|
onValueChange = { model.onChangeName(it) }, |
|
|
|
|
singleLine = true, |
|
|
|
|
label = { Text(text = model.nameDesc) }, |
|
|
|
|
placeholder = { Text(text = model.namePlaceholder) }, |
|
|
|
|
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), |
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done) |
|
|
|
|
) |
|
|
|
|
Spacer(modifier = Modifier.weight(0.1F)) |
|
|
|
|
OutlinedTextField( |
|
|
|
|
modifier = Modifier.weight(0.4F), value = name, |
|
|
|
|
onValueChange = { model.onChangeDesc(it) }, |
|
|
|
|
singleLine = true, |
|
|
|
|
label = { Text(text = model.descDesc) }, |
|
|
|
|
placeholder = { Text(text = model.descPlaceholder) }, |
|
|
|
|
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), |
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done) |
|
|
|
|
) |
|
|
|
|
Spacer(modifier = Modifier.weight(0.05F)) |
|
|
|
|
} |
|
|
|
|
Spacer( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.height(10.dp) |
|
|
|
|
) |
|
|
|
|
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) { |
|
|
|
|
OutlinedButton(onClick = { model.search() }, modifier = Modifier.width(100.dp)) { |
|
|
|
|
Text(text = "搜索") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Spacer( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.height(10.dp) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通知 |
|
|
|
|
* |
|
|
|
@ -212,64 +394,67 @@ fun ClubActivitiesTitle() { |
|
|
|
|
@Composable |
|
|
|
|
fun ClubActivitiesImage(model: CarouselViewModel = viewModel()) { |
|
|
|
|
Carousel(model = model) { |
|
|
|
|
Column(modifier = Modifier.fillMaxSize()) { |
|
|
|
|
Column { |
|
|
|
|
Card( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.weight(0.4F) |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.weight(0.6F) |
|
|
|
|
.fillMaxWidth(), |
|
|
|
|
backgroundColor = Color.Transparent |
|
|
|
|
) { |
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = R.drawable.hot_activity_desc_background), |
|
|
|
|
painter = painterResource(id = R.drawable.hot_activity_background), |
|
|
|
|
contentDescription = null |
|
|
|
|
) |
|
|
|
|
Box( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.padding(horizontal = 85.dp, vertical = 30.dp) |
|
|
|
|
.rotate(180F) |
|
|
|
|
) { |
|
|
|
|
Text( |
|
|
|
|
text = "文字对任何界面都属于核心内容,而利用 Jetpack Compose 可以更轻松地显示或写入文字。Compose 可以充分利用其构建块的组合,这意味着您无需覆盖各种属性和方法,也无需扩展大型类,即可拥有特定的可组合项设计以及按您期望的方式运行的逻辑。" |
|
|
|
|
.repeat(10), overflow = TextOverflow.Ellipsis |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = it), |
|
|
|
|
contentDescription = null |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
Card( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.weight(0.6F) |
|
|
|
|
.fillMaxWidth() |
|
|
|
|
.rotate(180F) |
|
|
|
|
.weight(0.4F) |
|
|
|
|
.fillMaxWidth(), |
|
|
|
|
backgroundColor = Color.Transparent |
|
|
|
|
) { |
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = R.drawable.hot_activity_background), |
|
|
|
|
painter = painterResource(id = R.drawable.hot_activity_desc_background), |
|
|
|
|
contentDescription = null |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Image( |
|
|
|
|
painter = painterResource(id = it), |
|
|
|
|
contentDescription = null |
|
|
|
|
) |
|
|
|
|
Row(modifier = Modifier.fillMaxWidth()) { |
|
|
|
|
Spacer(modifier = Modifier.weight(0.2F)) |
|
|
|
|
Column( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.weight(0.5F) |
|
|
|
|
) { |
|
|
|
|
Spacer(modifier = Modifier.weight(0.1F)) |
|
|
|
|
Text( |
|
|
|
|
text = "文字对任何界面都属于核心内容,而利用 Jetpack Compose 可以更轻松地显示或写入文字。Compose 可以充分利用其构建块的组合,这意味着您无需覆盖各种属性和方法,也无需扩展大型类,即可拥有特定的可组合项设计以及按您期望的方式运行的逻辑。" |
|
|
|
|
.repeat(10), overflow = TextOverflow.Ellipsis, |
|
|
|
|
modifier = Modifier.weight(0.8F) |
|
|
|
|
) |
|
|
|
|
Spacer(modifier = Modifier.weight(0.1F)) |
|
|
|
|
} |
|
|
|
|
Spacer(modifier = Modifier.weight(0.2F)) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@Preview(showBackground = true) |
|
|
|
|
@Preview(showBackground = true) |
|
|
|
|
@Composable |
|
|
|
|
fun DefaultPreview() { |
|
|
|
|
val model = MarqueeViewModel() |
|
|
|
|
CSAMSTheme { |
|
|
|
|
Box(modifier = Modifier.fillMaxSize()) { |
|
|
|
|
Column { |
|
|
|
|
// Marquee(model = model) { |
|
|
|
|
// model, value -> TestA(model = model, |
|
|
|
|
// offset = value) |
|
|
|
|
// } |
|
|
|
|
MessageBoard(model = model) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// CommunitySearch(model = ListViewModel()) |
|
|
|
|
|
|
|
|
|
CommunityListBody(model = ListViewModel()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|