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