社团变量重命名

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

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

Loading…
Cancel
Save