parent
8d4decf608
commit
6ce62e3e61
@ -27,7 +27,7 @@ class InboxViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch {
|
||||||
identityRepository.isLogged.onEach { logged ->
|
identityRepository.isLogged.onEach { logged ->
|
||||||
mvi.updateState { it.copy(isLogged = logged) }
|
mvi.updateState { it.copy(isLogged = logged) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
@ -17,7 +17,6 @@ class ProfileMainViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
|
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch {
|
||||||
identityRepository.isLogged.onEach { logged ->
|
identityRepository.isLogged.onEach { logged ->
|
||||||
mvi.updateState { it.copy(logged = logged) }
|
mvi.updateState { it.copy(logged = logged) }
|
||||||
|
@ -57,7 +57,7 @@ class ExploreViewModel(
|
|||||||
instance = apiConfigRepository.instance.value,
|
instance = apiConfigRepository.instance.value,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mvi.scope?.launch(Dispatchers.Main) {
|
mvi.scope?.launch {
|
||||||
identityRepository.isLogged.onEach { isLogged ->
|
identityRepository.isLogged.onEach { isLogged ->
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
it.copy(isLogged = isLogged ?: false)
|
it.copy(isLogged = isLogged ?: false)
|
||||||
|
@ -32,6 +32,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toSortType
|
|||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.GetSortTypesUseCase
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.GetSortTypesUseCase
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.resources.LanguageRepository
|
import com.github.diegoberaldin.raccoonforlemmy.resources.LanguageRepository
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.IO
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -55,7 +56,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.scope?.launch(Dispatchers.Main) {
|
mvi.scope?.launch {
|
||||||
themeRepository.uiTheme.onEach { value ->
|
themeRepository.uiTheme.onEach { value ->
|
||||||
mvi.updateState { it.copy(uiTheme = value) }
|
mvi.updateState { it.copy(uiTheme = value) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
@ -342,7 +343,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeTheme(value: UiTheme?) {
|
private fun changeTheme(value: UiTheme?) {
|
||||||
themeRepository.changeUiTheme(value)
|
themeRepository.changeUiTheme(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
theme = value?.toInt()
|
theme = value?.toInt()
|
||||||
)
|
)
|
||||||
@ -352,7 +353,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeFontFamily(value: UiFontFamily) {
|
private fun changeFontFamily(value: UiFontFamily) {
|
||||||
themeRepository.changeUiFontFamily(value)
|
themeRepository.changeUiFontFamily(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
uiFontFamily = value.toInt()
|
uiFontFamily = value.toInt()
|
||||||
)
|
)
|
||||||
@ -362,7 +363,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeUiFontScale(value: Float) {
|
private fun changeUiFontScale(value: Float) {
|
||||||
themeRepository.changeUiFontScale(value)
|
themeRepository.changeUiFontScale(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
uiFontScale = value
|
uiFontScale = value
|
||||||
)
|
)
|
||||||
@ -372,7 +373,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeContentFontScale(value: Float) {
|
private fun changeContentFontScale(value: Float) {
|
||||||
themeRepository.changeContentFontScale(value)
|
themeRepository.changeContentFontScale(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
contentFontScale = value
|
contentFontScale = value
|
||||||
)
|
)
|
||||||
@ -382,7 +383,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeContentFontFamily(value: UiFontFamily) {
|
private fun changeContentFontFamily(value: UiFontFamily) {
|
||||||
themeRepository.changeContentFontFamily(value)
|
themeRepository.changeContentFontFamily(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
contentFontFamily = value.toInt()
|
contentFontFamily = value.toInt()
|
||||||
)
|
)
|
||||||
@ -392,7 +393,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeLanguage(value: String) {
|
private fun changeLanguage(value: String) {
|
||||||
languageRepository.changeLanguage(value)
|
languageRepository.changeLanguage(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
locale = value
|
locale = value
|
||||||
)
|
)
|
||||||
@ -402,7 +403,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDefaultListingType(value: ListingType) {
|
private fun changeDefaultListingType(value: ListingType) {
|
||||||
mvi.updateState { it.copy(defaultListingType = value) }
|
mvi.updateState { it.copy(defaultListingType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
defaultListingType = value.toInt()
|
defaultListingType = value.toInt()
|
||||||
)
|
)
|
||||||
@ -414,7 +415,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDefaultPostSortType(value: SortType) {
|
private fun changeDefaultPostSortType(value: SortType) {
|
||||||
mvi.updateState { it.copy(defaultPostSortType = value) }
|
mvi.updateState { it.copy(defaultPostSortType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
defaultPostSortType = value.toInt()
|
defaultPostSortType = value.toInt()
|
||||||
)
|
)
|
||||||
@ -426,7 +427,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDefaultCommentSortType(value: SortType) {
|
private fun changeDefaultCommentSortType(value: SortType) {
|
||||||
mvi.updateState { it.copy(defaultCommentSortType = value) }
|
mvi.updateState { it.copy(defaultCommentSortType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
defaultCommentSortType = value.toInt()
|
defaultCommentSortType = value.toInt()
|
||||||
)
|
)
|
||||||
@ -436,7 +437,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeNavBarTitlesVisible(value: Boolean) {
|
private fun changeNavBarTitlesVisible(value: Boolean) {
|
||||||
themeRepository.changeNavItemTitles(value)
|
themeRepository.changeNavItemTitles(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
navigationTitlesVisible = value
|
navigationTitlesVisible = value
|
||||||
)
|
)
|
||||||
@ -446,7 +447,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeIncludeNsfw(value: Boolean) {
|
private fun changeIncludeNsfw(value: Boolean) {
|
||||||
mvi.updateState { it.copy(includeNsfw = value) }
|
mvi.updateState { it.copy(includeNsfw = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
includeNsfw = value
|
includeNsfw = value
|
||||||
)
|
)
|
||||||
@ -456,7 +457,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeBlurNsfw(value: Boolean) {
|
private fun changeBlurNsfw(value: Boolean) {
|
||||||
mvi.updateState { it.copy(blurNsfw = value) }
|
mvi.updateState { it.copy(blurNsfw = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
blurNsfw = value
|
blurNsfw = value
|
||||||
)
|
)
|
||||||
@ -466,7 +467,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDynamicColors(value: Boolean) {
|
private fun changeDynamicColors(value: Boolean) {
|
||||||
themeRepository.changeDynamicColors(value)
|
themeRepository.changeDynamicColors(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
dynamicColors = value
|
dynamicColors = value
|
||||||
)
|
)
|
||||||
@ -476,7 +477,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeCustomSeedColor(value: Color?) {
|
private fun changeCustomSeedColor(value: Color?) {
|
||||||
themeRepository.changeCustomSeedColor(value)
|
themeRepository.changeCustomSeedColor(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
customSeedColor = value?.toArgb()
|
customSeedColor = value?.toArgb()
|
||||||
)
|
)
|
||||||
@ -486,7 +487,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeUpvoteColor(value: Color?) {
|
private fun changeUpvoteColor(value: Color?) {
|
||||||
themeRepository.changeUpvoteColor(value)
|
themeRepository.changeUpvoteColor(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
upvoteColor = value?.toArgb()
|
upvoteColor = value?.toArgb()
|
||||||
)
|
)
|
||||||
@ -496,7 +497,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDownvoteColor(value: Color?) {
|
private fun changeDownvoteColor(value: Color?) {
|
||||||
themeRepository.changeDownvoteColor(value)
|
themeRepository.changeDownvoteColor(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
downvoteColor = value?.toArgb()
|
downvoteColor = value?.toArgb()
|
||||||
)
|
)
|
||||||
@ -506,7 +507,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeOpenUrlsInExternalBrowser(value: Boolean) {
|
private fun changeOpenUrlsInExternalBrowser(value: Boolean) {
|
||||||
mvi.updateState { it.copy(openUrlsInExternalBrowser = value) }
|
mvi.updateState { it.copy(openUrlsInExternalBrowser = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
openUrlsInExternalBrowser = value
|
openUrlsInExternalBrowser = value
|
||||||
)
|
)
|
||||||
@ -516,7 +517,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeEnableSwipeActions(value: Boolean) {
|
private fun changeEnableSwipeActions(value: Boolean) {
|
||||||
mvi.updateState { it.copy(enableSwipeActions = value) }
|
mvi.updateState { it.copy(enableSwipeActions = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
enableSwipeActions = value
|
enableSwipeActions = value
|
||||||
)
|
)
|
||||||
@ -526,7 +527,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeEnableDoubleTapAction(value: Boolean) {
|
private fun changeEnableDoubleTapAction(value: Boolean) {
|
||||||
mvi.updateState { it.copy(enableDoubleTapAction = value) }
|
mvi.updateState { it.copy(enableDoubleTapAction = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
enableDoubleTapAction = value
|
enableDoubleTapAction = value
|
||||||
)
|
)
|
||||||
@ -536,7 +537,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changePostLayout(value: PostLayout) {
|
private fun changePostLayout(value: PostLayout) {
|
||||||
themeRepository.changePostLayout(value)
|
themeRepository.changePostLayout(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
postLayout = value.toInt()
|
postLayout = value.toInt()
|
||||||
)
|
)
|
||||||
@ -552,7 +553,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeVoteFormat(value: VoteFormat) {
|
private fun changeVoteFormat(value: VoteFormat) {
|
||||||
mvi.updateState { it.copy(voteFormat = value) }
|
mvi.updateState { it.copy(voteFormat = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
voteFormat = value
|
voteFormat = value
|
||||||
)
|
)
|
||||||
@ -562,7 +563,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeAutoLoadImages(value: Boolean) {
|
private fun changeAutoLoadImages(value: Boolean) {
|
||||||
mvi.updateState { it.copy(autoLoadImages = value) }
|
mvi.updateState { it.copy(autoLoadImages = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
autoLoadImages = value
|
autoLoadImages = value
|
||||||
)
|
)
|
||||||
@ -572,7 +573,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeAutoExpandComments(value: Boolean) {
|
private fun changeAutoExpandComments(value: Boolean) {
|
||||||
mvi.updateState { it.copy(autoExpandComments = value) }
|
mvi.updateState { it.copy(autoExpandComments = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
autoExpandComments = value
|
autoExpandComments = value
|
||||||
)
|
)
|
||||||
@ -582,7 +583,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeFullHeightImages(value: Boolean) {
|
private fun changeFullHeightImages(value: Boolean) {
|
||||||
mvi.updateState { it.copy(fullHeightImages = value) }
|
mvi.updateState { it.copy(fullHeightImages = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
fullHeightImages = value
|
fullHeightImages = value
|
||||||
)
|
)
|
||||||
@ -592,7 +593,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeHideNavigationBarWhileScrolling(value: Boolean) {
|
private fun changeHideNavigationBarWhileScrolling(value: Boolean) {
|
||||||
mvi.updateState { it.copy(hideNavigationBarWhileScrolling = value) }
|
mvi.updateState { it.copy(hideNavigationBarWhileScrolling = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
hideNavigationBarWhileScrolling = value
|
hideNavigationBarWhileScrolling = value
|
||||||
)
|
)
|
||||||
@ -602,7 +603,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeMarkAsReadWhileScrolling(value: Boolean) {
|
private fun changeMarkAsReadWhileScrolling(value: Boolean) {
|
||||||
mvi.updateState { it.copy(markAsReadWhileScrolling = value) }
|
mvi.updateState { it.copy(markAsReadWhileScrolling = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
markAsReadWhileScrolling = value
|
markAsReadWhileScrolling = value
|
||||||
)
|
)
|
||||||
@ -612,7 +613,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeZombieModeInterval(value: Duration) {
|
private fun changeZombieModeInterval(value: Duration) {
|
||||||
mvi.updateState { it.copy(zombieModeInterval = value) }
|
mvi.updateState { it.copy(zombieModeInterval = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
zombieModeInterval = value
|
zombieModeInterval = value
|
||||||
)
|
)
|
||||||
@ -622,7 +623,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeZombieModeScrollAmount(value: Float) {
|
private fun changeZombieModeScrollAmount(value: Float) {
|
||||||
mvi.updateState { it.copy(zombieModeScrollAmount = value) }
|
mvi.updateState { it.copy(zombieModeScrollAmount = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
zombieModeScrollAmount = value
|
zombieModeScrollAmount = value
|
||||||
)
|
)
|
||||||
@ -632,7 +633,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeDefaultInboxUnreadOnly(value: Boolean) {
|
private fun changeDefaultInboxUnreadOnly(value: Boolean) {
|
||||||
mvi.updateState { it.copy(defaultInboxUnreadOnly = value) }
|
mvi.updateState { it.copy(defaultInboxUnreadOnly = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
defaultInboxType = value.toInboxDefaultType(),
|
defaultInboxType = value.toInboxDefaultType(),
|
||||||
)
|
)
|
||||||
@ -642,7 +643,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeCommentBarTheme(value: CommentBarTheme) {
|
private fun changeCommentBarTheme(value: CommentBarTheme) {
|
||||||
themeRepository.changeCommentBarTheme(value)
|
themeRepository.changeCommentBarTheme(value)
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
commentBarTheme = value.toInt()
|
commentBarTheme = value.toInt()
|
||||||
)
|
)
|
||||||
@ -652,7 +653,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun changeSearchPostTitleOnly(value: Boolean) {
|
private fun changeSearchPostTitleOnly(value: Boolean) {
|
||||||
mvi.updateState { it.copy(searchPostTitleOnly = value) }
|
mvi.updateState { it.copy(searchPostTitleOnly = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.currentSettings.value.copy(
|
val settings = settingsRepository.currentSettings.value.copy(
|
||||||
searchPostTitleOnly = value
|
searchPostTitleOnly = value
|
||||||
)
|
)
|
||||||
@ -667,7 +668,7 @@ class SettingsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLogout() {
|
private fun handleLogout() {
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val settings = settingsRepository.getSettings(null)
|
val settings = settingsRepository.getSettings(null)
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
@ -209,7 +209,7 @@ class InboxChatViewModel(
|
|||||||
private fun submitNewMessage(text: String) {
|
private fun submitNewMessage(text: String) {
|
||||||
val editedMessageId = uiState.value.editedMessageId
|
val editedMessageId = uiState.value.editedMessageId
|
||||||
if (text.isNotEmpty()) {
|
if (text.isNotEmpty()) {
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val auth = identityRepository.authToken.value
|
val auth = identityRepository.authToken.value
|
||||||
if (editedMessageId == null) {
|
if (editedMessageId == null) {
|
||||||
messageRepository.create(
|
messageRepository.create(
|
||||||
|
@ -68,7 +68,7 @@ class CommunityDetailViewModel(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch {
|
||||||
themeRepository.postLayout.onEach { layout ->
|
themeRepository.postLayout.onEach { layout ->
|
||||||
mvi.updateState { it.copy(postLayout = layout) }
|
mvi.updateState { it.copy(postLayout = layout) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
@ -274,6 +274,9 @@ class CommunityDetailViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
mvi.emitEffect(CommunityDetailMviModel.Effect.BackToTop)
|
mvi.emitEffect(CommunityDetailMviModel.Effect.BackToTop)
|
||||||
|
@ -5,8 +5,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.architecture.MviModel
|
|||||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommunityRepository
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommunityRepository
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.IO
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -23,7 +21,7 @@ class CommunityInfoViewModel(
|
|||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.updateState { it.copy(community = community) }
|
mvi.updateState { it.copy(community = community) }
|
||||||
|
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch {
|
||||||
settingsRepository.currentSettings.onEach {
|
settingsRepository.currentSettings.onEach {
|
||||||
mvi.updateState { it.copy(autoLoadImages = it.autoLoadImages) }
|
mvi.updateState { it.copy(autoLoadImages = it.autoLoadImages) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.launchIn
|
|||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ class ModalDrawerViewModel(
|
|||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.scope?.launch(Dispatchers.Main) {
|
mvi.scope?.launch {
|
||||||
apiConfigurationRepository.instance.onEach { instance ->
|
apiConfigurationRepository.instance.onEach { instance ->
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
it.copy(instance = instance)
|
it.copy(instance = instance)
|
||||||
@ -62,7 +63,7 @@ class ModalDrawerViewModel(
|
|||||||
|
|
||||||
observeChangesInFavoriteCommunities()
|
observeChangesInFavoriteCommunities()
|
||||||
|
|
||||||
mvi.scope?.launch {
|
withContext(Dispatchers.IO) {
|
||||||
delay(250)
|
delay(250)
|
||||||
refreshUser()
|
refreshUser()
|
||||||
refresh()
|
refresh()
|
||||||
|
@ -35,7 +35,7 @@ class InstanceInfoViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch {
|
||||||
settingsRepository.currentSettings.onEach { settings ->
|
settingsRepository.currentSettings.onEach { settings ->
|
||||||
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
|
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
@ -104,7 +104,7 @@ class ManageSubscriptionsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleUnsubscription(community: CommunityModel) {
|
private fun handleUnsubscription(community: CommunityModel) {
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
val auth = identityRepository.authToken.value
|
val auth = identityRepository.authToken.value
|
||||||
communityRepository.unsubscribe(
|
communityRepository.unsubscribe(
|
||||||
auth = auth, id = community.id
|
auth = auth, id = community.id
|
||||||
|
@ -36,7 +36,6 @@ class InboxMentionsViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
|
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch {
|
||||||
coordinator.events.onEach {
|
coordinator.events.onEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -62,7 +62,7 @@ class ModlogViewModel(
|
|||||||
initial = initial,
|
initial = initial,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
loadNextPage()
|
loadNextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ class MultiCommunityViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
|
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch {
|
||||||
themeRepository.postLayout.onEach { layout ->
|
themeRepository.postLayout.onEach { layout ->
|
||||||
mvi.updateState { it.copy(postLayout = layout) }
|
mvi.updateState { it.copy(postLayout = layout) }
|
||||||
@ -209,6 +208,9 @@ class MultiCommunityViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class ProfileLoggedViewModel(
|
|||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
mvi.updateState { it.copy(instance = apiConfigurationRepository.instance.value) }
|
mvi.updateState { it.copy(instance = apiConfigurationRepository.instance.value) }
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch {
|
||||||
themeRepository.postLayout.onEach { layout ->
|
themeRepository.postLayout.onEach { layout ->
|
||||||
mvi.updateState { it.copy(postLayout = layout) }
|
mvi.updateState { it.copy(postLayout = layout) }
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
@ -59,7 +59,7 @@ class PostDetailViewModel(
|
|||||||
?: apiConfigurationRepository.instance.value,
|
?: apiConfigurationRepository.instance.value,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mvi.scope?.launch(Dispatchers.Main) {
|
mvi.scope?.launch {
|
||||||
notificationCenter.subscribe(NotificationCenterEvent.PostUpdated::class).onEach { evt ->
|
notificationCenter.subscribe(NotificationCenterEvent.PostUpdated::class).onEach { evt ->
|
||||||
handlePostUpdate(evt.model)
|
handlePostUpdate(evt.model)
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
@ -131,9 +131,7 @@ class PostDetailViewModel(
|
|||||||
val auth = identityRepository.authToken.value.orEmpty()
|
val auth = identityRepository.authToken.value.orEmpty()
|
||||||
val user = siteRepository.getCurrentUser(auth)
|
val user = siteRepository.getCurrentUser(auth)
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
it.copy(
|
it.copy(currentUserId = user?.id ?: 0)
|
||||||
currentUserId = user?.id ?: 0,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +209,7 @@ class PostDetailViewModel(
|
|||||||
} else {
|
} else {
|
||||||
// comment to highlight found
|
// comment to highlight found
|
||||||
commentWasHighlighted = true
|
commentWasHighlighted = true
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.Main) {
|
||||||
mvi.emitEffect(PostDetailMviModel.Effect.ScrollToComment(indexOfHighlight))
|
mvi.emitEffect(PostDetailMviModel.Effect.ScrollToComment(indexOfHighlight))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,6 +392,9 @@ class PostDetailViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
mvi.scope?.launch(Dispatchers.IO) {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
mvi.emitEffect(PostDetailMviModel.Effect.BackToTop)
|
mvi.emitEffect(PostDetailMviModel.Effect.BackToTop)
|
||||||
@ -641,7 +642,7 @@ class PostDetailViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleExpanded(comment: CommentModel) {
|
private fun toggleExpanded(comment: CommentModel) {
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.Main) {
|
||||||
val commentId = comment.id
|
val commentId = comment.id
|
||||||
val newExpanded = !comment.expanded
|
val newExpanded = !comment.expanded
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
|
@ -58,8 +58,7 @@ class PostListViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
|
mvi.scope?.launch {
|
||||||
mvi.scope?.launch(Dispatchers.Main) {
|
|
||||||
apiConfigurationRepository.instance.onEach { instance ->
|
apiConfigurationRepository.instance.onEach { instance ->
|
||||||
mvi.updateState {
|
mvi.updateState {
|
||||||
it.copy(instance = instance)
|
it.copy(instance = instance)
|
||||||
@ -321,16 +320,22 @@ class PostListViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
mvi.emitEffect(PostListMviModel.Effect.BackToTop)
|
mvi.emitEffect(PostListMviModel.Effect.BackToTop)
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyListingType(value: ListingType) {
|
private fun applyListingType(value: ListingType) {
|
||||||
|
if (uiState.value.listingType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(listingType = value) }
|
mvi.updateState { it.copy(listingType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
mvi.emitEffect(PostListMviModel.Effect.BackToTop)
|
mvi.emitEffect(PostListMviModel.Effect.BackToTop)
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ class InboxRepliesViewModel(
|
|||||||
|
|
||||||
override fun onStarted() {
|
override fun onStarted() {
|
||||||
mvi.onStarted()
|
mvi.onStarted()
|
||||||
|
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch {
|
||||||
coordinator.events.onEach {
|
coordinator.events.onEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -105,7 +105,7 @@ class ReportListViewModel(
|
|||||||
initial = initial,
|
initial = initial,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.IO) {
|
||||||
loadNextPage()
|
loadNextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,9 @@ class SavedItemsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import kotlinx.coroutines.IO
|
|||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class UserDetailViewModel(
|
class UserDetailViewModel(
|
||||||
private val mvi: DefaultMviModel<UserDetailMviModel.Intent, UserDetailMviModel.UiState, UserDetailMviModel.Effect>,
|
private val mvi: DefaultMviModel<UserDetailMviModel.Intent, UserDetailMviModel.UiState, UserDetailMviModel.Effect>,
|
||||||
@ -108,7 +109,9 @@ class UserDetailViewModel(
|
|||||||
|
|
||||||
if (uiState.value.posts.isEmpty()) {
|
if (uiState.value.posts.isEmpty()) {
|
||||||
updateAvailableSortTypes()
|
updateAvailableSortTypes()
|
||||||
refresh(initial = true)
|
withContext(Dispatchers.IO) {
|
||||||
|
refresh(initial = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,8 +195,11 @@ class UserDetailViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun applySortType(value: SortType) {
|
private fun applySortType(value: SortType) {
|
||||||
|
if (uiState.value.sortType == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mvi.updateState { it.copy(sortType = value) }
|
mvi.updateState { it.copy(sortType = value) }
|
||||||
mvi.scope?.launch {
|
mvi.scope?.launch(Dispatchers.Main) {
|
||||||
mvi.emitEffect(UserDetailMviModel.Effect.BackToTop)
|
mvi.emitEffect(UserDetailMviModel.Effect.BackToTop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user