Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
saving
Browse files Browse the repository at this point in the history
  • Loading branch information
John Oberhauser committed Jun 20, 2024
1 parent 5f0e39d commit 01e5ed3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package social.firefly.feature.post

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand All @@ -18,8 +15,8 @@ import social.firefly.common.loadResource
import social.firefly.common.utils.FileType
import social.firefly.common.utils.StringFactory
import social.firefly.common.utils.edit
import social.firefly.core.accounts.AccountsManager
import social.firefly.core.analytics.NewPostAnalytics
import social.firefly.core.datastore.UserPreferencesDatastoreManager
import social.firefly.core.model.StatusVisibility
import social.firefly.core.model.request.PollCreate
import social.firefly.core.navigation.usecases.PopNavBackstack
Expand All @@ -37,7 +34,6 @@ import social.firefly.feature.post.status.StatusDelegate
import timber.log.Timber
import java.util.Locale

@OptIn(ExperimentalCoroutinesApi::class)
class NewPostViewModel(
private val analytics: NewPostAnalytics,
private val replyStatusId: String?,
Expand All @@ -48,8 +44,8 @@ class NewPostViewModel(
private val editStatus: EditStatus,
private val popNavBackstack: PopNavBackstack,
private val showSnackbar: ShowSnackbar,
private val userPreferencesDatastoreManager: UserPreferencesDatastoreManager,
private val statusRepository: StatusRepository,
private val accountsManager: AccountsManager,
) : ViewModel(), NewPostInteractions, KoinComponent {

val statusDelegate: StatusDelegate by inject {
Expand Down Expand Up @@ -151,10 +147,9 @@ class NewPostViewModel(

val visibility = status?.visibility ?: StatusVisibility.Public

val defaultLanguageCode = status?.language ?: userPreferencesDatastoreManager
.activeUserDatastore
.flatMapLatest { it.defaultLanguage }
.first()
val defaultLanguageCode = status?.language ?: accountsManager
.getActiveAccount()
.defaultLanguage
.ifBlank {
Locale.getDefault().language
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.paging.LoadState
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf
import social.firefly.common.Resource
Expand All @@ -43,7 +42,6 @@ import social.firefly.core.ui.common.appbar.FfCloseableTopAppBar
import social.firefly.core.ui.common.dropdown.FfDropDownItem
import social.firefly.core.ui.common.dropdown.FfIconButtonDropDownMenu
import social.firefly.core.ui.common.error.GenericError
import social.firefly.core.ui.common.loading.MaxSizeLoading
import social.firefly.core.ui.common.pullrefresh.PullRefreshIndicator
import social.firefly.core.ui.common.pullrefresh.pullRefresh
import social.firefly.core.ui.common.pullrefresh.rememberPullRefreshState
Expand All @@ -58,12 +56,8 @@ internal fun ThreadScreen(
viewModel: ThreadViewModel = koinViewModel(parameters = { parametersOf(threadStatusId) }),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val threadType by viewModel.threadType.collectAsStateWithLifecycle(
initialValue = ThreadType.TREE
)

ThreadScreen(
threadType = threadType,
uiState = uiState,
postCardDelegate = viewModel.postCardDelegate,
threadInteractions = viewModel,
Expand All @@ -77,7 +71,6 @@ internal fun ThreadScreen(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ThreadScreen(
threadType: ThreadType,
uiState: Resource<ThreadPostCardCollection>,
postCardDelegate: PostCardInteractions,
threadInteractions: ThreadInteractions,
Expand All @@ -86,12 +79,6 @@ private fun ThreadScreen(
Column(Modifier.systemBarsPadding()) {
FfCloseableTopAppBar(
title = stringResource(id = R.string.thread_screen_title),
actions = {
ThreadTypeButton(
threadType = threadType,
threadInteractions = threadInteractions,
)
}
)

val refreshState = rememberPullRefreshState(
Expand All @@ -115,7 +102,6 @@ private fun ThreadScreen(
modifier = Modifier
.widthIn(max = UiConstants.MAX_WIDTH)
.align(Alignment.TopCenter),
threadType = threadType,
statuses = it,
postCardDelegate = postCardDelegate,
threadInteractions = threadInteractions,
Expand All @@ -134,7 +120,6 @@ private fun ThreadScreen(

@Composable
private fun ThreadList(
threadType: ThreadType,
statuses: ThreadPostCardCollection,
postCardDelegate: PostCardInteractions,
threadInteractions: ThreadInteractions,
Expand Down Expand Up @@ -201,7 +186,6 @@ private fun ThreadList(
}

descendants(
threadType = threadType,
statuses = statuses,
postCardDelegate = postCardDelegate,
threadInteractions = threadInteractions
Expand All @@ -210,7 +194,6 @@ private fun ThreadList(
}

private fun LazyListScope.descendants(
threadType: ThreadType,
statuses: ThreadPostCardCollection,
postCardDelegate: PostCardInteractions,
threadInteractions: ThreadInteractions,
Expand All @@ -224,7 +207,7 @@ private fun LazyListScope.descendants(
PostCardListItem(
uiState = item.uiState,
postCardInteractions = postCardDelegate,
showDivider = threadType != ThreadType.TREE,
showDivider = false,
)
}
is ThreadDescendant.ViewMore -> {
Expand Down
Loading

0 comments on commit 01e5ed3

Please sign in to comment.