社团变量重命名

master
pan 4 years ago
parent e9f4ea9c7f
commit 3bcab0cb2e
  1. 42
      app/src/main/java/com/gyf/csams/ui/MainActivity.kt
  2. 26
      app/src/main/java/com/gyf/csams/ui/model/ViewModel.kt

@ -32,8 +32,8 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.ui.model.AssociationDto
import com.gyf.csams.ui.model.CarouselViewModel 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.ListViewModel
import com.gyf.csams.ui.model.MarqueeViewModel import com.gyf.csams.ui.model.MarqueeViewModel
import com.gyf.csams.ui.theme.CSAMSTheme import com.gyf.csams.ui.theme.CSAMSTheme
@ -69,7 +69,7 @@ fun Body() {
Main(navController = navController) Main(navController = navController)
} }
composable(MainMenu.List.name) { composable(MainMenu.List.name) {
CommunityList(navController = navController) AssociationList(navController = navController)
val model:ListViewModel= viewModel() val model:ListViewModel= viewModel()
val snackBarMsg:String by model.snackBarMsg.observeAsState("") val snackBarMsg:String by model.snackBarMsg.observeAsState("")
@ -180,17 +180,17 @@ fun MainBackground() {
* @param navController * @param navController
*/ */
@Composable @Composable
fun CommunityList(navController: NavController) { fun AssociationList(navController: NavController) {
MainFrame( MainFrame(
background = { background = {
CommunityListBackground() AssociationListBackground()
}, },
mainMenu = MainMenu.List, mainMenu = MainMenu.List,
nav = navController nav = navController
) { ) {
RegisterCommunity() RegisterAssociation()
CommunitySearch() AssociationSearch()
CommunityListBody() AssociationListBody()
} }
} }
@ -199,7 +199,7 @@ fun CommunityList(navController: NavController) {
* *
*/ */
@Composable @Composable
fun RegisterCommunity() { fun RegisterAssociation() {
Row( Row(
horizontalArrangement = Arrangement.End, horizontalArrangement = Arrangement.End,
modifier = Modifier modifier = Modifier
@ -219,7 +219,7 @@ fun RegisterCommunity() {
* *
*/ */
@Composable @Composable
fun CommunityListBackground() { fun AssociationListBackground() {
Image( Image(
painter = painterResource(id = R.drawable.mb_bg_fb_07), painter = painterResource(id = R.drawable.mb_bg_fb_07),
contentDescription = null, contentDescription = null,
@ -233,24 +233,22 @@ fun CommunityListBackground() {
* *
*/ */
@Composable @Composable
fun CommunityListBody(model: ListViewModel = viewModel()) { fun AssociationListBody(model: ListViewModel = viewModel()) {
val communityList: MutableList<CommunityDto>? by model.communityDto.observeAsState() val associationList: MutableList<AssociationDto>? by model.associationDto.observeAsState()
val listState = rememberLazyListState() val listState = rememberLazyListState()
// Text(text ="communityList.size=${communityList?.size}")
LazyColumn(state = listState) { LazyColumn(state = listState) {
communityList?.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)) {
Community(communityDto = 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)) {
Community(communityDto = it[1]) Association(associationDto = it[1])
} }
}else{ }else{
Box(modifier = Modifier Box(modifier = Modifier
@ -278,15 +276,15 @@ fun CommunityListBody(model: ListViewModel = viewModel()) {
} }
@Composable @Composable
fun Community(communityDto: CommunityDto) { fun Association(associationDto: AssociationDto) {
Card { Card {
Image( Image(
painter = painterResource(id = R.drawable.community_list_border), painter = painterResource(id = R.drawable.association_list_border),
contentDescription = null contentDescription = null
) )
Row(modifier = Modifier.fillMaxWidth(), Row(modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center) { horizontalArrangement = Arrangement.Center) {
Text(text = communityDto.name) Text(text = associationDto.name)
} }
} }
@ -298,7 +296,7 @@ fun Community(communityDto: CommunityDto) {
* *
*/ */
@Composable @Composable
fun CommunitySearch(model: ListViewModel = viewModel()) { fun AssociationSearch(model: ListViewModel = viewModel()) {
val name: String by model.name.observeAsState("") val name: String by model.name.observeAsState("")
Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) { Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) {
Column { Column {
@ -507,9 +505,7 @@ fun ClubActivitiesImage(model: CarouselViewModel = viewModel()) {
@Composable @Composable
fun DefaultPreview() { fun DefaultPreview() {
CSAMSTheme { CSAMSTheme {
// CommunitySearch(model = ListViewModel()) Text(text = "666")
Text(text = "234234")
} }
} }

@ -68,7 +68,7 @@ class CarouselViewModel:ViewModel(){
} }
data class CommunityDto(val name:String) data class AssociationDto(val name:String)
class ListViewModel:ViewModel(){ class ListViewModel:ViewModel(){
private val _name=MutableLiveData("") private val _name=MutableLiveData("")
@ -86,11 +86,11 @@ class ListViewModel:ViewModel(){
val snackBarMsg:LiveData<String> = _snackBarMsg val snackBarMsg:LiveData<String> = _snackBarMsg
//社团列表 //社团列表
private val _communityList=MutableLiveData<MutableList<CommunityDto>>(mutableListOf()) private val _associationList=MutableLiveData<MutableList<AssociationDto>>(mutableListOf())
val communityDto:LiveData<MutableList<CommunityDto>> = _communityList val associationDto:LiveData<MutableList<AssociationDto>> = _associationList
init { init {
loadCommunity() loadAssociation()
} }
fun onChangeName(name:String){ fun onChangeName(name:String){
@ -110,17 +110,17 @@ class ListViewModel:ViewModel(){
* 加载社团列表 * 加载社团列表
* *
*/ */
private fun loadCommunity(){ private fun loadAssociation(){
viewModelScope.launch { viewModelScope.launch {
_communityList.value?.apply { _associationList.value?.apply {
repeat(10 repeat(10
) { ) {
add(CommunityDto(name = "社团${_communityList.value?.size}")) add(AssociationDto(name = "社团${_associationList.value?.size}"))
} }
} }
Logger.i("初始化社团列表size=${_communityList.value?.size}") Logger.i("初始化社团列表size=${_associationList.value?.size}")
} }
} }
@ -133,20 +133,20 @@ class ListViewModel:ViewModel(){
*/ */
fun addMore(){ fun addMore(){
viewModelScope.launch { viewModelScope.launch {
val c = _communityList.value val c = _associationList.value
if(c!=null){ if(c!=null){
val t=mutableListOf<CommunityDto>() val t=mutableListOf<AssociationDto>()
t.addAll(c) t.addAll(c)
t.apply { t.apply {
repeat(10 repeat(10
) { ) {
add(CommunityDto(name = "社团${t.size}")) add(AssociationDto(name = "社团${t.size}"))
} }
} }
Logger.i("t.size=${t.size}") Logger.i("t.size=${t.size}")
_communityList.postValue(t) _associationList.postValue(t)
Logger.i("加载更多社团size=${_communityList.value?.size}") Logger.i("加载更多社团size=${_associationList.value?.size}")
_snackBarMsg.value="成功加载更多社团" _snackBarMsg.value="成功加载更多社团"
} }

Loading…
Cancel
Save