From caa63ff8b0dc2c30a8b44e99e911c607bcf898e5 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Tue, 1 Jun 2021 21:58:30 +0800 Subject: [PATCH] =?UTF-8?q?ScrollViewModel.kt=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=88=97=E8=A1=A8=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E5=92=8C=E6=9C=8D=E5=8A=A1=E7=AB=AF=E7=A4=BE=E5=9B=A2=E6=88=90?= =?UTF-8?q?=E5=91=98=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/AssociationManagementViewModel.kt | 4 +- .../main/model/AuditAssociationViewModel.kt | 5 +- .../gyf/csams/main/model/CheckActViewModel.kt | 4 +- .../main/model/CheckQualityReportViewModel.kt | 4 +- .../csams/main/model/ManagerActViewModel.kt | 4 +- .../gyf/csams/main/model/RenameViewModel.kt | 6 +- .../activity/model/ActivityDetailViewModel.kt | 152 ++---------------- .../activity/ui/ActivityDetailActivity.kt | 16 +- .../association/model/AssociationViewModel.kt | 98 ++--------- .../csams/association/model/ExamViewModel.kt | 4 +- .../association/ui/AssociationActivity.kt | 41 +++-- .../com/gyf/csams/main/model/MainViewModel.kt | 15 +- .../com/gyf/csams/main/ui/MainActivity.kt | 15 +- .../java/com/gyf/lib/model/ScrollViewModel.kt | 13 +- .../com/gyf/lib/model/SysMessageViewModel.kt | 13 +- lib/src/main/java/com/gyf/lib/util/Api.kt | 28 +++- lib/src/main/java/com/gyf/lib/util/Vo.kt | 27 +--- 17 files changed, 114 insertions(+), 335 deletions(-) diff --git a/background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt index 0f12568..12c8f0c 100644 --- a/background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt @@ -21,11 +21,11 @@ class AssociationManagementViewModel(application: Application) : ScrollViewModel load() } - override fun load() { + fun load() { TODO() } - override fun loadMore(callback: (message: String) -> Unit) { + fun loadMore(callback: (message: String) -> Unit) { TODO("Not yet implemented") } diff --git a/background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt index 347dfdc..f36eeea 100644 --- a/background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt @@ -17,7 +17,7 @@ class AuditAssociationViewModel(application: Application) : ScrollViewModel Unit) { + fun load(callback: (message: String) -> Unit) { viewModelScope.launch { HttpClient.post( Api.buildUrl(AssociationApi.Audit), HttpCallback>( @@ -35,9 +35,6 @@ class AuditAssociationViewModel(application: Application) : ScrollViewModel Unit) { - TODO("Not yet implemented") - } /** diff --git a/background/src/main/java/com/gyf/csams/main/model/CheckActViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/CheckActViewModel.kt index f43d15f..c75a720 100644 --- a/background/src/main/java/com/gyf/csams/main/model/CheckActViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/CheckActViewModel.kt @@ -21,7 +21,7 @@ class CheckActViewModel(application: Application) : ApplyViewModel(a load() } - override fun load() { + fun load() { viewModelScope.launch { _data.value?.apply { repeat(initSize) { @@ -39,7 +39,7 @@ class CheckActViewModel(application: Application) : ApplyViewModel(a } } - override fun loadMore(callback: (message: String) -> Unit) { + fun loadMore(callback: (message: String) -> Unit) { TODO("Not yet implemented") } diff --git a/background/src/main/java/com/gyf/csams/main/model/CheckQualityReportViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/CheckQualityReportViewModel.kt index 06972a4..138a492 100644 --- a/background/src/main/java/com/gyf/csams/main/model/CheckQualityReportViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/CheckQualityReportViewModel.kt @@ -22,7 +22,7 @@ class CheckQualityReportViewModel(application: Application) : ApplyViewModel Unit) { + fun loadMore(callback: (message: String) -> Unit) { TODO("Not yet implemented") } } \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt index f3180ea..a7eba4f 100644 --- a/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt @@ -22,7 +22,7 @@ class ManagerActViewModel(application: Application) : ScrollViewModel Unit) { + fun loadMore(callback: (message: String) -> Unit) { TODO("Not yet implemented") } } \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt index 73375c6..937346d 100644 --- a/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt @@ -26,7 +26,7 @@ class RenameViewModel(application: Application) : ScrollViewModel(appl load() } - override fun load() { + fun load() { viewModelScope.launch { _data.value?.apply { repeat(initSize) { @@ -42,8 +42,4 @@ class RenameViewModel(application: Application) : ScrollViewModel(appl } } } - - override fun loadMore(callback: (message: String) -> Unit) { - TODO("Not yet implemented") - } } \ No newline at end of file diff --git a/foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt b/foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt index 5e91c8a..a5af518 100644 --- a/foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt +++ b/foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt @@ -11,7 +11,6 @@ import com.gyf.csams.uikit.TopMenuInterface import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.uikit.ValidStringForm import com.gyf.lib.util.* -import com.orhanobut.logger.Logger import kotlinx.coroutines.launch /** @@ -90,116 +89,34 @@ class ActivityPhotoViewModel(application: Application) : } /** - * TODO 加载相册 + * * */ - override fun load() { - viewModelScope.launch { - _data.value?.apply { - repeat(initSize) { - add( - ActivityPhotoVo( - name = randomChinese(3), - size = randomNum(3).toLong(), - url = "", - md5 = "", - createTime = randomDateTime(), - studentId = "" - ) - ) - } - } - } + fun load() { + TODO("加载相册") } /** - * TODO 加载更多相册 + * * * @param callback */ - override fun loadMore(callback: (message: String) -> Unit) { - Logger.i("加载更多") - viewModelScope.launch { - _data.value?.apply { - val list = mutableListOf() - list.addAll(this) - repeat(initSize) { - add( - ActivityPhotoVo( - name = randomChinese(3), - size = randomNum(3).toLong(), - url = "", - md5 = "", - createTime = randomDateTime(), - studentId = "" - ) - ) - } - _data.postValue(list) - callback("成功加载更多相册") - } - } + fun loadMore(callback: (message: String) -> Unit) { + TODO("加载更多相册") } } class ActivityMemberViewModel(application: Application) : - ScrollViewModel(application) { - override val initSize: Int = 10 - - private val _allMember = MutableLiveData() - val allMember: LiveData = _allMember - - init { - load() - } + ScrollViewModel(application) { /** - * TODO 加载活动成员 * - */ - override fun load() { - viewModelScope.launch { - _data.value?.apply { - repeat(initSize) { - add(ActivityMemberVo(studentId = randomNum(), name = randomChinese(3))) - } - _allMember.value = ActivityMembersVo( - organizer = ActivityMemberVo( - studentId = randomNum(), - name = randomChinese(3) - ), participant = _data.value - ) - } - } - } - - /** - * TODO 加载更多活动成员 * - * @param callback */ - override fun loadMore(callback: (message: String) -> Unit) { - viewModelScope.launch { - _data.value?.apply { - val list = mutableListOf() - list.addAll(this) - repeat(initSize) { - add(ActivityMemberVo(studentId = randomNum(), name = randomChinese(3))) - } - _allMember.value?.apply { - _data.postValue(list) - _allMember.postValue( - ActivityMembersVo( - organizer = organizer, - participant = list - ) - ) - callback("成功加载更多活动参与者") - } - } - } + fun load() { + TODO("加载活动成员") } } @@ -225,57 +142,10 @@ class BBSViewModel(application: Application) : ScrollViewModel(applicatio val title = "发送评论" - - init { - load() - } - - /** - * TODO 加载评论 - * - */ - override fun load() { - viewModelScope.launch { - _data.value?.apply { - repeat(initSize) { - add( - BBSVo( - studentId = randomNum(), - createTime = randomDateTime(), - content = randomChinese(50), - name = randomChinese(3) - ) - ) - } - } - } - } - /** - * TODO 加载更多评论 * - * @param callback */ - override fun loadMore(callback: (message: String) -> Unit) { - viewModelScope.launch { - _data.value?.apply { - repeat(initSize) { - val list = mutableListOf() - list.addAll(this) - repeat(initSize) { - add( - BBSVo( - studentId = randomNum(), - name = randomChinese(3), - createTime = randomDateTime(), - content = randomChinese(50) - ) - ) - } - _data.postValue(list) - callback("成功加载更多评论") - } - } - } + fun load() { + TODO("加载评论") } } \ No newline at end of file diff --git a/foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt b/foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt index ded884c..8b9ec7b 100644 --- a/foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt @@ -27,9 +27,9 @@ import com.gyf.lib.uikit.MainColumnFrame import com.gyf.lib.uikit.NavBody import com.gyf.lib.uikit.ScaffoldModel import com.gyf.lib.uikit.ShowSnackbar -import com.gyf.lib.util.ActivityMemberVo import com.gyf.lib.util.ActivityPhotoVo import com.gyf.lib.util.BBSVo +import com.gyf.lib.util.UserInfoVo import com.gyf.lib.util.format /** @@ -287,7 +287,7 @@ class ActivityDetailActivity : ComponentActivity() { ) }) { - val data by model.allMember.observeAsState() + val data by model.data.observeAsState() data?.apply { Spacer(modifier = Modifier.height(5.dp)) @@ -301,7 +301,7 @@ class ActivityDetailActivity : ComponentActivity() { painter = painterResource(id = R.drawable.persion_name_border), contentDescription = null ) - Text(text = organizer.name) + Text(text = first().name) } } Spacer(modifier = Modifier.height(5.dp)) @@ -315,7 +315,7 @@ class ActivityDetailActivity : ComponentActivity() { .border(width = 1.dp, color = MaterialTheme.colors.onBackground) ) { val listState = rememberLazyListState() - participant?.let { + drop(1).let { LazyColumn(state = listState) { it.chunked(2).forEach { item { @@ -341,9 +341,8 @@ class ActivityDetailActivity : ComponentActivity() { } } } -// Logger.i("totalItemsCount=${listState.layoutInfo.totalItemsCount},firstVisibleItemIndex=${listState.firstVisibleItemIndex}") if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { - model.loadMore { scaffoldModel.update(message = it) } + TODO("加载更多") } } } @@ -353,7 +352,7 @@ class ActivityDetailActivity : ComponentActivity() { } @Composable - private fun Participant(modifier: Modifier = Modifier, vo: ActivityMemberVo) { + private fun Participant(modifier: Modifier = Modifier, vo: UserInfoVo) { Box(modifier = modifier, contentAlignment = Alignment.Center) { Image( painter = painterResource(id = R.drawable.participant_border), @@ -416,9 +415,8 @@ class ActivityDetailActivity : ComponentActivity() { } } } -// Logger.i("totalItemsCount=${listState.layoutInfo.totalItemsCount},firstVisibleItemIndex=${listState.firstVisibleItemIndex}") if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { - model.loadMore { scaffoldModel.update(message = it) } + TODO("加载更多") } } diff --git a/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt b/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt index 35b9aa1..72b99ad 100644 --- a/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt +++ b/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt @@ -11,7 +11,6 @@ import com.gyf.csams.uikit.TopMenuInterface import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.uikit.StringForm import com.gyf.lib.util.* -import com.orhanobut.logger.Logger import kotlinx.coroutines.launch @@ -58,70 +57,34 @@ class AssociationViewModel : ViewModel(), TopMenuInterface { } /** - * 社团会员 + * 社团成员 * */ -class MemberViewModel(application: Application) : ScrollViewModel(application) { +class MemberViewModel(application: Application) : ScrollViewModel(application) { val name = StringForm(formDesc = "姓名关键字", 5) - val search = "搜索" - - private val _memberList = MutableLiveData>(mutableListOf()) - - val memberList = _memberList - override val initSize: Int = 10 - init { - load() - } - /** - * 初始化成员 + * 加载社团成员 * */ - override fun load() { + fun load(id: Int, callback: (message: String) -> Unit) { viewModelScope.launch { - _memberList.value?.apply { - repeat(initSize) { - add(MemberVo(name = "成员${size + 1}")) - } - Logger.i("初始化社团成员size=$size") - } - - } - } - - - /** - * 加载更多成员 - * - */ - override fun loadMore(callback: (message: String) -> Unit) { - viewModelScope.launch { - _memberList.value?.let { - val t = mutableListOf() - t.addAll(it) - t.apply { - repeat(10) { - add(MemberVo(name = "成员${t.size + 1}")) - } - } - _memberList.postValue(t) - Logger.i("加载更多社团成员,size=${t.size}") - } + HttpClient.post( + Api.buildUrl(AssociationApi.LoadMember), HttpCallback>( + action = "加载社团成员", + onSuccess = { + it.body?.let { + _data.postValue(it) + } + }, + typeToken = object : TypeToken>>() {}.type + ), + jsonParam = QueryAssociationMembers(id = id, name = name.formValue.value) + ) } } - - /** - * TODO 社团成员搜索 - * - * @param callback - */ - fun search(callback: (value: String) -> Unit) { - Logger.i("搜索条件[成员姓名:${name.formValue.value}]") - callback(NOT_IMPL_TIP) - } } class OngoingActViewModel : ViewModel() { @@ -136,33 +99,4 @@ class OngoingActViewModel : ViewModel() { */ class HistoryActViewModel(application: Application) : ScrollViewModel(application) { override val initSize = 10 - - init { - load() - } - - override fun load() { - viewModelScope.launch { - _data.value?.apply { - repeat(initSize) { - add(HistoryActVo(name = "活动${size + 1}")) - } - Logger.i("初始化活动数量:${size}") - } - } - } - - override fun loadMore(callback: (message: String) -> Unit) { - _data.value?.apply { - val t = mutableListOf() - t.addAll(this) - t.apply { - repeat(10) { - add(HistoryActVo(name = "活动${t.size + 1}")) - } - } - _data.postValue(t) - callback("成功加载更多活动") - } - } } \ No newline at end of file diff --git a/foreground/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt b/foreground/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt index 1afaea2..3204fe8 100644 --- a/foreground/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt +++ b/foreground/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt @@ -139,7 +139,7 @@ class ExamViewModel(application: Application) : ScrollViewModel(applicatio * 加载题目 * */ - override fun load() { + fun load() { viewModelScope.launch { _data.value?.apply { repeat(initSize) { @@ -183,7 +183,7 @@ class ExamViewModel(application: Application) : ScrollViewModel(applicatio * * @param callback */ - override fun loadMore(callback: (message: String) -> Unit) { + fun loadMore(callback: (message: String) -> Unit) { // _data.value?.apply { // val list= mutableListOf() // list.addAll(this) diff --git a/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt b/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt index 7195fd2..15318d9 100644 --- a/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupProperties @@ -32,8 +33,6 @@ import com.gyf.csams.association.model.* import com.gyf.csams.uikit.* import com.gyf.lib.uikit.* import com.gyf.lib.util.HistoryActVo -import com.gyf.lib.util.MemberVo -import com.orhanobut.logger.Logger /** @@ -42,7 +41,7 @@ import com.orhanobut.logger.Logger */ class AssociationActivity : ComponentActivity() { - val associationId: Int + private val associationId: Int get() { val id = intent.getIntExtra( AssociationActivity::javaClass.name, @@ -218,8 +217,7 @@ class AssociationActivity : ComponentActivity() { @Composable private fun Search( modifier: Modifier = Modifier, - model: MemberViewModel = viewModel(), - scaffoldModel: ScaffoldModel = viewModel() + model: MemberViewModel = viewModel() ) { Column(modifier = modifier.fillMaxSize()) { Spacer(modifier = Modifier.weight(0.5F)) @@ -240,10 +238,14 @@ class AssociationActivity : ComponentActivity() { ) Spacer(modifier = Modifier.weight(spaceWeight)) OutlinedButton( - onClick = { model.search { scaffoldModel.update(message = it) } }, + onClick = { + model.load(associationId) { + + } + }, modifier = Modifier.weight(buttonWeight) ) { - Text(text = model.search) + Text(text = stringResource(id = R.string.search_btn)) } Spacer(modifier = Modifier.weight(spaceWeight)) } @@ -257,13 +259,15 @@ class AssociationActivity : ComponentActivity() { @Composable private fun MemberList( modifier: Modifier = Modifier, - model: MemberViewModel = viewModel(), - scaffoldModel: ScaffoldModel = viewModel() + model: MemberViewModel = viewModel() ) { - val list: MutableList? by model.memberList.observeAsState() + model.load(associationId) { + + } + val data by model.data.observeAsState() val listState = rememberLazyListState() LazyColumn(state = listState, modifier = modifier) { - list?.forEach { + data?.forEach { item { Column { Spacer(modifier = Modifier.height(10.dp)) @@ -289,8 +293,8 @@ class AssociationActivity : ComponentActivity() { modifier = Modifier.fillMaxWidth() ) { IconButton(onClick = { - model.loadMore { - scaffoldModel.update(message = it) + model.load(associationId) { + } }) { Icon( @@ -445,12 +449,8 @@ class AssociationActivity : ComponentActivity() { */ @Composable private fun OngoingActivity( - modifier: Modifier = Modifier, - model: OngoingActViewModel = viewModel() + modifier: Modifier = Modifier ) { - val act by model.act.observeAsState() - // TODO 解决Build Warnning - Logger.i("$act") Row(modifier = modifier.clickable(onClick = { startActivity(Intent(this, ActivityDetailActivity::class.java)) }), horizontalArrangement = Arrangement.Center) { @@ -471,8 +471,7 @@ class AssociationActivity : ComponentActivity() { @Composable private fun HistoryActivityList( modifier: Modifier, - model: HistoryActViewModel = viewModel(), - scaffoldModel: ScaffoldModel = viewModel() + model: HistoryActViewModel = viewModel() ) { val listState = rememberLazyListState() val list by model.data.observeAsState() @@ -491,7 +490,7 @@ class AssociationActivity : ComponentActivity() { } } if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { - model.loadMore { scaffoldModel.update(message = it) } + TODO("加载更多") } } diff --git a/foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt b/foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt index d3b25d9..aab6f71 100644 --- a/foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt +++ b/foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt @@ -147,13 +147,12 @@ class MarqueeViewModel : AbstractComment() { * 社团列表 * */ -class ListViewModel(application: Application) : ScrollViewModel(application) { +class AssociationListViewModel(application: Application) : + ScrollViewModel(application) { val name = StringForm(formDesc = "社团名称", textLength = 5) val desc = StringForm(formDesc = "社团简介", textLength = 10) - val searchDesc = "搜索" - override val initSize: Int = 10 init { @@ -164,7 +163,7 @@ class ListViewModel(application: Application) : ScrollViewModel(a * 加载社团列表 * */ - override fun load(callback: (message: String) -> Unit) { + fun load(callback: (message: String) -> Unit) { viewModelScope.launch { HttpClient.post( Api.buildUrl(AssociationApi.List), @@ -186,14 +185,6 @@ class ListViewModel(application: Application) : ScrollViewModel(a ) } } - - /** - * 加载更多社团列表 - * - */ - override fun loadMore(callback: (message: String) -> Unit) { - TODO(NOT_IMPL_TIP) - } } diff --git a/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt b/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt index ad4f221..d6e9586 100644 --- a/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt @@ -16,6 +16,7 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -187,9 +188,9 @@ class MainActivity : BaseActivity() { mainMenu = MainMenu.List, nav = navController ) { - val memberVo: AssociationMemberVo? = - (TokenManager.getOwnInfo() as? UserVo)?.associationMemberVo - if (memberVo == null) { + val associationVo: AssociationVo? = + (TokenManager.getOwnInfo() as? UserVo)?.associationVo + if (associationVo == null) { RegisterAssociation() } AssociationSearch() @@ -227,7 +228,7 @@ class MainActivity : BaseActivity() { */ @Composable private fun AssociationListBody( - model: ListViewModel = viewModel(), + model: AssociationListViewModel = viewModel(), scaffoldModel: ScaffoldModel = viewModel() ) { val associationListList: MutableList? by model.data.observeAsState() @@ -265,7 +266,7 @@ class MainActivity : BaseActivity() { } if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { - model.loadMore { scaffoldModel.update(message = it) } + TODO("加载更多") } } @@ -303,7 +304,7 @@ class MainActivity : BaseActivity() { */ @Composable private fun AssociationSearch( - model: ListViewModel = viewModel(), + model: AssociationListViewModel = viewModel(), scaffoldModel: ScaffoldModel = viewModel() ) { Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) { @@ -334,7 +335,7 @@ class MainActivity : BaseActivity() { }, modifier = Modifier.width(100.dp) ) { - Text(text = model.searchDesc) + Text(text = stringResource(id = R.string.search_btn)) } } Spacer( diff --git a/lib/src/main/java/com/gyf/lib/model/ScrollViewModel.kt b/lib/src/main/java/com/gyf/lib/model/ScrollViewModel.kt index f31ae21..01e4abd 100644 --- a/lib/src/main/java/com/gyf/lib/model/ScrollViewModel.kt +++ b/lib/src/main/java/com/gyf/lib/model/ScrollViewModel.kt @@ -9,16 +9,5 @@ abstract class ScrollViewModel(application: Application) : AndroidViewModel(a protected val _data = MutableLiveData>(mutableListOf()) val data: LiveData> = _data - abstract val initSize: Int - - - //加载列表 - @Deprecated("") - open fun load() { - } - - open fun load(callback: (message: String) -> Unit) {} - - //加载更多数据 - abstract fun loadMore(callback: (message: String) -> Unit) + open val initSize: Int = 10 } \ No newline at end of file diff --git a/lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt b/lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt index c046f38..8659ef4 100644 --- a/lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt +++ b/lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt @@ -90,7 +90,7 @@ abstract class SysMessageViewModel(application: Application) : abstract fun clientType(): ClientType init { - load() + load {} } @@ -98,7 +98,7 @@ abstract class SysMessageViewModel(application: Application) : *加载通知列表 * */ - final override fun load() { + fun load(callback: (message: String) -> Unit) { viewModelScope.launch { HttpClient.post( Api.buildUrl(NotificationApi.List), @@ -126,13 +126,4 @@ abstract class SysMessageViewModel(application: Application) : ) } } - - /** - *TODO - * - * @param callback - */ - override fun loadMore(callback: (message: String) -> Unit) { - callback(NOT_IMPL_TIP) - } } \ No newline at end of file diff --git a/lib/src/main/java/com/gyf/lib/util/Api.kt b/lib/src/main/java/com/gyf/lib/util/Api.kt index dbb2c62..03e2c81 100644 --- a/lib/src/main/java/com/gyf/lib/util/Api.kt +++ b/lib/src/main/java/com/gyf/lib/util/Api.kt @@ -57,8 +57,10 @@ enum class MainApi(val path: String) : UrlPath { //热门活动 HotActivity("/hotActivity"), - //留言区 + //发送留言 LeaveMessage("/leaveMessage"), + + //获取留言 GetMessage("/getMessage"); override fun build(): String { @@ -72,14 +74,33 @@ enum class MainApi(val path: String) : UrlPath { * @property path */ enum class AssociationApi(val path: String) : UrlPath { + //上传logo Logo("/uploadLogo"), + + //提交注册资料 Register("/register"), + + //受理注册资料 Accept("/accept"), + + //模糊查询社团 List("/list"), + + //审核注册资料 Check("/check"), + + //社团注册资料列表 Audit("/audit"), + + //审核进度 Read("/read"), - Load("/load"); + + //id精确查询社团 + Load("/load"), + + //加载社团成员 + LoadMember("${Load.path}/members"); + override fun build(): String { return "/api/association${this.path}" @@ -87,7 +108,10 @@ enum class AssociationApi(val path: String) : UrlPath { } enum class NotificationApi(val path: String) : UrlPath { + //通知计数 Count("/count"), + + // List("/list"), Pull("/pull"); diff --git a/lib/src/main/java/com/gyf/lib/util/Vo.kt b/lib/src/main/java/com/gyf/lib/util/Vo.kt index 25cfce6..0d755f8 100644 --- a/lib/src/main/java/com/gyf/lib/util/Vo.kt +++ b/lib/src/main/java/com/gyf/lib/util/Vo.kt @@ -102,7 +102,8 @@ data class UserVo( override val name: String, override val headImg: String?, override val desc: String, - val associationMemberVo: AssociationMemberVo? + val associationVo: AssociationVo?, + val isHead: Boolean? ) : OwnInfoVo() data class PageDto(val currentPage: Long, val pageSize: Int = 10) @@ -164,21 +165,6 @@ data class ActivityDetailVo( val activityDesc: String ) - -data class ActivityMemberVo(val studentId: String, val name: String) - -/** - * 活动成员 - * - * @property organizer - * @property participant - */ -data class ActivityMembersVo( - val organizer: ActivityMemberVo, - val participant: MutableList? -) - - /** * 图片 * @property name 文件名 @@ -333,6 +319,12 @@ data class ShowAssociationVo( ) : ClientBaseVo() +data class QueryAssociationMembers( + val id: Int, + val name: String? = null, + override val clientType: ClientType = ClientType.Foreground +) : ClientBaseVo() + data class BBSVo(val studentId: String, val name: String, val createTime: Date, val content: String) @@ -389,9 +381,6 @@ data class LeaveMessageFormatVo(val message: String, val user: UserInfoVo) data class ManagerLoginVo(val account: String, val password: String, val device: String) - -data class MemberVo(val name: String) - data class OngoingActVo(val name: String) /**