From 5249723790b66b7c9df76b2556b3230b01c4c021 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:42:39 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E4=BB=A4=20ViewModel=20=E4=B8=BA=20@St?= =?UTF-8?q?able=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/page/editprofile/viewmodel/EditProfileViewModel.kt | 8 ++++++++ .../tieba/post/ui/page/forum/ForumViewModel.kt | 2 ++ .../ui/page/forum/threadlist/ForumThreadListViewModel.kt | 3 +++ .../post/ui/page/history/list/HistoryListViewModel.kt | 3 +++ .../post/ui/page/hottopic/list/HotTopicListViewModel.kt | 2 ++ .../huanchengfly/tieba/post/ui/page/main/MainViewModel.kt | 2 ++ .../post/ui/page/main/explore/concern/ConcernViewModel.kt | 2 ++ .../tieba/post/ui/page/main/explore/hot/HotViewModel.kt | 2 ++ .../main/explore/personalized/PersonalizedViewModel.kt | 3 +++ .../main/notifications/list/NotificationsListViewModel.kt | 3 +++ .../tieba/post/ui/page/main/user/UserViewModel.kt | 2 ++ .../post/ui/page/threadstore/ThreadStoreViewModel.kt | 2 ++ 12 files changed, 34 insertions(+) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/editprofile/viewmodel/EditProfileViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/editprofile/viewmodel/EditProfileViewModel.kt index c30af8ff..fe418c60 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/editprofile/viewmodel/EditProfileViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/editprofile/viewmodel/EditProfileViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.editprofile.viewmodel +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.interfaces.ITiebaApi import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode @@ -17,6 +18,7 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* import javax.inject.Inject +@Stable @HiltViewModel class EditProfileViewModel @Inject constructor() : BaseViewModel() { @@ -113,24 +115,30 @@ class EditProfileViewModel @Inject constructor() : false, message = partialChange.error ) + EditProfilePartialChange.Submit.Success -> EditProfileEvent.Submit.Result( true, changed = false ) + EditProfilePartialChange.Submit.SuccessWithoutChange -> EditProfileEvent.Submit.Result( true ) + EditProfilePartialChange.ModifyNickname.Start -> EditProfileEvent.ModifyNickname.Start is EditProfilePartialChange.ModifyNickname.Finish -> EditProfileEvent.ModifyNickname.Finish( partialChange.result ) + EditProfilePartialChange.UploadPortrait.Start -> EditProfileEvent.UploadPortrait.Pick is EditProfilePartialChange.UploadPortrait.Success -> EditProfileEvent.UploadPortrait.Success( partialChange.message ) + is EditProfilePartialChange.UploadPortrait.Fail -> EditProfileEvent.UploadPortrait.Fail( partialChange.error ) + else -> null } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/ForumViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/ForumViewModel.kt index 87444ae4..843dbfdb 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/ForumViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/ForumViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.forum +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.CommonResponse import com.huanchengfly.tieba.post.api.models.LikeForumResultBean @@ -24,6 +25,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class ForumViewModel @Inject constructor() : BaseViewModel() { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt index b05cb185..103a3bc8 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.forum.threadlist +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo @@ -56,12 +57,14 @@ enum class ForumThreadListType { Latest, Good } +@Stable @HiltViewModel class LatestThreadListViewModel @Inject constructor() : ForumThreadListViewModel() { override fun createPartialChangeProducer(): PartialChangeProducer = ForumThreadListPartialChangeProducer(ForumThreadListType.Latest) } +@Stable @HiltViewModel class GoodThreadListViewModel @Inject constructor() : ForumThreadListViewModel() { override fun createPartialChangeProducer(): PartialChangeProducer = diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/history/list/HistoryListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/history/list/HistoryListViewModel.kt index 57760102..3c22b014 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/history/list/HistoryListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/history/list/HistoryListViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.history.list +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage import com.huanchengfly.tieba.post.arch.BaseViewModel import com.huanchengfly.tieba.post.arch.PartialChange @@ -43,12 +44,14 @@ abstract class HistoryListViewModel : } } +@Stable @HiltViewModel class ThreadHistoryListViewModel @Inject constructor() : HistoryListViewModel() { override fun createPartialChangeProducer(): PartialChangeProducer = HistoryListPartialChangeProducer(HistoryUtil.TYPE_THREAD) } +@Stable @HiltViewModel class ForumHistoryListViewModel @Inject constructor() : HistoryListViewModel() { override fun createPartialChangeProducer(): PartialChangeProducer = diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/hottopic/list/HotTopicListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/hottopic/list/HotTopicListViewModel.kt index 5e0467f3..c44d8647 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/hottopic/list/HotTopicListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/hottopic/list/HotTopicListViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.hottopic.list +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.protos.topicList.NewTopicList import com.huanchengfly.tieba.post.api.models.protos.topicList.TopicListResponse @@ -20,6 +21,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class HotTopicListViewModel @Inject constructor() : BaseViewModel() { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/MainViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/MainViewModel.kt index 382980e7..1ca086eb 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/MainViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/MainViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.arch.BaseViewModel import com.huanchengfly.tieba.post.arch.PartialChange import com.huanchengfly.tieba.post.arch.PartialChangeProducer @@ -13,6 +14,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import javax.inject.Inject +@Stable @HiltViewModel class MainViewModel @Inject constructor() : BaseViewModel() { override fun createInitialState(): MainUiState = MainUiState() diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt index cb5f3d1f..846a5e05 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main.explore.concern +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.App import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.AgreeBean @@ -26,6 +27,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class ConcernViewModel @Inject constructor() : BaseViewModel() { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/hot/HotViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/hot/HotViewModel.kt index 6cf18ace..8b68347f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/hot/HotViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/hot/HotViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main.explore.hot +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.protos.FrsTabInfo import com.huanchengfly.tieba.post.api.models.protos.RecommendTopicList @@ -22,6 +23,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class HotViewModel @Inject constructor() : BaseViewModel() { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt index 200477e6..dd3e6f3d 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main.explore.personalized +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.CommonResponse @@ -29,6 +30,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class PersonalizedViewModel @Inject constructor() : BaseViewModel() { @@ -44,6 +46,7 @@ class PersonalizedViewModel @Inject constructor() : is PersonalizedPartialChange.Refresh.Success -> PersonalizedUiEvent.RefreshSuccess( partialChange.data.size ) + else -> null } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt index d13e00fb..414febce 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main.notifications.list +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.MessageListBean import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage @@ -22,6 +23,7 @@ abstract class NotificationsListViewModel : } } +@Stable @HiltViewModel class ReplyMeListViewModel @Inject constructor() : NotificationsListViewModel() { override fun createPartialChangeProducer(): @@ -30,6 +32,7 @@ class ReplyMeListViewModel @Inject constructor() : NotificationsListViewModel() } } +@Stable @HiltViewModel class AtMeListViewModel @Inject constructor() : NotificationsListViewModel() { override fun createPartialChangeProducer(): diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/user/UserViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/user/UserViewModel.kt index aa05ab2e..5a8efd2c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/user/UserViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/user/UserViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.main.user +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.Profile import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage @@ -11,6 +12,7 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* import javax.inject.Inject +@Stable @HiltViewModel class UserViewModel @Inject constructor() : BaseViewModel() { override fun createInitialState(): UserUiState = diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStoreViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStoreViewModel.kt index c164b00b..b69e2283 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStoreViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStoreViewModel.kt @@ -1,5 +1,6 @@ package com.huanchengfly.tieba.post.ui.page.threadstore +import androidx.compose.runtime.Stable import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.CommonResponse import com.huanchengfly.tieba.post.api.models.ThreadStoreBean @@ -24,6 +25,7 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +@Stable @HiltViewModel class ThreadStoreViewModel @Inject constructor() : BaseViewModel() {