From fc324240b6683c0cf9716df1b10d65c422476d0b Mon Sep 17 00:00:00 2001 From: AllenTom Date: Fri, 6 Sep 2024 15:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A8=E6=80=81=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E6=98=BE=E7=A4=BA=E7=83=AD=E9=97=A8=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../riderpro/ui/index/tabs/moment/MomentViewModel.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/moment/MomentViewModel.kt b/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/moment/MomentViewModel.kt index c22bd5b..e78c180 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/moment/MomentViewModel.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/moment/MomentViewModel.kt @@ -28,8 +28,10 @@ object MomentViewModel : ViewModel() { private val _momentsFlow = MutableStateFlow>(PagingData.empty()) val momentsFlow = _momentsFlow.asStateFlow() val accountService: AccountService = AccountServiceImpl() + var existsException = mutableStateOf(false) init { viewModelScope.launch { + // 获取当前用户信息 val profile = accountService.getMyAccountProfile() Pager( config = PagingConfig(pageSize = 5, enablePlaceholders = false), @@ -47,12 +49,19 @@ object MomentViewModel : ViewModel() { fun refreshPager() { viewModelScope.launch { val profile = accountService.getMyAccountProfile() + // 检查是否有动态 + val existMoments = momentService.getMoments(timelineId = profile.id, pageNumber = 1) + if (existMoments.list.isEmpty()) { + existsException.value = true + } Pager( config = PagingConfig(pageSize = 5, enablePlaceholders = false), pagingSourceFactory = { MomentPagingSource( MomentRemoteDataSource(momentService), - timelineId = profile.id + // 如果没有动态,则显示热门动态 + timelineId = if (existMoments.list.isEmpty()) null else profile.id, + trend = if (existMoments.list.isEmpty()) true else null ) } ).flow.cachedIn(viewModelScope).collectLatest {