ScrollViewModel.kt 删除加载列表方法

和服务端社团成员接口对接数据
master
pan 4 years ago
parent 779c6c989f
commit caa63ff8b0
  1. 4
      background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt
  2. 5
      background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt
  3. 4
      background/src/main/java/com/gyf/csams/main/model/CheckActViewModel.kt
  4. 4
      background/src/main/java/com/gyf/csams/main/model/CheckQualityReportViewModel.kt
  5. 4
      background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt
  6. 6
      background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt
  7. 152
      foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt
  8. 16
      foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt
  9. 98
      foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt
  10. 4
      foreground/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt
  11. 41
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  12. 15
      foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt
  13. 15
      foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  14. 13
      lib/src/main/java/com/gyf/lib/model/ScrollViewModel.kt
  15. 13
      lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt
  16. 28
      lib/src/main/java/com/gyf/lib/util/Api.kt
  17. 27
      lib/src/main/java/com/gyf/lib/util/Vo.kt

@ -21,11 +21,11 @@ class AssociationManagementViewModel(application: Application) : ScrollViewModel
load() load()
} }
override fun load() { fun load() {
TODO() TODO()
} }
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

@ -17,7 +17,7 @@ class AuditAssociationViewModel(application: Application) : ScrollViewModel<Disp
load { } load { }
} }
override fun load(callback: (message: String) -> Unit) { fun load(callback: (message: String) -> Unit) {
viewModelScope.launch { viewModelScope.launch {
HttpClient.post( HttpClient.post(
Api.buildUrl(AssociationApi.Audit), HttpCallback<MutableList<DisposeRegInfoVo>>( Api.buildUrl(AssociationApi.Audit), HttpCallback<MutableList<DisposeRegInfoVo>>(
@ -35,9 +35,6 @@ class AuditAssociationViewModel(application: Application) : ScrollViewModel<Disp
} }
} }
override fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented")
}
/** /**

@ -21,7 +21,7 @@ class CheckActViewModel(application: Application) : ApplyViewModel<ApplyActVo>(a
load() load()
} }
override fun load() { fun load() {
viewModelScope.launch { viewModelScope.launch {
_data.value?.apply { _data.value?.apply {
repeat(initSize) { repeat(initSize) {
@ -39,7 +39,7 @@ class CheckActViewModel(application: Application) : ApplyViewModel<ApplyActVo>(a
} }
} }
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

@ -22,7 +22,7 @@ class CheckQualityReportViewModel(application: Application) : ApplyViewModel<Qua
load() load()
} }
override fun load() { fun load() {
viewModelScope.launch { viewModelScope.launch {
_data.value?.apply { _data.value?.apply {
repeat(initSize) { repeat(initSize) {
@ -38,7 +38,7 @@ class CheckQualityReportViewModel(application: Application) : ApplyViewModel<Qua
} }
} }
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
} }

@ -22,7 +22,7 @@ class ManagerActViewModel(application: Application) : ScrollViewModel<ActivityVo
load() load()
} }
override fun load() { fun load() {
_data.value?.apply { _data.value?.apply {
repeat(initSize) { repeat(initSize) {
add( add(
@ -39,7 +39,7 @@ class ManagerActViewModel(application: Application) : ScrollViewModel<ActivityVo
} }
} }
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
} }

@ -26,7 +26,7 @@ class RenameViewModel(application: Application) : ScrollViewModel<RenameVo>(appl
load() load()
} }
override fun load() { fun load() {
viewModelScope.launch { viewModelScope.launch {
_data.value?.apply { _data.value?.apply {
repeat(initSize) { repeat(initSize) {
@ -42,8 +42,4 @@ class RenameViewModel(application: Application) : ScrollViewModel<RenameVo>(appl
} }
} }
} }
override fun loadMore(callback: (message: String) -> Unit) {
TODO("Not yet implemented")
}
} }

@ -11,7 +11,6 @@ import com.gyf.csams.uikit.TopMenuInterface
import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.uikit.ValidStringForm import com.gyf.lib.uikit.ValidStringForm
import com.gyf.lib.util.* import com.gyf.lib.util.*
import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
@ -90,116 +89,34 @@ class ActivityPhotoViewModel(application: Application) :
} }
/** /**
* TODO 加载相册 *
* *
*/ */
override fun load() { fun load() {
viewModelScope.launch { TODO("加载相册")
_data.value?.apply {
repeat(initSize) {
add(
ActivityPhotoVo(
name = randomChinese(3),
size = randomNum(3).toLong(),
url = "",
md5 = "",
createTime = randomDateTime(),
studentId = ""
)
)
}
}
}
} }
/** /**
* TODO 加载更多相册 *
* *
* @param callback * @param callback
*/ */
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
Logger.i("加载更多") TODO("加载更多相册")
viewModelScope.launch {
_data.value?.apply {
val list = mutableListOf<ActivityPhotoVo>()
list.addAll(this)
repeat(initSize) {
add(
ActivityPhotoVo(
name = randomChinese(3),
size = randomNum(3).toLong(),
url = "",
md5 = "",
createTime = randomDateTime(),
studentId = ""
)
)
}
_data.postValue(list)
callback("成功加载更多相册")
}
}
} }
} }
class ActivityMemberViewModel(application: Application) : class ActivityMemberViewModel(application: Application) :
ScrollViewModel<ActivityMemberVo>(application) { ScrollViewModel<UserInfoVo>(application) {
override val initSize: Int = 10
private val _allMember = MutableLiveData<ActivityMembersVo>()
val allMember: LiveData<ActivityMembersVo> = _allMember
init {
load()
}
/** /**
* 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) { fun load() {
viewModelScope.launch { TODO("加载活动成员")
_data.value?.apply {
val list = mutableListOf<ActivityMemberVo>()
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("成功加载更多活动参与者")
}
}
}
} }
} }
@ -225,57 +142,10 @@ class BBSViewModel(application: Application) : ScrollViewModel<BBSVo>(applicatio
val title = "发送评论" 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) { fun load() {
viewModelScope.launch { TODO("加载评论")
_data.value?.apply {
repeat(initSize) {
val list = mutableListOf<BBSVo>()
list.addAll(this)
repeat(initSize) {
add(
BBSVo(
studentId = randomNum(),
name = randomChinese(3),
createTime = randomDateTime(),
content = randomChinese(50)
)
)
}
_data.postValue(list)
callback("成功加载更多评论")
}
}
}
} }
} }

@ -27,9 +27,9 @@ import com.gyf.lib.uikit.MainColumnFrame
import com.gyf.lib.uikit.NavBody import com.gyf.lib.uikit.NavBody
import com.gyf.lib.uikit.ScaffoldModel import com.gyf.lib.uikit.ScaffoldModel
import com.gyf.lib.uikit.ShowSnackbar import com.gyf.lib.uikit.ShowSnackbar
import com.gyf.lib.util.ActivityMemberVo
import com.gyf.lib.util.ActivityPhotoVo import com.gyf.lib.util.ActivityPhotoVo
import com.gyf.lib.util.BBSVo import com.gyf.lib.util.BBSVo
import com.gyf.lib.util.UserInfoVo
import com.gyf.lib.util.format 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 { data?.apply {
Spacer(modifier = Modifier.height(5.dp)) Spacer(modifier = Modifier.height(5.dp))
@ -301,7 +301,7 @@ class ActivityDetailActivity : ComponentActivity() {
painter = painterResource(id = R.drawable.persion_name_border), painter = painterResource(id = R.drawable.persion_name_border),
contentDescription = null contentDescription = null
) )
Text(text = organizer.name) Text(text = first().name)
} }
} }
Spacer(modifier = Modifier.height(5.dp)) Spacer(modifier = Modifier.height(5.dp))
@ -315,7 +315,7 @@ class ActivityDetailActivity : ComponentActivity() {
.border(width = 1.dp, color = MaterialTheme.colors.onBackground) .border(width = 1.dp, color = MaterialTheme.colors.onBackground)
) { ) {
val listState = rememberLazyListState() val listState = rememberLazyListState()
participant?.let { drop(1).let {
LazyColumn(state = listState) { LazyColumn(state = listState) {
it.chunked(2).forEach { it.chunked(2).forEach {
item { 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) { 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 @Composable
private fun Participant(modifier: Modifier = Modifier, vo: ActivityMemberVo) { private fun Participant(modifier: Modifier = Modifier, vo: UserInfoVo) {
Box(modifier = modifier, contentAlignment = Alignment.Center) { Box(modifier = modifier, contentAlignment = Alignment.Center) {
Image( Image(
painter = painterResource(id = R.drawable.participant_border), 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) { if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) {
model.loadMore { scaffoldModel.update(message = it) } TODO("加载更多")
} }
} }

@ -11,7 +11,6 @@ import com.gyf.csams.uikit.TopMenuInterface
import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.uikit.StringForm import com.gyf.lib.uikit.StringForm
import com.gyf.lib.util.* import com.gyf.lib.util.*
import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -58,69 +57,33 @@ class AssociationViewModel : ViewModel(), TopMenuInterface<AssociationMenu> {
} }
/** /**
* 社团 * 社团
* *
*/ */
class MemberViewModel(application: Application) : ScrollViewModel<MemberVo>(application) { class MemberViewModel(application: Application) : ScrollViewModel<UserInfoVo>(application) {
val name = StringForm(formDesc = "姓名关键字", 5) val name = StringForm(formDesc = "姓名关键字", 5)
val search = "搜索"
private val _memberList = MutableLiveData<MutableList<MemberVo>>(mutableListOf())
val memberList = _memberList
override val initSize: Int = 10 override val initSize: Int = 10
init {
load()
}
/**
* 初始化成员
*
*/
override fun load() {
viewModelScope.launch {
_memberList.value?.apply {
repeat(initSize) {
add(MemberVo(name = "成员${size + 1}"))
}
Logger.i("初始化社团成员size=$size")
}
}
}
/** /**
* 加载更多成员 * 加载社团成员
* *
*/ */
override fun loadMore(callback: (message: String) -> Unit) { fun load(id: Int, callback: (message: String) -> Unit) {
viewModelScope.launch { viewModelScope.launch {
_memberList.value?.let { HttpClient.post(
val t = mutableListOf<MemberVo>() Api.buildUrl(AssociationApi.LoadMember), HttpCallback<MutableList<UserInfoVo>>(
t.addAll(it) action = "加载社团成员",
t.apply { onSuccess = {
repeat(10) { it.body?.let {
add(MemberVo(name = "成员${t.size + 1}")) _data.postValue(it)
} }
} },
_memberList.postValue(t) typeToken = object : TypeToken<ApiResponse<MutableList<UserInfoVo>>>() {}.type
Logger.i("加载更多社团成员,size=${t.size}") ),
} 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)
} }
} }
@ -136,33 +99,4 @@ class OngoingActViewModel : ViewModel() {
*/ */
class HistoryActViewModel(application: Application) : ScrollViewModel<HistoryActVo>(application) { class HistoryActViewModel(application: Application) : ScrollViewModel<HistoryActVo>(application) {
override val initSize = 10 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<HistoryActVo>()
t.addAll(this)
t.apply {
repeat(10) {
add(HistoryActVo(name = "活动${t.size + 1}"))
}
}
_data.postValue(t)
callback("成功加载更多活动")
}
}
} }

@ -139,7 +139,7 @@ class ExamViewModel(application: Application) : ScrollViewModel<Exam>(applicatio
* 加载题目 * 加载题目
* *
*/ */
override fun load() { fun load() {
viewModelScope.launch { viewModelScope.launch {
_data.value?.apply { _data.value?.apply {
repeat(initSize) { repeat(initSize) {
@ -183,7 +183,7 @@ class ExamViewModel(application: Application) : ScrollViewModel<Exam>(applicatio
* *
* @param callback * @param callback
*/ */
override fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {
// _data.value?.apply { // _data.value?.apply {
// val list= mutableListOf<Exam>() // val list= mutableListOf<Exam>()
// list.addAll(this) // list.addAll(this)

@ -19,6 +19,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties import androidx.compose.ui.window.PopupProperties
@ -32,8 +33,6 @@ import com.gyf.csams.association.model.*
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.* import com.gyf.lib.uikit.*
import com.gyf.lib.util.HistoryActVo 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() { class AssociationActivity : ComponentActivity() {
val associationId: Int private val associationId: Int
get() { get() {
val id = intent.getIntExtra( val id = intent.getIntExtra(
AssociationActivity::javaClass.name, AssociationActivity::javaClass.name,
@ -218,8 +217,7 @@ class AssociationActivity : ComponentActivity() {
@Composable @Composable
private fun Search( private fun Search(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
model: MemberViewModel = viewModel(), model: MemberViewModel = viewModel()
scaffoldModel: ScaffoldModel = viewModel()
) { ) {
Column(modifier = modifier.fillMaxSize()) { Column(modifier = modifier.fillMaxSize()) {
Spacer(modifier = Modifier.weight(0.5F)) Spacer(modifier = Modifier.weight(0.5F))
@ -240,10 +238,14 @@ class AssociationActivity : ComponentActivity() {
) )
Spacer(modifier = Modifier.weight(spaceWeight)) Spacer(modifier = Modifier.weight(spaceWeight))
OutlinedButton( OutlinedButton(
onClick = { model.search { scaffoldModel.update(message = it) } }, onClick = {
model.load(associationId) {
}
},
modifier = Modifier.weight(buttonWeight) modifier = Modifier.weight(buttonWeight)
) { ) {
Text(text = model.search) Text(text = stringResource(id = R.string.search_btn))
} }
Spacer(modifier = Modifier.weight(spaceWeight)) Spacer(modifier = Modifier.weight(spaceWeight))
} }
@ -257,13 +259,15 @@ class AssociationActivity : ComponentActivity() {
@Composable @Composable
private fun MemberList( private fun MemberList(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
model: MemberViewModel = viewModel(), model: MemberViewModel = viewModel()
scaffoldModel: ScaffoldModel = viewModel()
) { ) {
val list: MutableList<MemberVo>? by model.memberList.observeAsState() model.load(associationId) {
}
val data by model.data.observeAsState()
val listState = rememberLazyListState() val listState = rememberLazyListState()
LazyColumn(state = listState, modifier = modifier) { LazyColumn(state = listState, modifier = modifier) {
list?.forEach { data?.forEach {
item { item {
Column { Column {
Spacer(modifier = Modifier.height(10.dp)) Spacer(modifier = Modifier.height(10.dp))
@ -289,8 +293,8 @@ class AssociationActivity : ComponentActivity() {
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
IconButton(onClick = { IconButton(onClick = {
model.loadMore { model.load(associationId) {
scaffoldModel.update(message = it)
} }
}) { }) {
Icon( Icon(
@ -445,12 +449,8 @@ class AssociationActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun OngoingActivity( private fun OngoingActivity(
modifier: Modifier = Modifier, modifier: Modifier = Modifier
model: OngoingActViewModel = viewModel()
) { ) {
val act by model.act.observeAsState()
// TODO 解决Build Warnning
Logger.i("$act")
Row(modifier = modifier.clickable(onClick = { Row(modifier = modifier.clickable(onClick = {
startActivity(Intent(this, ActivityDetailActivity::class.java)) startActivity(Intent(this, ActivityDetailActivity::class.java))
}), horizontalArrangement = Arrangement.Center) { }), horizontalArrangement = Arrangement.Center) {
@ -471,8 +471,7 @@ class AssociationActivity : ComponentActivity() {
@Composable @Composable
private fun HistoryActivityList( private fun HistoryActivityList(
modifier: Modifier, modifier: Modifier,
model: HistoryActViewModel = viewModel(), model: HistoryActViewModel = viewModel()
scaffoldModel: ScaffoldModel = viewModel()
) { ) {
val listState = rememberLazyListState() val listState = rememberLazyListState()
val list by model.data.observeAsState() val list by model.data.observeAsState()
@ -491,7 +490,7 @@ class AssociationActivity : ComponentActivity() {
} }
} }
if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) {
model.loadMore { scaffoldModel.update(message = it) } TODO("加载更多")
} }
} }

@ -147,13 +147,12 @@ class MarqueeViewModel : AbstractComment() {
* 社团列表 * 社团列表
* *
*/ */
class ListViewModel(application: Application) : ScrollViewModel<AssociationVo>(application) { class AssociationListViewModel(application: Application) :
ScrollViewModel<AssociationVo>(application) {
val name = StringForm(formDesc = "社团名称", textLength = 5) val name = StringForm(formDesc = "社团名称", textLength = 5)
val desc = StringForm(formDesc = "社团简介", textLength = 10) val desc = StringForm(formDesc = "社团简介", textLength = 10)
val searchDesc = "搜索"
override val initSize: Int = 10 override val initSize: Int = 10
init { init {
@ -164,7 +163,7 @@ class ListViewModel(application: Application) : ScrollViewModel<AssociationVo>(a
* 加载社团列表 * 加载社团列表
* *
*/ */
override fun load(callback: (message: String) -> Unit) { fun load(callback: (message: String) -> Unit) {
viewModelScope.launch { viewModelScope.launch {
HttpClient.post( HttpClient.post(
Api.buildUrl(AssociationApi.List), Api.buildUrl(AssociationApi.List),
@ -186,14 +185,6 @@ class ListViewModel(application: Application) : ScrollViewModel<AssociationVo>(a
) )
} }
} }
/**
* 加载更多社团列表
*
*/
override fun loadMore(callback: (message: String) -> Unit) {
TODO(NOT_IMPL_TIP)
}
} }

@ -16,6 +16,7 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
@ -187,9 +188,9 @@ class MainActivity : BaseActivity() {
mainMenu = MainMenu.List, mainMenu = MainMenu.List,
nav = navController nav = navController
) { ) {
val memberVo: AssociationMemberVo? = val associationVo: AssociationVo? =
(TokenManager.getOwnInfo() as? UserVo)?.associationMemberVo (TokenManager.getOwnInfo() as? UserVo)?.associationVo
if (memberVo == null) { if (associationVo == null) {
RegisterAssociation() RegisterAssociation()
} }
AssociationSearch() AssociationSearch()
@ -227,7 +228,7 @@ class MainActivity : BaseActivity() {
*/ */
@Composable @Composable
private fun AssociationListBody( private fun AssociationListBody(
model: ListViewModel = viewModel(), model: AssociationListViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel() scaffoldModel: ScaffoldModel = viewModel()
) { ) {
val associationListList: MutableList<AssociationVo>? by model.data.observeAsState() val associationListList: MutableList<AssociationVo>? by model.data.observeAsState()
@ -265,7 +266,7 @@ class MainActivity : BaseActivity() {
} }
if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) { 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 @Composable
private fun AssociationSearch( private fun AssociationSearch(
model: ListViewModel = viewModel(), model: AssociationListViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel() scaffoldModel: ScaffoldModel = viewModel()
) { ) {
Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) { Card(modifier = Modifier.padding(horizontal = 50.dp, vertical = 10.dp)) {
@ -334,7 +335,7 @@ class MainActivity : BaseActivity() {
}, },
modifier = Modifier.width(100.dp) modifier = Modifier.width(100.dp)
) { ) {
Text(text = model.searchDesc) Text(text = stringResource(id = R.string.search_btn))
} }
} }
Spacer( Spacer(

@ -9,16 +9,5 @@ abstract class ScrollViewModel<T>(application: Application) : AndroidViewModel(a
protected val _data = MutableLiveData<MutableList<T>>(mutableListOf()) protected val _data = MutableLiveData<MutableList<T>>(mutableListOf())
val data: LiveData<MutableList<T>> = _data val data: LiveData<MutableList<T>> = _data
abstract val initSize: Int open val initSize: Int = 10
//加载列表
@Deprecated("")
open fun load() {
}
open fun load(callback: (message: String) -> Unit) {}
//加载更多数据
abstract fun loadMore(callback: (message: String) -> Unit)
} }

@ -90,7 +90,7 @@ abstract class SysMessageViewModel(application: Application) :
abstract fun clientType(): ClientType abstract fun clientType(): ClientType
init { init {
load() load {}
} }
@ -98,7 +98,7 @@ abstract class SysMessageViewModel(application: Application) :
*加载通知列表 *加载通知列表
* *
*/ */
final override fun load() { fun load(callback: (message: String) -> Unit) {
viewModelScope.launch { viewModelScope.launch {
HttpClient.post( HttpClient.post(
Api.buildUrl(NotificationApi.List), 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)
}
} }

@ -57,8 +57,10 @@ enum class MainApi(val path: String) : UrlPath {
//热门活动 //热门活动
HotActivity("/hotActivity"), HotActivity("/hotActivity"),
//留言 //发送留言
LeaveMessage("/leaveMessage"), LeaveMessage("/leaveMessage"),
//获取留言
GetMessage("/getMessage"); GetMessage("/getMessage");
override fun build(): String { override fun build(): String {
@ -72,14 +74,33 @@ enum class MainApi(val path: String) : UrlPath {
* @property path * @property path
*/ */
enum class AssociationApi(val path: String) : UrlPath { enum class AssociationApi(val path: String) : UrlPath {
//上传logo
Logo("/uploadLogo"), Logo("/uploadLogo"),
//提交注册资料
Register("/register"), Register("/register"),
//受理注册资料
Accept("/accept"), Accept("/accept"),
//模糊查询社团
List("/list"), List("/list"),
//审核注册资料
Check("/check"), Check("/check"),
//社团注册资料列表
Audit("/audit"), Audit("/audit"),
//审核进度
Read("/read"), Read("/read"),
Load("/load");
//id精确查询社团
Load("/load"),
//加载社团成员
LoadMember("${Load.path}/members");
override fun build(): String { override fun build(): String {
return "/api/association${this.path}" return "/api/association${this.path}"
@ -87,7 +108,10 @@ enum class AssociationApi(val path: String) : UrlPath {
} }
enum class NotificationApi(val path: String) : UrlPath { enum class NotificationApi(val path: String) : UrlPath {
//通知计数
Count("/count"), Count("/count"),
//
List("/list"), List("/list"),
Pull("/pull"); Pull("/pull");

@ -102,7 +102,8 @@ data class UserVo(
override val name: String, override val name: String,
override val headImg: String?, override val headImg: String?,
override val desc: String, override val desc: String,
val associationMemberVo: AssociationMemberVo? val associationVo: AssociationVo?,
val isHead: Boolean?
) : OwnInfoVo() ) : OwnInfoVo()
data class PageDto(val currentPage: Long, val pageSize: Int = 10) data class PageDto(val currentPage: Long, val pageSize: Int = 10)
@ -164,21 +165,6 @@ data class ActivityDetailVo(
val activityDesc: String 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<ActivityMemberVo>?
)
/** /**
* 图片 * 图片
* @property name 文件名 * @property name 文件名
@ -333,6 +319,12 @@ data class ShowAssociationVo(
) : ClientBaseVo() ) : 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) 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 ManagerLoginVo(val account: String, val password: String, val device: String)
data class MemberVo(val name: String)
data class OngoingActVo(val name: String) data class OngoingActVo(val name: String)
/** /**

Loading…
Cancel
Save