mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-08 16:28:45 +01:00
refactor: remove redundant architecture structure (#587)
This commit is contained in:
parent
843b4098ca
commit
0acbe4aa63
@ -1,8 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.architecture
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
@ -25,9 +22,6 @@ abstract class DefaultMviModel<Intent, State, Effect>(
|
||||
override val uiState = MutableStateFlow(initialState)
|
||||
override val effects = MutableSharedFlow<Effect>()
|
||||
|
||||
protected var scope: CoroutineScope? = null
|
||||
private set
|
||||
|
||||
/**
|
||||
* Emit an effect (event).
|
||||
*
|
||||
@ -49,13 +43,4 @@ abstract class DefaultMviModel<Intent, State, Effect>(
|
||||
override fun reduce(intent: Intent) {
|
||||
// Noop
|
||||
}
|
||||
|
||||
override fun onStarted() {
|
||||
scope = CoroutineScope(SupervisorJob())
|
||||
}
|
||||
|
||||
override fun onDisposed() {
|
||||
scope?.cancel()
|
||||
scope = null
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,4 @@ interface MviModel<Intent, State, Effect> {
|
||||
* @param intent View intent to process
|
||||
*/
|
||||
fun reduce(intent: Intent)
|
||||
|
||||
/**
|
||||
* To be called whenever the view component becomes visible to start listening events,
|
||||
* initialize the coroutine scope, etc.
|
||||
*/
|
||||
fun onStarted()
|
||||
|
||||
/**
|
||||
* To be called wheneer the view component is not visible any more to cancel ongoing operations.
|
||||
*/
|
||||
fun onDisposed()
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.architecture
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
|
||||
@Composable
|
||||
fun MviModel<*, *, *>.bindToLifecycle(key: Any = Unit) {
|
||||
DisposableEffect(key) {
|
||||
onStarted()
|
||||
onDispose(::onDisposed)
|
||||
}
|
||||
}
|
@ -31,7 +31,6 @@ import cafe.adriel.voyager.navigator.tab.Tab
|
||||
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.InboxTypeSheet
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -58,7 +57,6 @@ object InboxScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<InboxMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val drawerCoordinator = remember { getDrawerCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.inbox.main
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -29,9 +30,8 @@ class InboxViewModel(
|
||||
|
||||
private var firstLoad = true
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
identityRepository.isLogged.onEach { logged ->
|
||||
updateState { it.copy(isLogged = logged) }
|
||||
}.launchIn(this)
|
||||
@ -86,7 +86,7 @@ class InboxViewModel(
|
||||
}
|
||||
|
||||
private fun markAllRead() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
userRepository.readAll(auth)
|
||||
emitEffect(InboxMviModel.Effect.Refresh)
|
||||
|
@ -7,7 +7,7 @@ import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Logout
|
||||
import androidx.compose.material.icons.automirrored.filled.Logout
|
||||
import androidx.compose.material.icons.filled.ManageAccounts
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@ -38,7 +38,6 @@ import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Dimensions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getDrawerCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
|
||||
@ -65,7 +64,6 @@ internal object ProfileMainScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ProfileMainMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(topAppBarState)
|
||||
@ -133,7 +131,7 @@ internal object ProfileMainScreen : Tab {
|
||||
model.reduce(ProfileMainMviModel.Intent.Logout)
|
||||
},
|
||||
),
|
||||
imageVector = Icons.Filled.Logout,
|
||||
imageVector = Icons.AutoMirrored.Filled.Logout,
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primary),
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.profile.main
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.usecase.LogoutUseCase
|
||||
@ -15,9 +16,8 @@ class ProfileMainViewModel(
|
||||
initialState = ProfileMainMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
identityRepository.isLogged.onEach { logged ->
|
||||
updateState { it.copy(logged = logged) }
|
||||
}.launchIn(this)
|
||||
@ -31,7 +31,7 @@ class ProfileMainViewModel(
|
||||
}
|
||||
|
||||
private fun handleLogout() {
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
logout()
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeActionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -102,7 +101,6 @@ class ExploreScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ExploreMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.search.main
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
|
||||
@ -39,7 +40,7 @@ class ExploreViewModel(
|
||||
private val settingsRepository: SettingsRepository,
|
||||
private val notificationCenter: NotificationCenter,
|
||||
private val hapticFeedback: HapticFeedback,
|
||||
private val contentResetCoordinator: ContentResetCoordinator,
|
||||
contentResetCoordinator: ContentResetCoordinator,
|
||||
private val getSortTypesUseCase: GetSortTypesUseCase,
|
||||
) : ExploreMviModel,
|
||||
DefaultMviModel<ExploreMviModel.Intent, ExploreMviModel.UiState, ExploreMviModel.Effect>(
|
||||
@ -50,14 +51,13 @@ class ExploreViewModel(
|
||||
private var debounceJob: Job? = null
|
||||
private var firstLoad = true
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState {
|
||||
it.copy(
|
||||
instance = apiConfigRepository.instance.value,
|
||||
)
|
||||
}
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
identityRepository.isLogged.onEach { isLogged ->
|
||||
updateState {
|
||||
it.copy(isLogged = isLogged ?: false)
|
||||
@ -122,7 +122,7 @@ class ExploreViewModel(
|
||||
sortType = sortType,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
emitEffect(ExploreMviModel.Effect.BackToTop)
|
||||
}
|
||||
@ -137,13 +137,13 @@ class ExploreViewModel(
|
||||
override fun reduce(intent: ExploreMviModel.Intent) {
|
||||
when (intent) {
|
||||
ExploreMviModel.Intent.LoadNextPage -> {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
ExploreMviModel.Intent.Refresh -> {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
@ -236,7 +236,7 @@ class ExploreViewModel(
|
||||
private fun setSearch(value: String) {
|
||||
debounceJob?.cancel()
|
||||
updateState { it.copy(searchText = value) }
|
||||
debounceJob = scope?.launch(Dispatchers.IO) {
|
||||
debounceJob = screenModelScope.launch(Dispatchers.IO) {
|
||||
delay(1_000)
|
||||
emitEffect(ExploreMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
@ -245,7 +245,7 @@ class ExploreViewModel(
|
||||
|
||||
private fun changeListingType(value: ListingType) {
|
||||
updateState { it.copy(listingType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(ExploreMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -253,7 +253,7 @@ class ExploreViewModel(
|
||||
|
||||
private fun changeSortType(value: SortType) {
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(ExploreMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -261,7 +261,7 @@ class ExploreViewModel(
|
||||
|
||||
private fun changeResultType(value: SearchResultType) {
|
||||
updateState { it.copy(resultType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(ExploreMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -395,7 +395,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -439,7 +439,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -483,7 +483,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -527,7 +527,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -568,7 +568,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -612,7 +612,7 @@ class ExploreViewModel(
|
||||
},
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
|
@ -38,7 +38,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.UiBarTheme
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
@ -61,7 +60,6 @@ class AdvancedSettingsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<AdvancedSettingsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.settings.advanced
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.UiBarTheme
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
@ -33,9 +34,8 @@ class AdvancedSettingsViewModel(
|
||||
initialState = AdvancedSettingsMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.navItemTitles.onEach { value ->
|
||||
updateState { it.copy(navBarTitlesVisible = value) }
|
||||
}.launchIn(this)
|
||||
@ -117,7 +117,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeNavBarTitlesVisible(value: Boolean) {
|
||||
themeRepository.changeNavItemTitles(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
navigationTitlesVisible = value
|
||||
)
|
||||
@ -127,7 +127,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeEnableDoubleTapAction(value: Boolean) {
|
||||
updateState { it.copy(enableDoubleTapAction = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
enableDoubleTapAction = value
|
||||
)
|
||||
@ -137,7 +137,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeAutoLoadImages(value: Boolean) {
|
||||
updateState { it.copy(autoLoadImages = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
autoLoadImages = value
|
||||
)
|
||||
@ -147,7 +147,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeAutoExpandComments(value: Boolean) {
|
||||
updateState { it.copy(autoExpandComments = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
autoExpandComments = value
|
||||
)
|
||||
@ -157,7 +157,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeHideNavigationBarWhileScrolling(value: Boolean) {
|
||||
updateState { it.copy(hideNavigationBarWhileScrolling = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
hideNavigationBarWhileScrolling = value
|
||||
)
|
||||
@ -167,7 +167,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeMarkAsReadWhileScrolling(value: Boolean) {
|
||||
updateState { it.copy(markAsReadWhileScrolling = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
markAsReadWhileScrolling = value
|
||||
)
|
||||
@ -177,7 +177,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeZombieModeInterval(value: Duration) {
|
||||
updateState { it.copy(zombieModeInterval = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
zombieModeInterval = value
|
||||
)
|
||||
@ -187,7 +187,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeZombieModeScrollAmount(value: Float) {
|
||||
updateState { it.copy(zombieModeScrollAmount = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
zombieModeScrollAmount = value
|
||||
)
|
||||
@ -197,7 +197,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeDefaultInboxUnreadOnly(value: Boolean) {
|
||||
updateState { it.copy(defaultInboxUnreadOnly = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
defaultInboxType = value.toInboxDefaultType(),
|
||||
)
|
||||
@ -208,7 +208,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeSearchPostTitleOnly(value: Boolean) {
|
||||
updateState { it.copy(searchPostTitleOnly = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
searchPostTitleOnly = value
|
||||
)
|
||||
@ -218,7 +218,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeEdgeToEdge(value: Boolean) {
|
||||
updateState { it.copy(edgeToEdge = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
edgeToEdge = value
|
||||
)
|
||||
@ -228,7 +228,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeInfiniteScrollDisabled(value: Boolean) {
|
||||
updateState { it.copy(infiniteScrollDisabled = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
infiniteScrollEnabled = !value
|
||||
)
|
||||
@ -242,7 +242,7 @@ class AdvancedSettingsViewModel(
|
||||
else -> false
|
||||
}
|
||||
updateState { it.copy(opaqueSystemBars = opaque) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
opaqueSystemBars = opaque
|
||||
)
|
||||
@ -252,7 +252,7 @@ class AdvancedSettingsViewModel(
|
||||
|
||||
private fun changeImageSourcePath(value: Boolean) {
|
||||
updateState { it.copy(imageSourcePath = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
imageSourcePath = value
|
||||
)
|
||||
|
@ -39,7 +39,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toReadableN
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getColorSchemeProvider
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -65,7 +64,6 @@ class SettingsColorAndFontScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<SettingsColorAndFontMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -2,6 +2,7 @@ package com.github.diegoberaldin.raccoonforlemmy.feature.settings.colors
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.CommentBarTheme
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.UiFontFamily
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toInt
|
||||
@ -32,9 +33,8 @@ class SettingsColorAndFontViewModel(
|
||||
initialState = SettingsColorAndFontMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.uiTheme.onEach { value ->
|
||||
updateState { it.copy(uiTheme = value) }
|
||||
}.launchIn(this)
|
||||
@ -112,7 +112,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeFontFamily(value: UiFontFamily) {
|
||||
themeRepository.changeUiFontFamily(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
uiFontFamily = value.toInt()
|
||||
)
|
||||
@ -122,7 +122,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeUiFontScale(value: Float) {
|
||||
themeRepository.changeUiFontScale(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
uiFontScale = value
|
||||
)
|
||||
@ -134,7 +134,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeDynamicColors(value: Boolean) {
|
||||
themeRepository.changeDynamicColors(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
dynamicColors = value
|
||||
)
|
||||
@ -144,7 +144,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeCustomSeedColor(value: Color?) {
|
||||
themeRepository.changeCustomSeedColor(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
customSeedColor = value?.toArgb()
|
||||
)
|
||||
@ -154,7 +154,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeUpVoteColor(value: Color?) {
|
||||
themeRepository.changeUpVoteColor(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
upVoteColor = value?.toArgb()
|
||||
)
|
||||
@ -164,7 +164,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeDownVoteColor(value: Color?) {
|
||||
themeRepository.changeDownVoteColor(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
downVoteColor = value?.toArgb()
|
||||
)
|
||||
@ -174,7 +174,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeReplyColor(value: Color?) {
|
||||
themeRepository.changeReplyColor(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
replyColor = value?.toArgb()
|
||||
)
|
||||
@ -184,7 +184,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeSaveColor(value: Color?) {
|
||||
themeRepository.changeSaveColor(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
saveColor = value?.toArgb()
|
||||
)
|
||||
@ -194,7 +194,7 @@ class SettingsColorAndFontViewModel(
|
||||
|
||||
private fun changeCommentBarTheme(value: CommentBarTheme) {
|
||||
themeRepository.changeCommentBarTheme(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
commentBarTheme = value.toInt()
|
||||
)
|
||||
|
@ -41,7 +41,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
@ -81,7 +80,6 @@ class SettingsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<SettingsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(topAppBarState)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.settings.main
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.UiTheme
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toInt
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
@ -40,9 +41,8 @@ class SettingsViewModel(
|
||||
initialState = SettingsMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.uiTheme.onEach { value ->
|
||||
updateState { it.copy(uiTheme = value) }
|
||||
}.launchIn(this)
|
||||
@ -119,7 +119,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeTheme(value: UiTheme?) {
|
||||
themeRepository.changeUiTheme(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
theme = value?.toInt()
|
||||
)
|
||||
@ -129,7 +129,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeLanguage(value: String) {
|
||||
l10nManager.changeLanguage(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
locale = value
|
||||
)
|
||||
@ -139,7 +139,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeDefaultListingType(value: ListingType) {
|
||||
updateState { it.copy(defaultListingType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
defaultListingType = value.toInt()
|
||||
)
|
||||
@ -151,7 +151,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeDefaultPostSortType(value: SortType) {
|
||||
updateState { it.copy(defaultPostSortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
defaultPostSortType = value.toInt()
|
||||
)
|
||||
@ -163,7 +163,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeDefaultCommentSortType(value: SortType) {
|
||||
updateState { it.copy(defaultCommentSortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
defaultCommentSortType = value.toInt()
|
||||
)
|
||||
@ -173,7 +173,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeIncludeNsfw(value: Boolean) {
|
||||
updateState { it.copy(includeNsfw = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
includeNsfw = value
|
||||
)
|
||||
@ -183,7 +183,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeBlurNsfw(value: Boolean) {
|
||||
updateState { it.copy(blurNsfw = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
blurNsfw = value
|
||||
)
|
||||
@ -193,7 +193,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeOpenUrlsInExternalBrowser(value: Boolean) {
|
||||
updateState { it.copy(openUrlsInExternalBrowser = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
openUrlsInExternalBrowser = value
|
||||
)
|
||||
@ -203,7 +203,7 @@ class SettingsViewModel(
|
||||
|
||||
private fun changeEnableSwipeActions(value: Boolean) {
|
||||
updateState { it.copy(enableSwipeActions = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
enableSwipeActions = value
|
||||
)
|
||||
@ -223,7 +223,7 @@ class SettingsViewModel(
|
||||
}
|
||||
|
||||
private fun handleLogout() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.getSettings(null)
|
||||
updateState {
|
||||
it.copy(
|
||||
|
@ -35,7 +35,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import cafe.adriel.voyager.navigator.tab.CurrentTab
|
||||
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.DrawerEvent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.TabNavigationSection
|
||||
@ -64,7 +63,6 @@ internal object MainScreen : Screen {
|
||||
var bottomBarHeightPx by remember { mutableStateOf(0f) }
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val model = getScreenModel<MainScreenMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val uiFontScale by themeRepository.uiFontScale.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.inbox.InboxCoordinator
|
||||
@ -17,9 +18,8 @@ class MainViewModel(
|
||||
initialState = MainScreenMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
init {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
identityRepository.startup()
|
||||
|
||||
inboxCoordinator.totalUnread.onEach { unreadCount ->
|
||||
|
@ -35,7 +35,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.handleUrl
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -54,10 +53,7 @@ class AboutDialog : Screen {
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
|
||||
val viewModel = getScreenModel<AboutDialogMviModel>()
|
||||
viewModel.bindToLifecycle(key)
|
||||
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val settingsRepository = remember { getSettingsRepository() }
|
||||
|
@ -10,8 +10,7 @@ class AboutDialogViewModel(
|
||||
initialState = AboutDialogMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState {
|
||||
it.copy(
|
||||
version = AppInfo.versionCode,
|
||||
|
@ -58,7 +58,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepos
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.IconSize
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
@ -86,7 +85,6 @@ class AccountSettingsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<AccountSettingsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.accountsettings
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -30,9 +31,8 @@ class AccountSettingsViewModel(
|
||||
|
||||
private var accountSettings: AccountSettingsModel? = null
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
updateState { it.copy(defaultSortType = evt.value) }
|
||||
@ -183,7 +183,7 @@ class AccountSettingsViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -203,7 +203,7 @@ class AccountSettingsViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -238,7 +238,7 @@ class AccountSettingsViewModel(
|
||||
showReadPosts = currentState.showReadPosts,
|
||||
) ?: return
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
siteRepository.updateAccountSettings(
|
||||
|
@ -44,7 +44,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsIntValueRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
@ -77,7 +76,6 @@ class BanUserScreen(
|
||||
commentId,
|
||||
)
|
||||
}
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.ban
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -23,8 +24,7 @@ class BanUserViewModel(
|
||||
initialState = BanUserMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState {
|
||||
it.copy(targetBanValue = newValue)
|
||||
}
|
||||
@ -61,7 +61,7 @@ class BanUserViewModel(
|
||||
val days = currentState.days.toLong().takeIf { newValue }
|
||||
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newUser = communityRepository.banUser(
|
||||
|
@ -55,7 +55,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepos
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.IconSize
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomImage
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
@ -85,7 +84,6 @@ class InboxChatScreen(
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<InboxChatMviModel> { parametersOf(otherUserId) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val galleryHelper = remember { getGalleryHelper() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.chat
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -33,9 +34,8 @@ class InboxChatViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
|
||||
@ -77,7 +77,7 @@ class InboxChatViewModel(
|
||||
override fun reduce(intent: InboxChatMviModel.Intent) {
|
||||
when (intent) {
|
||||
InboxChatMviModel.Intent.LoadNextPage -> {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ class InboxChatViewModel(
|
||||
|
||||
private fun markAsRead(read: Boolean, messageId: Int) {
|
||||
val auth = identityRepository.authToken.value
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val newMessage = messageRepository.markAsRead(
|
||||
read = read,
|
||||
messageId = messageId,
|
||||
@ -194,7 +194,7 @@ class InboxChatViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -221,7 +221,7 @@ class InboxChatViewModel(
|
||||
val editedMessageId = uiState.value.editedMessageId
|
||||
val isEditing = editedMessageId != null
|
||||
if (text.isNotEmpty()) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
val newMessage = if (isEditing) {
|
||||
messageRepository.edit(
|
||||
@ -265,7 +265,7 @@ class InboxChatViewModel(
|
||||
}
|
||||
|
||||
private fun deleteMessage(message: PrivateMessageModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
runCatching {
|
||||
messageRepository.delete(
|
||||
|
@ -79,7 +79,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Dimensions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomDropDown
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
@ -142,7 +141,6 @@ class CommunityDetailScreen(
|
||||
tag = communityId.toString(),
|
||||
parameters = { parametersOf(communityId, otherInstance) },
|
||||
)
|
||||
model.bindToLifecycle(key + communityId.toString())
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val lazyListState = rememberLazyListState()
|
||||
val scope = rememberCoroutineScope()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.communitydetail
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -63,9 +64,8 @@ class CommunityDetailViewModel(
|
||||
private var pageCursor: String? = null
|
||||
private var hideReadPosts = false
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
if (uiState.value.community.id == 0) {
|
||||
val community = itemCache.getCommunity(communityId) ?: CommunityModel()
|
||||
updateState {
|
||||
@ -175,11 +175,11 @@ class CommunityDetailViewModel(
|
||||
|
||||
override fun reduce(intent: CommunityDetailMviModel.Intent) {
|
||||
when (intent) {
|
||||
CommunityDetailMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
CommunityDetailMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
CommunityDetailMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
CommunityDetailMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ class CommunityDetailViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(CommunityDetailMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -393,7 +393,7 @@ class CommunityDetailViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -417,7 +417,7 @@ class CommunityDetailViewModel(
|
||||
return
|
||||
}
|
||||
val newPost = post.copy(read = true)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.setRead(
|
||||
@ -440,7 +440,7 @@ class CommunityDetailViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -466,7 +466,7 @@ class CommunityDetailViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -487,7 +487,7 @@ class CommunityDetailViewModel(
|
||||
|
||||
private fun subscribe() {
|
||||
hapticFeedback.vibrate()
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
communityRepository.subscribe(
|
||||
auth = identityRepository.authToken.value,
|
||||
id = communityId,
|
||||
@ -499,7 +499,7 @@ class CommunityDetailViewModel(
|
||||
|
||||
private fun unsubscribe() {
|
||||
hapticFeedback.vibrate()
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val community = communityRepository.unsubscribe(
|
||||
auth = identityRepository.authToken.value,
|
||||
id = communityId,
|
||||
@ -530,7 +530,7 @@ class CommunityDetailViewModel(
|
||||
|
||||
private fun blockCommunity() {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value
|
||||
communityRepository.block(communityId, true, auth).getOrThrow()
|
||||
@ -545,7 +545,7 @@ class CommunityDetailViewModel(
|
||||
|
||||
private fun blockInstance() {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val community = uiState.value.community
|
||||
val instanceId = community.instanceId
|
||||
@ -581,7 +581,7 @@ class CommunityDetailViewModel(
|
||||
}
|
||||
|
||||
private fun feature(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.featureInCommunity(
|
||||
postId = post.id,
|
||||
@ -595,7 +595,7 @@ class CommunityDetailViewModel(
|
||||
}
|
||||
|
||||
private fun lock(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.lock(
|
||||
postId = post.id,
|
||||
@ -609,7 +609,7 @@ class CommunityDetailViewModel(
|
||||
}
|
||||
|
||||
private fun toggleModeratorStatus(userId: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val isModerator = uiState.value.moderators.containsId(userId)
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newModerators = communityRepository.addModerator(
|
||||
@ -625,7 +625,7 @@ class CommunityDetailViewModel(
|
||||
}
|
||||
|
||||
private fun toggleFavorite() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val accountId = accountRepository.getActive()?.id ?: 0L
|
||||
val newValue = !uiState.value.community.favorite
|
||||
if (newValue) {
|
||||
|
@ -33,7 +33,6 @@ import androidx.compose.ui.Modifier
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ContentFontClass
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomizedContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -64,7 +63,6 @@ class CommunityInfoScreen(
|
||||
tag = communityId.toString(),
|
||||
parameters = { parametersOf(communityId) },
|
||||
)
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.communityinfo
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
@ -19,9 +20,8 @@ class CommunityInfoViewModel(
|
||||
initialState = CommunityInfoMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
if (uiState.value.community.id == 0) {
|
||||
val community = itemCache.getCommunity(communityId) ?: CommunityModel()
|
||||
updateState { it.copy(community = community) }
|
||||
|
@ -36,7 +36,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toFontScale
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ContentFontClass
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
|
||||
@ -57,7 +56,6 @@ class ConfigureContentViewScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ConfigureContentViewMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.configurecontentview
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.UiFontFamily
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.VoteFormat
|
||||
@ -28,9 +29,8 @@ class ConfigureContentViewViewModel(
|
||||
initialState = ConfigureContentViewMviModel.State()
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { value ->
|
||||
updateState { it.copy(postLayout = value) }
|
||||
}.launchIn(this)
|
||||
@ -95,7 +95,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changePostLayout(value: PostLayout) {
|
||||
themeRepository.changePostLayout(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
postLayout = value.toInt()
|
||||
)
|
||||
@ -105,7 +105,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changeVoteFormat(value: VoteFormat) {
|
||||
updateState { it.copy(voteFormat = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.let {
|
||||
if (value == VoteFormat.Hidden) {
|
||||
it.copy(showScores = false)
|
||||
@ -122,7 +122,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changeFullHeightImages(value: Boolean) {
|
||||
updateState { it.copy(fullHeightImages = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
fullHeightImages = value
|
||||
)
|
||||
@ -132,7 +132,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changePreferUserNicknames(value: Boolean) {
|
||||
updateState { it.copy(preferUserNicknames = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
preferUserNicknames = value
|
||||
)
|
||||
@ -142,7 +142,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changePostBodyMaxLines(value: Int?) {
|
||||
updateState { it.copy(postBodyMaxLines = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
postBodyMaxLines = value
|
||||
)
|
||||
@ -159,7 +159,7 @@ class ConfigureContentViewViewModel(
|
||||
ContentFontClass.AncillaryText -> it.copy(ancillary = value)
|
||||
}
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
contentFontScale = contentFontScale
|
||||
)
|
||||
@ -169,7 +169,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changeContentFontFamily(value: UiFontFamily) {
|
||||
themeRepository.changeContentFontFamily(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
contentFontFamily = value.toInt()
|
||||
)
|
||||
@ -179,7 +179,7 @@ class ConfigureContentViewViewModel(
|
||||
|
||||
private fun changeCommentBarThickness(value: Int) {
|
||||
themeRepository.changeCommentBarThickness(value)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value.copy(
|
||||
commentBarThickness = value
|
||||
)
|
||||
|
@ -15,13 +15,13 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.automirrored.filled.Message
|
||||
import androidx.compose.material.icons.filled.Dashboard
|
||||
import androidx.compose.material.icons.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.KeyboardDoubleArrowLeft
|
||||
import androidx.compose.material.icons.filled.KeyboardDoubleArrowRight
|
||||
import androidx.compose.material.icons.filled.Mail
|
||||
import androidx.compose.material.icons.filled.Message
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
@ -41,7 +41,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
|
||||
@ -61,7 +60,6 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ConfigureSwipeActionsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
@ -156,7 +154,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowLeft
|
||||
else -> Icons.Filled.KeyboardArrowLeft
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowLeft
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
@ -212,7 +210,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowRight
|
||||
else -> Icons.Filled.KeyboardArrowRight
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowRight
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
@ -257,7 +255,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
item {
|
||||
SettingsHeader(
|
||||
title = LocalXmlStrings.current.exploreResultTypeComments,
|
||||
icon = Icons.Filled.Message,
|
||||
icon = Icons.AutoMirrored.Filled.Message,
|
||||
rightButton = @Composable {
|
||||
TextButton(
|
||||
contentPadding = PaddingValues(
|
||||
@ -295,7 +293,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowLeft
|
||||
else -> Icons.Filled.KeyboardArrowLeft
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowLeft
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
@ -351,7 +349,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowRight
|
||||
else -> Icons.Filled.KeyboardArrowRight
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowRight
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
@ -434,7 +432,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowLeft
|
||||
else -> Icons.Filled.KeyboardArrowLeft
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowLeft
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
@ -490,7 +488,7 @@ class ConfigureSwipeActionsScreen : Screen {
|
||||
ConfigureActionItem(
|
||||
icon = when (idx) {
|
||||
1 -> Icons.Default.KeyboardDoubleArrowRight
|
||||
else -> Icons.Filled.KeyboardArrowRight
|
||||
else -> Icons.AutoMirrored.Filled.KeyboardArrowRight
|
||||
},
|
||||
action = action,
|
||||
options = buildList {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.configureswipeactions
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -23,9 +24,8 @@ class ConfigureSwipeActionsViewModel(
|
||||
initialState = ConfigureSwipeActionsMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ActionsOnSwipeSelected::class)
|
||||
.onEach { evt ->
|
||||
when (evt.target) {
|
||||
@ -88,7 +88,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun addActionPosts(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -132,7 +132,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun removeActionPosts(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -176,7 +176,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun addActionComments(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -220,7 +220,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun removeActionComments(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -264,7 +264,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun addActionInbox(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -308,7 +308,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
}
|
||||
|
||||
private fun removeActionInbox(action: ActionOnSwipe, direction: ActionOnSwipeDirection) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val settings = settingsRepository.currentSettings.value
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
val newActions = when (direction) {
|
||||
@ -357,7 +357,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
actionsOnSwipeToStartPosts = ActionOnSwipe.DEFAULT_SWIPE_TO_START_POSTS,
|
||||
actionsOnSwipeToEndPosts = ActionOnSwipe.DEFAULT_SWIPE_TO_START_POSTS,
|
||||
)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
settingsRepository.updateSettings(newSettings, accountId)
|
||||
settingsRepository.changeCurrentSettings(newSettings)
|
||||
@ -372,7 +372,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
actionsOnSwipeToStartComments = ActionOnSwipe.DEFAULT_SWIPE_TO_START_COMMENTS,
|
||||
actionsOnSwipeToEndComments = ActionOnSwipe.DEFAULT_SWIPE_TO_END_COMMENTS,
|
||||
)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
settingsRepository.updateSettings(newSettings, accountId)
|
||||
settingsRepository.changeCurrentSettings(newSettings)
|
||||
@ -387,7 +387,7 @@ class ConfigureSwipeActionsViewModel(
|
||||
actionsOnSwipeToStartInbox = ActionOnSwipe.DEFAULT_SWIPE_TO_START_INBOX,
|
||||
actionsOnSwipeToEndInbox = ActionOnSwipe.DEFAULT_SWIPE_TO_END_INBOX,
|
||||
)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
settingsRepository.updateSettings(newSettings, accountId)
|
||||
settingsRepository.changeCurrentSettings(newSettings)
|
||||
|
@ -1,7 +1,14 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.createcomment
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
@ -10,8 +17,26 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.Send
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
@ -29,10 +54,15 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.*
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommentCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CreatePostSection
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.PostCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.PostCardBody
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.TextFormattingBar
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.SelectLanguageDialog
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
|
||||
@ -68,7 +98,6 @@ class CreateCommentScreen(
|
||||
draftId,
|
||||
)
|
||||
}
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.createcomment
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -42,9 +43,8 @@ class CreateCommentViewModel(
|
||||
initialState = CreateCommentMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val originalPostFromCache = postId?.let { itemCache.getPost(it) }
|
||||
val originalCommentFromCache = parentId?.let { itemCache.getComment(it) }
|
||||
@ -154,7 +154,7 @@ class CreateCommentViewModel(
|
||||
}
|
||||
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
if (postId != null) {
|
||||
@ -201,7 +201,7 @@ class CreateCommentViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -233,7 +233,7 @@ class CreateCommentViewModel(
|
||||
val body = currentState.textValue.text
|
||||
val languageId = currentState.currentLanguageId
|
||||
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
updateState { it.copy(loading = true) }
|
||||
val draft = DraftModel(
|
||||
|
@ -1,7 +1,15 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.createpost
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
@ -12,8 +20,28 @@ import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Groups
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
@ -35,7 +63,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CreatePostSection
|
||||
@ -74,7 +101,6 @@ class CreatePostScreen(
|
||||
val model = getScreenModel<CreatePostMviModel> {
|
||||
parametersOf(editedPostId, crossPostId, draftId)
|
||||
}
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.createpost
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -43,9 +44,8 @@ class CreatePostViewModel(
|
||||
initialState = CreatePostMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
val editedPost = editedPostId?.let {
|
||||
itemCache.getPost(it)
|
||||
}
|
||||
@ -150,7 +150,7 @@ class CreatePostViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -167,7 +167,7 @@ class CreatePostViewModel(
|
||||
if (bytes.isEmpty()) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val url = postRepository.uploadImage(auth, bytes)
|
||||
@ -241,7 +241,7 @@ class CreatePostViewModel(
|
||||
}
|
||||
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
when {
|
||||
@ -294,7 +294,7 @@ class CreatePostViewModel(
|
||||
val nsfw = currentState.nsfw
|
||||
val languageId = currentState.currentLanguageId
|
||||
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
val accountId = accountRepository.getActive()?.id ?: return@launch
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
|
@ -44,7 +44,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
|
||||
@ -68,7 +67,6 @@ class CreateReportScreen(
|
||||
commentId,
|
||||
)
|
||||
}
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.createreport
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommentRepository
|
||||
@ -38,7 +39,7 @@ class CreateReportViewModel(
|
||||
val text = uiState.value.text
|
||||
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
if (postId != null) {
|
||||
|
@ -41,7 +41,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
@ -63,7 +62,6 @@ class DraftsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<DraftsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.drafts
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -26,9 +27,8 @@ class DraftsViewModel(
|
||||
initialState = DraftsMviModel.State(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -62,7 +62,7 @@ class DraftsViewModel(
|
||||
initial = initial,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val currentState = uiState.value
|
||||
updateState { it.copy(loading = true) }
|
||||
val refreshing = currentState.refreshing
|
||||
@ -126,7 +126,7 @@ class DraftsViewModel(
|
||||
}
|
||||
|
||||
private fun deleteDraft(model: DraftModel) {
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
model.id?.also { id ->
|
||||
draftRepository.delete(id)
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import cafe.adriel.voyager.navigator.tab.Tab
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.DrawerEvent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getDrawerCoordinator
|
||||
@ -74,7 +73,6 @@ object ModalDrawerContent : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ModalDrawerMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val coordinator = remember { getDrawerCoordinator() }
|
||||
val themeRepository = remember { getThemeRepository() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.drawer
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -48,16 +49,15 @@ class ModalDrawerViewModel(
|
||||
|
||||
private val searchEventChannel = Channel<Unit>()
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
apiConfigurationRepository.instance.onEach { instance ->
|
||||
updateState {
|
||||
it.copy(instance = instance)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
identityRepository.isLogged.debounce(250).onEach { _ ->
|
||||
refreshUser()
|
||||
refresh()
|
||||
@ -78,6 +78,7 @@ class ModalDrawerViewModel(
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
searchEventChannel.receiveAsFlow().debounce(1000).onEach {
|
||||
refresh()
|
||||
}.launchIn(this)
|
||||
@ -121,13 +122,13 @@ class ModalDrawerViewModel(
|
||||
|
||||
override fun reduce(intent: ModalDrawerMviModel.Intent) {
|
||||
when (intent) {
|
||||
ModalDrawerMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
ModalDrawerMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
is ModalDrawerMviModel.Intent.SetSearch -> {
|
||||
updateState { it.copy(searchText = intent.value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
searchEventChannel.send(Unit)
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ContentFontClass
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomizedContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItem
|
||||
@ -72,7 +71,6 @@ class InstanceInfoScreen(
|
||||
tag = instanceName,
|
||||
parameters = { parametersOf(url) }
|
||||
)
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.instanceinfo
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -33,9 +34,8 @@ class InstanceInfoViewModel(
|
||||
|
||||
private var currentPage = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -88,7 +88,7 @@ class InstanceInfoViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
val refreshing = currentState.refreshing
|
||||
@ -135,7 +135,7 @@ class InstanceInfoViewModel(
|
||||
|
||||
private fun changeSortType(value: SortType) {
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(InstanceInfoMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.HelpOutline
|
||||
import androidx.compose.material.icons.filled.Clear
|
||||
import androidx.compose.material.icons.filled.HelpOutline
|
||||
import androidx.compose.material.icons.filled.Visibility
|
||||
import androidx.compose.material.icons.filled.VisibilityOff
|
||||
import androidx.compose.material3.Button
|
||||
@ -53,7 +53,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.IconSize
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.handleUrl
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -77,8 +76,6 @@ class LoginBottomSheet : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<LoginMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
@ -148,7 +145,7 @@ class LoginBottomSheet : Screen {
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.HelpOutline,
|
||||
imageVector = Icons.AutoMirrored.Filled.HelpOutline,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.login
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.AccountRepository
|
||||
@ -17,7 +18,7 @@ import kotlinx.coroutines.withContext
|
||||
|
||||
class LoginViewModel(
|
||||
private val login: LoginUseCase,
|
||||
private val apiConfigurationRepository: ApiConfigurationRepository,
|
||||
apiConfigurationRepository: ApiConfigurationRepository,
|
||||
private val identityRepository: IdentityRepository,
|
||||
private val accountRepository: AccountRepository,
|
||||
private val siteRepository: SiteRepository,
|
||||
@ -28,8 +29,7 @@ class LoginViewModel(
|
||||
initialState = LoginMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
val instance = apiConfigurationRepository.instance.value
|
||||
updateState {
|
||||
it.copy(instanceName = instance)
|
||||
@ -114,7 +114,7 @@ class LoginViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
|
||||
val res = communityRepository.getAll(
|
||||
|
@ -31,7 +31,6 @@ import androidx.compose.ui.Modifier
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId
|
||||
@ -48,7 +47,6 @@ class ManageAccountsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ManageAccountsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.manageaccounts
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.data.AccountModel
|
||||
@ -27,10 +28,9 @@ class ManageAccountsViewModel(
|
||||
initialState = ManageAccountsMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
if (uiState.value.accounts.isEmpty()) {
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -57,13 +57,13 @@ class ManageAccountsViewModel(
|
||||
is ManageAccountsMviModel.Intent.DeleteAccount -> {
|
||||
uiState.value.accounts.getOrNull(intent.index)?.also { account ->
|
||||
if (account.active) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
logout()
|
||||
deleteAccount(account)
|
||||
close()
|
||||
}
|
||||
} else {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
deleteAccount(account)
|
||||
updateState {
|
||||
it.copy(accounts = it.accounts.filter { a -> a.id != account.id })
|
||||
@ -79,7 +79,7 @@ class ManageAccountsViewModel(
|
||||
if (account.active) {
|
||||
return
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
switchAccount(account)
|
||||
contentResetCoordinator.resetHome = true
|
||||
contentResetCoordinator.resetExplore = true
|
||||
|
@ -36,7 +36,6 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItemPlaceholder
|
||||
@ -56,7 +55,6 @@ class ManageBanScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ManageBanMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.manageban
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
@ -24,9 +25,8 @@ class ManageBanViewModel(
|
||||
initialState = ManageBanMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -51,7 +51,7 @@ class ManageBanViewModel(
|
||||
}
|
||||
|
||||
ManageBanMviModel.Intent.Refresh -> {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ class ManageBanViewModel(
|
||||
}
|
||||
|
||||
private fun unbanUser(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
runCatching {
|
||||
userRepository.block(
|
||||
@ -92,7 +92,7 @@ class ManageBanViewModel(
|
||||
}
|
||||
|
||||
private fun unbanCommunity(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
runCatching {
|
||||
communityRepository.block(
|
||||
@ -108,7 +108,7 @@ class ManageBanViewModel(
|
||||
}
|
||||
|
||||
private fun unbanInstance(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
runCatching {
|
||||
siteRepository.block(
|
||||
|
@ -44,7 +44,6 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -69,7 +68,6 @@ class ManageSubscriptionsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ManageSubscriptionsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigatorCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.managesubscriptions
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -33,9 +34,8 @@ class ManageSubscriptionsViewModel(
|
||||
initialState = ManageSubscriptionsMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -85,7 +85,7 @@ class ManageSubscriptionsViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(refreshing = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
val accountId = accountRepository.getActive()?.id ?: 0L
|
||||
val favoriteCommunityIds =
|
||||
@ -109,7 +109,7 @@ class ManageSubscriptionsViewModel(
|
||||
}
|
||||
|
||||
private fun handleUnsubscription(community: CommunityModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
communityRepository.unsubscribe(
|
||||
auth = auth, id = community.id
|
||||
@ -121,7 +121,7 @@ class ManageSubscriptionsViewModel(
|
||||
}
|
||||
|
||||
private fun deleteMultiCommunity(community: MultiCommunityModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
multiCommunityRepository.delete(community)
|
||||
updateState {
|
||||
val newCommunities = it.multiCommunities.filter { c -> c.id != community.id }
|
||||
@ -148,7 +148,7 @@ class ManageSubscriptionsViewModel(
|
||||
|
||||
private fun toggleFavorite(community: CommunityModel) {
|
||||
val communityId = community.id
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val accountId = accountRepository.getActive()?.id ?: 0L
|
||||
val newValue = !community.favorite
|
||||
if (newValue) {
|
||||
|
@ -40,7 +40,6 @@ import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeActionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -71,7 +70,6 @@ class InboxMentionsScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<InboxMentionsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.mentions
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -34,9 +35,8 @@ class InboxMentionsViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
coordinator.events.onEach {
|
||||
when (it) {
|
||||
InboxCoordinator.Event.Refresh -> refresh()
|
||||
@ -75,11 +75,11 @@ class InboxMentionsViewModel(
|
||||
|
||||
override fun reduce(intent: InboxMentionsMviModel.Intent) {
|
||||
when (intent) {
|
||||
InboxMentionsMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
InboxMentionsMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
InboxMentionsMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
InboxMentionsMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ class InboxMentionsViewModel(
|
||||
|
||||
private fun changeUnreadOnly(value: Boolean) {
|
||||
updateState { it.copy(unreadOnly = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh(initial = true)
|
||||
emitEffect(InboxMentionsMviModel.Effect.BackToTop)
|
||||
}
|
||||
@ -181,7 +181,7 @@ class InboxMentionsViewModel(
|
||||
|
||||
private fun markAsRead(read: Boolean, mention: PersonMentionModel) {
|
||||
val auth = identityRepository.authToken.value
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
userRepository.setMentionRead(
|
||||
read = read,
|
||||
mentionId = mention.id,
|
||||
@ -215,7 +215,7 @@ class InboxMentionsViewModel(
|
||||
score = newComment.score,
|
||||
)
|
||||
handleItemUpdate(newMention)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -237,7 +237,7 @@ class InboxMentionsViewModel(
|
||||
score = newComment.score,
|
||||
)
|
||||
handleItemUpdate(newMention)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -252,7 +252,7 @@ class InboxMentionsViewModel(
|
||||
}
|
||||
|
||||
private fun updateUnreadItems() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val unreadCount = coordinator.updateUnreadCount()
|
||||
emitEffect(InboxMentionsMviModel.Effect.UpdateUnreadItems(unreadCount))
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import cafe.adriel.voyager.navigator.tab.Tab
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.TabNavigationSection
|
||||
@ -56,7 +55,6 @@ class InboxMessagesScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<InboxMessagesMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.messages
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -29,9 +30,8 @@ class InboxMessagesViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
coordinator.events.onEach {
|
||||
when (it) {
|
||||
InboxCoordinator.Event.Refresh -> refresh()
|
||||
@ -71,11 +71,11 @@ class InboxMessagesViewModel(
|
||||
|
||||
override fun reduce(intent: InboxMessagesMviModel.Intent) {
|
||||
when (intent) {
|
||||
InboxMessagesMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
InboxMessagesMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
InboxMessagesMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
InboxMessagesMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ class InboxMessagesViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(unreadOnly = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh(initial = true)
|
||||
emitEffect(InboxMessagesMviModel.Effect.BackToTop)
|
||||
}
|
||||
@ -152,7 +152,7 @@ class InboxMessagesViewModel(
|
||||
}
|
||||
|
||||
private fun updateUnreadItems() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val unreadCount = coordinator.updateUnreadCount()
|
||||
emitEffect(InboxMessagesMviModel.Effect.UpdateUnreadItems(unreadCount))
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeActionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -78,7 +77,6 @@ class ModdedCommentsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ModdedCommentsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.moddedcontents.comments
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
@ -27,9 +28,8 @@ class ModdedCommentsViewModel(
|
||||
|
||||
private var currentPage = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -54,7 +54,7 @@ class ModdedCommentsViewModel(
|
||||
|
||||
override fun reduce(intent: ModdedCommentsMviModel.Intent) {
|
||||
when (intent) {
|
||||
ModdedCommentsMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
ModdedCommentsMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ class ModdedCommentsViewModel(
|
||||
initial = initial,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,7 @@ class ModdedCommentsViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -199,7 +199,7 @@ class ModdedCommentsViewModel(
|
||||
val newValue = comment.myVote >= 0
|
||||
val newComment = commentRepository.asDownVoted(comment, newValue)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -221,7 +221,7 @@ class ModdedCommentsViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
@ -237,7 +237,7 @@ class ModdedCommentsViewModel(
|
||||
}
|
||||
|
||||
private fun distinguish(comment: CommentModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newComment = commentRepository.distinguish(
|
||||
commentId = comment.id,
|
||||
|
@ -50,7 +50,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeActionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -81,7 +80,6 @@ class ModdedPostsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ModdedPostsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.moddedcontents.posts
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -35,9 +36,8 @@ class ModdedPostsViewModel(
|
||||
private var currentPage = 1
|
||||
private var pageCursor: String? = null
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -73,7 +73,7 @@ class ModdedPostsViewModel(
|
||||
}
|
||||
|
||||
ModdedPostsMviModel.Intent.HapticIndication -> hapticFeedback.vibrate()
|
||||
ModdedPostsMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
ModdedPostsMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ class ModdedPostsViewModel(
|
||||
initial = initial,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ class ModdedPostsViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -220,7 +220,7 @@ class ModdedPostsViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -242,7 +242,7 @@ class ModdedPostsViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -261,7 +261,7 @@ class ModdedPostsViewModel(
|
||||
}
|
||||
|
||||
private fun feature(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.featureInCommunity(
|
||||
postId = post.id,
|
||||
@ -275,7 +275,7 @@ class ModdedPostsViewModel(
|
||||
}
|
||||
|
||||
private fun lock(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.lock(
|
||||
postId = post.id,
|
||||
|
@ -38,7 +38,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
|
||||
@ -68,7 +67,6 @@ class ModlogScreen(
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ModlogMviModel> { parametersOf(communityId) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.modlog
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
@ -24,9 +25,8 @@ class ModlogViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -48,7 +48,7 @@ class ModlogViewModel(
|
||||
override fun reduce(intent: ModlogMviModel.Intent) {
|
||||
when (intent) {
|
||||
ModlogMviModel.Intent.Refresh -> refresh()
|
||||
ModlogMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
ModlogMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ class ModlogViewModel(
|
||||
initial = initial,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ class ModlogViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val refreshing = currentState.refreshing
|
||||
|
@ -64,7 +64,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Dimensions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
@ -106,7 +105,6 @@ class MultiCommunityScreen(
|
||||
val model = getScreenModel<MultiCommunityMviModel>(parameters = {
|
||||
parametersOf(communityId)
|
||||
})
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(topAppBarState)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.multicommunity.detail
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -47,9 +48,8 @@ class MultiCommunityViewModel(
|
||||
|
||||
private var hideReadPosts = false
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
if ((uiState.value.community.id ?: 0) == 0L) {
|
||||
val community =
|
||||
multiCommunityRepository.getById(communityId.toLong()) ?: MultiCommunityModel()
|
||||
@ -166,7 +166,7 @@ class MultiCommunityViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
val sort = currentState.sortType ?: SortType.Active
|
||||
@ -230,7 +230,7 @@ class MultiCommunityViewModel(
|
||||
voted = newVote,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -251,7 +251,7 @@ class MultiCommunityViewModel(
|
||||
return
|
||||
}
|
||||
val newPost = post.copy(read = true)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.setRead(
|
||||
@ -274,7 +274,7 @@ class MultiCommunityViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -297,7 +297,7 @@ class MultiCommunityViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
|
@ -56,7 +56,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomImage
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -76,7 +75,6 @@ class MultiCommunityEditorScreen(
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<MultiCommunityEditorMviModel> { parametersOf(communityId) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.multicommunity.editor
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -35,9 +36,8 @@ class MultiCommunityEditorViewModel(
|
||||
private var communities: List<Pair<CommunityModel, Boolean>> = emptyList()
|
||||
private var debounceJob: Job? = null
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -63,7 +63,7 @@ class MultiCommunityEditorViewModel(
|
||||
}
|
||||
|
||||
private fun populate() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val editedCommunity = communityId?.toLong()?.let {
|
||||
multiCommunityRepository.getById(it)
|
||||
}
|
||||
@ -88,7 +88,7 @@ class MultiCommunityEditorViewModel(
|
||||
private fun setSearch(value: String) {
|
||||
debounceJob?.cancel()
|
||||
updateState { it.copy(searchText = value) }
|
||||
debounceJob = scope?.launch(Dispatchers.IO) {
|
||||
debounceJob = screenModelScope.launch(Dispatchers.IO) {
|
||||
delay(1_000)
|
||||
updateState {
|
||||
val filtered = filterCommunities()
|
||||
@ -152,7 +152,7 @@ class MultiCommunityEditorViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val icon = currentState.icon
|
||||
val communityIds = currentState.communities.filter { it.second }.map { it.first.id }
|
||||
val editedCommunity = communityId?.toLong()?.let {
|
||||
|
@ -39,7 +39,6 @@ import cafe.adriel.voyager.navigator.tab.Tab
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -91,7 +90,6 @@ object ProfileLoggedScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ProfileLoggedMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.myaccount
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.ProfileLoggedSection
|
||||
@ -51,15 +52,14 @@ class ProfileLoggedViewModel(
|
||||
|
||||
private var currentPage = 1
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState { it.copy(instance = apiConfigurationRepository.instance.value) }
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
identityRepository.isLogged.drop(1).debounce(250).onEach { logged ->
|
||||
if (logged == true) {
|
||||
updateState {
|
||||
@ -122,11 +122,11 @@ class ProfileLoggedViewModel(
|
||||
is ProfileLoggedMviModel.Intent.ChangeSection -> changeSection(intent.section)
|
||||
is ProfileLoggedMviModel.Intent.DeleteComment -> deleteComment(intent.id)
|
||||
is ProfileLoggedMviModel.Intent.DeletePost -> deletePost(intent.id)
|
||||
ProfileLoggedMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
ProfileLoggedMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
ProfileLoggedMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
ProfileLoggedMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ class ProfileLoggedViewModel(
|
||||
voted = newVote,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -375,7 +375,7 @@ class ProfileLoggedViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -397,7 +397,7 @@ class ProfileLoggedViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -419,7 +419,7 @@ class ProfileLoggedViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -438,7 +438,7 @@ class ProfileLoggedViewModel(
|
||||
val newValue = comment.myVote >= 0
|
||||
val newComment = commentRepository.asDownVoted(comment, newValue)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -460,7 +460,7 @@ class ProfileLoggedViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
@ -508,7 +508,7 @@ class ProfileLoggedViewModel(
|
||||
}
|
||||
|
||||
private fun deletePost(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.delete(id = id, auth = auth)
|
||||
handlePostDelete(id)
|
||||
@ -516,7 +516,7 @@ class ProfileLoggedViewModel(
|
||||
}
|
||||
|
||||
private fun deleteComment(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.delete(id, auth)
|
||||
refresh()
|
||||
|
@ -74,7 +74,6 @@ import cafe.adriel.voyager.core.screen.ScreenKey
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
@ -142,7 +141,6 @@ class PostDetailScreen(
|
||||
isMod,
|
||||
)
|
||||
})
|
||||
model.bindToLifecycle(key + postId.toString())
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val isOnOtherInstance = remember { otherInstance.isNotEmpty() }
|
||||
val otherInstanceName = remember { otherInstance }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.postdetail
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -55,15 +56,14 @@ class PostDetailViewModel(
|
||||
private var highlightCommentPath: String? = null
|
||||
private var commentWasHighlighted = false
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState {
|
||||
it.copy(
|
||||
instance = otherInstance.takeIf { n -> n.isNotEmpty() }
|
||||
?: apiConfigurationRepository.instance.value,
|
||||
)
|
||||
}
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
if (uiState.value.post.id == 0) {
|
||||
val post = itemCache.getPost(postId) ?: PostModel()
|
||||
updateState {
|
||||
@ -224,7 +224,7 @@ class PostDetailViewModel(
|
||||
} else {
|
||||
// comment to highlight found
|
||||
commentWasHighlighted = true
|
||||
scope?.launch(Dispatchers.Main) {
|
||||
screenModelScope.launch(Dispatchers.Main) {
|
||||
emitEffect(PostDetailMviModel.Effect.ScrollToComment(indexOfHighlight))
|
||||
}
|
||||
}
|
||||
@ -232,13 +232,13 @@ class PostDetailViewModel(
|
||||
|
||||
override fun reduce(intent: PostDetailMviModel.Intent) {
|
||||
when (intent) {
|
||||
PostDetailMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
PostDetailMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
if (!uiState.value.initial) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
PostDetailMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
PostDetailMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun refreshPost() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
val updatedPost = postRepository.get(
|
||||
id = postId,
|
||||
@ -416,7 +416,7 @@ class PostDetailViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(PostDetailMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -429,7 +429,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun loadMoreComments(parentId: Int, loadUntilHighlight: Boolean = false) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val currentState = uiState.value
|
||||
val auth = identityRepository.authToken.value
|
||||
val sort = currentState.sortType
|
||||
@ -482,7 +482,7 @@ class PostDetailViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
updateState { it.copy(post = newPost) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -511,7 +511,7 @@ class PostDetailViewModel(
|
||||
updateState {
|
||||
it.copy(post = newPost)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -536,7 +536,7 @@ class PostDetailViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
updateState { it.copy(post = newPost) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -575,7 +575,7 @@ class PostDetailViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -597,7 +597,7 @@ class PostDetailViewModel(
|
||||
val newValue = comment.myVote >= 0
|
||||
val newComment = commentRepository.asDownVoted(comment, newValue)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -622,7 +622,7 @@ class PostDetailViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
@ -641,7 +641,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun deleteComment(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.delete(id, auth)
|
||||
handleCommentDelete(id)
|
||||
@ -654,7 +654,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun deletePost() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.delete(id = postId, auth = auth)
|
||||
notificationCenter.send(
|
||||
@ -665,7 +665,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun toggleExpanded(comment: CommentModel) {
|
||||
scope?.launch(Dispatchers.Main) {
|
||||
screenModelScope.launch(Dispatchers.Main) {
|
||||
val commentId = comment.id
|
||||
val newExpanded = !comment.expanded
|
||||
updateState {
|
||||
@ -697,7 +697,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun feature(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.featureInCommunity(
|
||||
postId = post.id,
|
||||
@ -711,7 +711,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun lock(post: PostModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newPost = postRepository.lock(
|
||||
postId = post.id,
|
||||
@ -725,7 +725,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun distinguish(comment: CommentModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newComment = commentRepository.distinguish(
|
||||
commentId = comment.id,
|
||||
@ -739,7 +739,7 @@ class PostDetailViewModel(
|
||||
}
|
||||
|
||||
private fun toggleModeratorStatus(userId: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val isModerator = uiState.value.moderators.containsId(userId)
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val post = uiState.value.post
|
||||
|
@ -62,7 +62,6 @@ import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
@ -106,7 +105,6 @@ class PostListScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<PostListMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(topAppBarState)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.postlist
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
|
||||
@ -44,7 +45,7 @@ class PostListViewModel(
|
||||
private val hapticFeedback: HapticFeedback,
|
||||
private val zombieModeHelper: ZombieModeHelper,
|
||||
private val imagePreloadManager: ImagePreloadManager,
|
||||
private val contentResetCoordinator: ContentResetCoordinator,
|
||||
contentResetCoordinator: ContentResetCoordinator,
|
||||
private val getSortTypesUseCase: GetSortTypesUseCase,
|
||||
) : PostListMviModel,
|
||||
DefaultMviModel<PostListMviModel.Intent, PostListMviModel.UiState, PostListMviModel.Effect>(
|
||||
@ -56,9 +57,8 @@ class PostListViewModel(
|
||||
private var firstLoad = true
|
||||
private var hideReadPosts = false
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
apiConfigurationRepository.instance.onEach { instance ->
|
||||
updateState {
|
||||
it.copy(instance = instance)
|
||||
@ -157,7 +157,7 @@ class PostListViewModel(
|
||||
sortType = settings.defaultPostSortType.toSortType(),
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
emitEffect(PostListMviModel.Effect.BackToTop)
|
||||
}
|
||||
@ -171,11 +171,11 @@ class PostListViewModel(
|
||||
|
||||
override fun reduce(intent: PostListMviModel.Intent) {
|
||||
when (intent) {
|
||||
PostListMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
PostListMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
PostListMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
PostListMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ class PostListViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(PostListMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -346,7 +346,7 @@ class PostListViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(listingType = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
emitEffect(PostListMviModel.Effect.BackToTop)
|
||||
refresh()
|
||||
}
|
||||
@ -359,7 +359,7 @@ class PostListViewModel(
|
||||
voted = newVote,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -380,7 +380,7 @@ class PostListViewModel(
|
||||
return
|
||||
}
|
||||
val newPost = post.copy(read = true)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.setRead(
|
||||
@ -403,7 +403,7 @@ class PostListViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -426,7 +426,7 @@ class PostListViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -468,7 +468,7 @@ class PostListViewModel(
|
||||
}
|
||||
|
||||
private fun handlePostDelete(id: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.delete(id = id, auth = auth)
|
||||
handlePostDelete(id)
|
||||
@ -496,21 +496,21 @@ class PostListViewModel(
|
||||
}
|
||||
|
||||
private fun blockUser(userId: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
userRepository.block(userId, true, auth)
|
||||
}
|
||||
}
|
||||
|
||||
private fun blockCommunity(communityId: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
communityRepository.block(communityId, true, auth)
|
||||
}
|
||||
}
|
||||
|
||||
private fun blockInstance(instanceId: Int) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value
|
||||
siteRepository.block(instanceId, true, auth)
|
||||
|
@ -44,7 +44,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
|
||||
@ -68,7 +67,6 @@ class RemoveScreen(
|
||||
commentId,
|
||||
)
|
||||
}
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val genericError = LocalXmlStrings.current.messageGenericError
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.remove
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
|
||||
@ -41,7 +42,7 @@ class RemoveViewModel(
|
||||
val text = uiState.value.text
|
||||
|
||||
updateState { it.copy(loading = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
if (postId != null) {
|
||||
|
@ -41,7 +41,6 @@ import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeActionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -71,7 +70,6 @@ class InboxRepliesScreen : Tab {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<InboxRepliesMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.replies
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -37,9 +38,8 @@ class InboxRepliesViewModel(
|
||||
private var currentPage: Int = 1
|
||||
private var currentUserId: Int? = null
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
coordinator.events.onEach {
|
||||
when (it) {
|
||||
InboxCoordinator.Event.Refresh -> refresh()
|
||||
@ -78,11 +78,11 @@ class InboxRepliesViewModel(
|
||||
|
||||
override fun reduce(intent: InboxRepliesMviModel.Intent) {
|
||||
when (intent) {
|
||||
InboxRepliesMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
InboxRepliesMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
InboxRepliesMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
InboxRepliesMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ class InboxRepliesViewModel(
|
||||
|
||||
private fun changeUnreadOnly(value: Boolean) {
|
||||
updateState { it.copy(unreadOnly = value) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh(initial = true)
|
||||
emitEffect(InboxRepliesMviModel.Effect.BackToTop)
|
||||
}
|
||||
@ -188,7 +188,7 @@ class InboxRepliesViewModel(
|
||||
|
||||
private fun markAsRead(read: Boolean, reply: PersonMentionModel) {
|
||||
val auth = identityRepository.authToken.value
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
userRepository.setReplyRead(
|
||||
read = read,
|
||||
replyId = reply.id,
|
||||
@ -218,7 +218,7 @@ class InboxRepliesViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleItemUpdate(newMention)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -239,7 +239,7 @@ class InboxRepliesViewModel(
|
||||
downVoted = newValue
|
||||
)
|
||||
handleItemUpdate(newMention)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
|
@ -35,7 +35,6 @@ import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@ -48,7 +47,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeAction
|
||||
@ -79,12 +77,10 @@ class ReportListScreen(
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<ReportListMviModel> { parametersOf(communityId) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
var rawContent by remember { mutableStateOf<Any?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val settingsRepository = remember { getSettingsRepository() }
|
||||
val settings by settingsRepository.currentSettings.collectAsState()
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.reportlist
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -35,9 +36,8 @@ class ReportListViewModel(
|
||||
|
||||
private var currentPage = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -66,7 +66,7 @@ class ReportListViewModel(
|
||||
is ReportListMviModel.Intent.ChangeSection -> changeSection(intent.value)
|
||||
is ReportListMviModel.Intent.ChangeUnresolvedOnly -> changeUnresolvedOnly(intent.value)
|
||||
ReportListMviModel.Intent.Refresh -> refresh()
|
||||
ReportListMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
ReportListMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ class ReportListViewModel(
|
||||
initial = initial,
|
||||
)
|
||||
}
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,7 @@ class ReportListViewModel(
|
||||
}
|
||||
|
||||
private fun resolve(report: PostReportModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newReport = postRepository.resolveReport(
|
||||
@ -217,7 +217,7 @@ class ReportListViewModel(
|
||||
}
|
||||
|
||||
private fun resolve(report: CommentReportModel) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val newReport = commentRepository.resolveReport(
|
||||
|
@ -48,7 +48,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
|
||||
@ -83,7 +82,6 @@ class SavedItemsScreen : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<SavedItemsMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigatorCoordinator = remember { getNavigationCoordinator() }
|
||||
val topAppBarState = rememberTopAppBarState()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.saveditems
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
|
||||
@ -43,10 +44,9 @@ class SavedItemsViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState { it.copy(instance = apiConfigurationRepository.instance.value) }
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
themeRepository.postLayout.onEach { layout ->
|
||||
updateState { it.copy(postLayout = layout) }
|
||||
}.launchIn(this)
|
||||
@ -166,7 +166,7 @@ class SavedItemsViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
val user = siteRepository.getCurrentUser(auth.orEmpty()) ?: return@launch
|
||||
@ -278,7 +278,7 @@ class SavedItemsViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -303,7 +303,7 @@ class SavedItemsViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -328,7 +328,7 @@ class SavedItemsViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -353,7 +353,7 @@ class SavedItemsViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -372,7 +372,7 @@ class SavedItemsViewModel(
|
||||
val newValue = comment.myVote >= 0
|
||||
val newComment = commentRepository.asDownVoted(comment, newValue)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -394,7 +394,7 @@ class SavedItemsViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
|
@ -36,7 +36,6 @@ import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.CommunityItemPlaceholder
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -50,7 +49,6 @@ class SelectCommunityDialog : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<SelectCommunityMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.selectcommunity
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
@ -25,9 +26,8 @@ class SelectCommunityViewModel(
|
||||
private var communities: List<CommunityModel> = emptyList()
|
||||
private var debounceJob: Job? = null
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -51,7 +51,7 @@ class SelectCommunityViewModel(
|
||||
private fun setSearch(value: String) {
|
||||
debounceJob?.cancel()
|
||||
updateState { it.copy(searchText = value) }
|
||||
debounceJob = scope?.launch(Dispatchers.IO) {
|
||||
debounceJob = screenModelScope.launch(Dispatchers.IO) {
|
||||
delay(1_000)
|
||||
updateState {
|
||||
val filtered = filterCommunities()
|
||||
@ -61,7 +61,7 @@ class SelectCommunityViewModel(
|
||||
}
|
||||
|
||||
private fun populate() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
communities = communityRepository.getSubscribed(auth).sortedBy { it.name }
|
||||
updateState {
|
||||
|
@ -33,7 +33,6 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId
|
||||
@ -56,7 +55,6 @@ class SelectInstanceBottomSheet : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<SelectInstanceMviModel>(key)
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
var changeInstanceDialogOpen by remember {
|
||||
mutableStateOf(false)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.selectinstance
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.InstanceSelectionRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.ValidationError
|
||||
@ -26,21 +27,20 @@ class SelectInstanceViewModel(
|
||||
|
||||
private val saveOperationChannel = Channel<List<String>>()
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
apiConfigurationRepository.instance.onEach { instance ->
|
||||
updateState { it.copy(currentInstance = instance) }
|
||||
}.launchIn(this)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
saveOperationChannel.receiveAsFlow().debounce(500).onEach { newInstances ->
|
||||
instanceRepository.updateAll(newInstances)
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
if (uiState.value.instances.isEmpty()) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val instances = instanceRepository.getAll()
|
||||
updateState { it.copy(instances = instances) }
|
||||
}
|
||||
@ -64,7 +64,7 @@ class SelectInstanceViewModel(
|
||||
}
|
||||
|
||||
private fun deleteInstance(value: String) {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
instanceRepository.remove(value)
|
||||
val instances = instanceRepository.getAll()
|
||||
updateState { it.copy(instances = instances) }
|
||||
@ -83,7 +83,7 @@ class SelectInstanceViewModel(
|
||||
return
|
||||
}
|
||||
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(changeInstanceLoading = true) }
|
||||
val res = communityRepository.getAll(
|
||||
instance = instanceName,
|
||||
@ -120,7 +120,7 @@ class SelectInstanceViewModel(
|
||||
val element = removeAt(from)
|
||||
add(to, element)
|
||||
}
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
saveOperationChannel.send(newInstances)
|
||||
updateState {
|
||||
it.copy(instances = newInstances)
|
||||
@ -130,7 +130,7 @@ class SelectInstanceViewModel(
|
||||
|
||||
private fun confirmSelection(value: String) {
|
||||
apiConfigurationRepository.changeInstance(value)
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
emitEffect(SelectInstanceMviModel.Effect.Confirm(value))
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Dimensions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomDropDown
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenu
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.FloatingActionButtonMenuItem
|
||||
@ -133,7 +132,6 @@ class UserDetailScreen(
|
||||
override fun Content() {
|
||||
val model = getScreenModel<UserDetailMviModel>(tag = userId.toString(),
|
||||
parameters = { parametersOf(userId, otherInstance) })
|
||||
model.bindToLifecycle(key + userId.toString())
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val lazyListState = rememberLazyListState()
|
||||
val scope = rememberCoroutineScope()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.userdetail
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.UserDetailSection
|
||||
@ -56,15 +57,14 @@ class UserDetailViewModel(
|
||||
|
||||
private var currentPage = 1
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
init {
|
||||
updateState {
|
||||
it.copy(
|
||||
instance = otherInstance.takeIf { n -> n.isNotEmpty() }
|
||||
?: apiConfigurationRepository.instance.value,
|
||||
)
|
||||
}
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
if (uiState.value.user.id == 0) {
|
||||
val user = itemCache.getUser(userId) ?: UserModel()
|
||||
updateState {
|
||||
@ -86,7 +86,7 @@ class UserDetailViewModel(
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
scope?.launch {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState {
|
||||
it.copy(
|
||||
@ -155,11 +155,11 @@ class UserDetailViewModel(
|
||||
}
|
||||
|
||||
UserDetailMviModel.Intent.HapticIndication -> hapticFeedback.vibrate()
|
||||
UserDetailMviModel.Intent.LoadNextPage -> scope?.launch(Dispatchers.IO) {
|
||||
UserDetailMviModel.Intent.LoadNextPage -> screenModelScope.launch(Dispatchers.IO) {
|
||||
loadNextPage()
|
||||
}
|
||||
|
||||
UserDetailMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||
UserDetailMviModel.Intent.Refresh -> screenModelScope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ class UserDetailViewModel(
|
||||
return
|
||||
}
|
||||
updateState { it.copy(sortType = value) }
|
||||
scope?.launch(Dispatchers.Main) {
|
||||
screenModelScope.launch(Dispatchers.Main) {
|
||||
emitEffect(UserDetailMviModel.Effect.BackToTop)
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ class UserDetailViewModel(
|
||||
}
|
||||
|
||||
private fun updateAvailableSortTypes() {
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
val sortTypes = if (uiState.value.section == UserDetailSection.Posts) {
|
||||
getSortTypesUseCase.getTypesForPosts(otherInstance = otherInstance)
|
||||
} else {
|
||||
@ -379,7 +379,7 @@ class UserDetailViewModel(
|
||||
voted = newVote,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.upVote(
|
||||
@ -401,7 +401,7 @@ class UserDetailViewModel(
|
||||
downVoted = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.downVote(
|
||||
@ -423,7 +423,7 @@ class UserDetailViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handlePostUpdate(newPost)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
postRepository.save(
|
||||
@ -445,7 +445,7 @@ class UserDetailViewModel(
|
||||
voted = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.upVote(
|
||||
@ -464,7 +464,7 @@ class UserDetailViewModel(
|
||||
val newValue = comment.myVote >= 0
|
||||
val newComment = commentRepository.asDownVoted(comment, newValue)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.downVote(
|
||||
@ -486,7 +486,7 @@ class UserDetailViewModel(
|
||||
saved = newValue,
|
||||
)
|
||||
handleCommentUpdate(newComment)
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
commentRepository.save(
|
||||
@ -531,7 +531,7 @@ class UserDetailViewModel(
|
||||
|
||||
private fun blockUser() {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val auth = identityRepository.authToken.value
|
||||
userRepository.block(userId, true, auth).getOrThrow()
|
||||
@ -546,7 +546,7 @@ class UserDetailViewModel(
|
||||
|
||||
private fun blockInstance() {
|
||||
updateState { it.copy(asyncInProgress = true) }
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val user = uiState.value.user
|
||||
val instanceId = user.instanceId
|
||||
|
@ -35,7 +35,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepos
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ContentFontClass
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomizedContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener
|
||||
@ -62,7 +61,6 @@ class UserInfoScreen(
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val model = getScreenModel<UserInfoMviModel> { parametersOf(userId) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.userinfo
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
@ -19,9 +20,8 @@ class UserInfoViewModel(
|
||||
initialState = UserInfoMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
val user = itemCache.getUser(userId) ?: UserModel()
|
||||
updateState {
|
||||
it.copy(user = user)
|
||||
|
@ -30,7 +30,6 @@ import androidx.compose.ui.graphics.Color
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.koin.getScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ProgressHud
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ZoomableImage
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -51,7 +50,6 @@ class ZoomableImageScreen(
|
||||
override fun Content() {
|
||||
|
||||
val model = getScreenModel<ZoomableImageMviModel>()
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val successMessage = LocalXmlStrings.current.messageOperationSuccessful
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.unit.zoomableimage
|
||||
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.epochMillis
|
||||
@ -21,9 +22,8 @@ class ZoomableImageViewModel(
|
||||
initialState = ZoomableImageMviModel.UiState(),
|
||||
) {
|
||||
|
||||
override fun onStarted() {
|
||||
super.onStarted()
|
||||
scope?.launch {
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
settingsRepository.currentSettings.onEach { settings ->
|
||||
updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
|
||||
}.launchIn(this)
|
||||
@ -47,7 +47,7 @@ class ZoomableImageViewModel(
|
||||
|
||||
private fun downloadAndSave(url: String, folder: String) {
|
||||
val imageSourcePath = settingsRepository.currentSettings.value.imageSourcePath
|
||||
scope?.launch(Dispatchers.IO) {
|
||||
screenModelScope.launch(Dispatchers.IO) {
|
||||
updateState { it.copy(loading = true) }
|
||||
try {
|
||||
val bytes = galleryHelper.download(url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user