完成登出
This commit is contained in:
@@ -1,5 +1,43 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import com.aiosman.riderpro.ui.favourite.FavouriteListViewModel
|
||||
import com.aiosman.riderpro.ui.favourite.FavouriteNoticeViewModel
|
||||
import com.aiosman.riderpro.ui.follower.FollowerNoticeViewModel
|
||||
import com.aiosman.riderpro.ui.follower.FollowingListViewModel
|
||||
import com.aiosman.riderpro.ui.index.IndexViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.message.MessageListViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.moment.MomentViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.search.DiscoverViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.search.SearchViewModel
|
||||
import com.aiosman.riderpro.ui.like.LikeNoticeViewModel
|
||||
|
||||
object AppState {
|
||||
var UserId: Int? = null
|
||||
|
||||
fun ReloadAppState() {
|
||||
// 重置动态列表页面
|
||||
MomentViewModel.ResetModel()
|
||||
// 重置我的页面
|
||||
MyProfileViewModel.ResetModel()
|
||||
// 重置发现页面
|
||||
DiscoverViewModel.ResetModel()
|
||||
// 重置搜索页面
|
||||
SearchViewModel.ResetModel()
|
||||
// 重置消息页面
|
||||
MessageListViewModel.ResetModel()
|
||||
// 重置点赞通知页面
|
||||
LikeNoticeViewModel.ResetModel()
|
||||
// 重置收藏页面
|
||||
FavouriteListViewModel.ResetModel()
|
||||
// 重置收藏通知页面
|
||||
FavouriteNoticeViewModel.ResetModel()
|
||||
// 重置粉丝通知页面
|
||||
FollowerNoticeViewModel.ResetModel()
|
||||
// 重置关注列表页面
|
||||
FollowingListViewModel.ResetModel()
|
||||
// 重置关注通知页面
|
||||
IndexViewModel.ResetModel()
|
||||
UserId = null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
import com.aiosman.riderpro.AppState
|
||||
import com.aiosman.riderpro.data.api.ApiClient
|
||||
import com.aiosman.riderpro.data.api.ChangePasswordRequestBody
|
||||
import com.aiosman.riderpro.data.api.GoogleRegisterRequestBody
|
||||
@@ -366,6 +367,7 @@ class AccountServiceImpl : AccountService {
|
||||
override suspend fun getMyAccount(): UserAuth {
|
||||
val resp = ApiClient.api.checkToken()
|
||||
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
||||
AppState.UserId = body.id
|
||||
return UserAuth(body.id)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
||||
import androidx.compose.material.pullrefresh.pullRefresh
|
||||
import androidx.compose.material.pullrefresh.rememberPullRefreshState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -28,6 +29,7 @@ import com.aiosman.riderpro.ui.NavigationRoute
|
||||
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
|
||||
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
|
||||
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
|
||||
import com.aiosman.riderpro.ui.favourite.FavouriteListViewModel.refreshPager
|
||||
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@@ -41,6 +43,9 @@ fun FavouriteListPage() {
|
||||
val state = rememberPullRefreshState(FavouriteListViewModel.isLoading, onRefresh = {
|
||||
model.refreshPager(force = true)
|
||||
})
|
||||
LaunchedEffect(Unit) {
|
||||
refreshPager()
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.aiosman.riderpro.entity.MomentEntity
|
||||
import com.aiosman.riderpro.entity.MomentPagingSource
|
||||
import com.aiosman.riderpro.entity.MomentRemoteDataSource
|
||||
import com.aiosman.riderpro.entity.MomentServiceImpl
|
||||
import com.aiosman.riderpro.ui.index.tabs.moment.MomentViewModel.accountService
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
@@ -27,9 +26,6 @@ object FavouriteListViewModel:ViewModel() {
|
||||
MutableStateFlow<PagingData<MomentEntity>>(PagingData.empty())
|
||||
val favouriteMomentsFlow = _favouriteMomentsFlow.asStateFlow()
|
||||
var isLoading by mutableStateOf(false)
|
||||
init {
|
||||
refreshPager()
|
||||
}
|
||||
fun refreshPager(force:Boolean = false) {
|
||||
viewModelScope.launch {
|
||||
if (force) {
|
||||
@@ -50,4 +46,7 @@ object FavouriteListViewModel:ViewModel() {
|
||||
|
||||
}
|
||||
}
|
||||
fun ResetModel() {
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,8 @@ object FavouriteNoticeViewModel : ViewModel() {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun ResetModel() {
|
||||
isFirstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -75,4 +75,7 @@ object FollowerNoticeViewModel : ViewModel() {
|
||||
)
|
||||
)
|
||||
}
|
||||
fun ResetModel() {
|
||||
isFirstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -62,4 +62,8 @@ object FollowingListViewModel : ViewModel() {
|
||||
updateIsFollow(userId, false)
|
||||
}
|
||||
|
||||
fun ResetModel(){
|
||||
userId = null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,4 +7,9 @@ import androidx.lifecycle.ViewModel
|
||||
|
||||
object IndexViewModel:ViewModel() {
|
||||
var tabIndex by mutableStateOf(0)
|
||||
|
||||
fun ResetModel(){
|
||||
tabIndex = 0
|
||||
}
|
||||
|
||||
}
|
||||
@@ -104,4 +104,10 @@ object MessageListViewModel : ViewModel() {
|
||||
noticeInfo = it.copy(commentCount = it.commentCount + delta)
|
||||
}
|
||||
}
|
||||
fun ResetModel(){
|
||||
_commentItemsFlow.value = PagingData.empty()
|
||||
noticeInfo = null
|
||||
isLoading = false
|
||||
isFirstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,9 @@ fun MomentsList() {
|
||||
val navigationBarPaddings =
|
||||
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + 48.dp
|
||||
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
||||
LaunchedEffect(Unit) {
|
||||
model.refreshPager()
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
|
||||
@@ -29,20 +29,21 @@ object MomentViewModel : ViewModel() {
|
||||
private val momentService: MomentService = MomentServiceImpl()
|
||||
private val _momentsFlow = MutableStateFlow<PagingData<MomentEntity>>(PagingData.empty())
|
||||
val momentsFlow = _momentsFlow.asStateFlow()
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
var existsMoment = mutableStateOf(false)
|
||||
var refreshing by mutableStateOf(false)
|
||||
init {
|
||||
refreshPager()
|
||||
}
|
||||
|
||||
var isFirstLoad = true
|
||||
fun refreshPager(pullRefresh: Boolean = false) {
|
||||
if (!isFirstLoad) {
|
||||
return
|
||||
}
|
||||
isFirstLoad = false
|
||||
viewModelScope.launch {
|
||||
if (pullRefresh) {
|
||||
refreshing = true
|
||||
}
|
||||
// 检查是否有动态
|
||||
val existMoments = momentService.getMoments(timelineId = AppState.UserId, pageNumber = 1)
|
||||
val existMoments =
|
||||
momentService.getMoments(timelineId = AppState.UserId, pageNumber = 1)
|
||||
if (existMoments.list.isEmpty()) {
|
||||
existsMoment.value = true
|
||||
}
|
||||
@@ -162,7 +163,7 @@ object MomentViewModel : ViewModel() {
|
||||
/**
|
||||
* 更新动态评论数
|
||||
*/
|
||||
fun updateMomentCommentCount(id: Int,delta: Int) {
|
||||
fun updateMomentCommentCount(id: Int, delta: Int) {
|
||||
val currentPagingData = _momentsFlow.value
|
||||
val updatedPagingData = currentPagingData.map { momentItem ->
|
||||
if (momentItem.id == id) {
|
||||
@@ -173,4 +174,9 @@ object MomentViewModel : ViewModel() {
|
||||
}
|
||||
_momentsFlow.value = updatedPagingData
|
||||
}
|
||||
|
||||
fun ResetModel() {
|
||||
_momentsFlow.value = PagingData.empty()
|
||||
isFirstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.cachedIn
|
||||
import com.aiosman.riderpro.AppState
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.AccountServiceImpl
|
||||
@@ -75,7 +76,9 @@ object MyProfileViewModel : ViewModel() {
|
||||
token = null
|
||||
rememberMe = false
|
||||
saveData()
|
||||
|
||||
}
|
||||
AppState.ReloadAppState()
|
||||
}
|
||||
|
||||
fun updateUserProfileBanner(bannerImageUrl: Uri?, context: Context) {
|
||||
@@ -106,11 +109,14 @@ object MyProfileViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
val followerCount get() = profile?.followerCount ?: 0
|
||||
val followingCount get() = profile?.followingCount ?: 0
|
||||
val bio get() = profile?.bio ?: ""
|
||||
val nickName get() = profile?.nickName ?: ""
|
||||
val avatar get() = profile?.avatar
|
||||
|
||||
fun ResetModel() {
|
||||
profile = null
|
||||
_momentsFlow.value = PagingData.empty()
|
||||
firstLoad = true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,12 +60,10 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
fun DiscoverScreen() {
|
||||
val model = DiscoverViewModel
|
||||
val navController = LocalNavController.current
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
||||
val navigationBarPaddings =
|
||||
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + 48.dp
|
||||
LaunchedEffect(Unit) {
|
||||
systemUiController.setStatusBarColor(Color.Transparent, darkIcons = true)
|
||||
DiscoverViewModel.refreshPager()
|
||||
}
|
||||
var refreshing by remember { mutableStateOf(false) }
|
||||
val state = rememberPullRefreshState(refreshing, onRefresh = {
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.aiosman.riderpro.entity.MomentEntity
|
||||
import com.aiosman.riderpro.entity.MomentPagingSource
|
||||
import com.aiosman.riderpro.entity.MomentRemoteDataSource
|
||||
import com.aiosman.riderpro.entity.MomentServiceImpl
|
||||
import com.aiosman.riderpro.ui.index.tabs.moment.MomentViewModel.accountService
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
@@ -22,7 +21,12 @@ object DiscoverViewModel:ViewModel() {
|
||||
private val _discoverMomentsFlow =
|
||||
MutableStateFlow<PagingData<MomentEntity>>(PagingData.empty())
|
||||
val discoverMomentsFlow = _discoverMomentsFlow.asStateFlow()
|
||||
init {
|
||||
var firstLoad = true
|
||||
fun refreshPager() {
|
||||
if (!firstLoad) {
|
||||
return
|
||||
}
|
||||
firstLoad = false
|
||||
viewModelScope.launch {
|
||||
Pager(
|
||||
config = PagingConfig(pageSize = 5, enablePlaceholders = false),
|
||||
@@ -37,19 +41,7 @@ object DiscoverViewModel:ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
fun refreshPager() {
|
||||
viewModelScope.launch {
|
||||
Pager(
|
||||
config = PagingConfig(pageSize = 5, enablePlaceholders = false),
|
||||
pagingSourceFactory = {
|
||||
MomentPagingSource(
|
||||
MomentRemoteDataSource(momentService),
|
||||
trend = true
|
||||
)
|
||||
}
|
||||
).flow.cachedIn(viewModelScope).collectLatest {
|
||||
_discoverMomentsFlow.value = it
|
||||
}
|
||||
}
|
||||
fun ResetModel(){
|
||||
firstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,10 @@ object SearchViewModel : ViewModel() {
|
||||
}
|
||||
showResult = true
|
||||
}
|
||||
|
||||
fun ResetModel(){
|
||||
_momentsFlow.value = PagingData.empty()
|
||||
_usersFlow.value = PagingData.empty()
|
||||
showResult = false
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,8 @@ object LikeNoticeViewModel : ViewModel() {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun ResetModel() {
|
||||
isFirstLoad = true
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,7 @@ fun UserAuthScreen() {
|
||||
this.rememberMe = rememberMe
|
||||
saveData()
|
||||
}
|
||||
accountService.getMyAccount()
|
||||
Messaging.RegistDevice(scope, context)
|
||||
navController.navigate(NavigationRoute.Index.route) {
|
||||
popUpTo(NavigationRoute.Login.route) { inclusive = true }
|
||||
|
||||
Reference in New Issue
Block a user