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 {