a lot of improvements for long polling service and notifications
This commit is contained in:
@@ -13,13 +13,16 @@ import com.meloda.app.fast.data.State
|
||||
import com.meloda.app.fast.data.api.users.UsersUseCase
|
||||
import com.meloda.app.fast.data.db.AccountsRepository
|
||||
import com.meloda.app.fast.data.processState
|
||||
import com.meloda.app.fast.datastore.SettingsController
|
||||
import com.meloda.app.fast.datastore.UserSettings
|
||||
import com.meloda.app.fast.datastore.model.LongPollState
|
||||
import com.meloda.app.fast.model.database.AccountEntity
|
||||
import com.meloda.app.fast.network.OAuthErrorDomain
|
||||
import com.meloda.fast.auth.login.model.CaptchaArguments
|
||||
import com.meloda.fast.auth.login.model.LoginError
|
||||
import com.meloda.fast.auth.login.model.LoginScreenState
|
||||
import com.meloda.fast.auth.login.model.LoginValidationArguments
|
||||
import com.meloda.fast.auth.login.model.LoginUserBannedArguments
|
||||
import com.meloda.fast.auth.login.model.LoginValidationArguments
|
||||
import com.meloda.fast.auth.login.model.LoginValidationResult
|
||||
import com.meloda.fast.auth.login.validation.LoginValidator
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -67,7 +70,8 @@ class LoginViewModelImpl(
|
||||
private val oAuthUseCase: OAuthUseCase,
|
||||
private val usersUseCase: UsersUseCase,
|
||||
private val accountsRepository: AccountsRepository,
|
||||
private val loginValidator: LoginValidator
|
||||
private val loginValidator: LoginValidator,
|
||||
private val userSettings: UserSettings
|
||||
) : ViewModel(), LoginViewModel {
|
||||
|
||||
override val screenState = MutableStateFlow(LoginScreenState.EMPTY)
|
||||
@@ -155,6 +159,8 @@ class LoginViewModelImpl(
|
||||
UserConfig.trustedHash = account.trustedHash
|
||||
}
|
||||
|
||||
startLongPoll()
|
||||
|
||||
usersUseCase.get(
|
||||
userIds = null,
|
||||
fields = VkConstants.USER_FIELDS,
|
||||
@@ -238,6 +244,8 @@ class LoginViewModelImpl(
|
||||
UserConfig.trustedHash = account.trustedHash
|
||||
}
|
||||
|
||||
startLongPoll()
|
||||
|
||||
accountsRepository.storeAccounts(listOf(currentAccount))
|
||||
|
||||
captchaArguments.update { null }
|
||||
@@ -338,4 +346,14 @@ class LoginViewModelImpl(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startLongPoll() {
|
||||
userSettings.setLongPollStateToApply(
|
||||
if (SettingsController.isLongPollInBackgroundEnabled) {
|
||||
LongPollState.Background
|
||||
} else {
|
||||
LongPollState.InApp
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-13
@@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
@@ -156,17 +155,13 @@ fun ConversationsScreen(
|
||||
val view = LocalView.current
|
||||
val currentTheme = LocalTheme.current
|
||||
|
||||
val maxLines by remember {
|
||||
derivedStateOf {
|
||||
if (currentTheme.multiline) 2 else 1
|
||||
}
|
||||
val maxLines by remember(currentTheme) {
|
||||
mutableIntStateOf(if (currentTheme.multiline) 2 else 1)
|
||||
}
|
||||
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
val isListScrollingUp = listState.isScrollingUp()
|
||||
|
||||
val paginationConditionMet by remember {
|
||||
val paginationConditionMet by remember(canPaginate, listState) {
|
||||
derivedStateOf {
|
||||
canPaginate &&
|
||||
(listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index
|
||||
@@ -292,7 +287,7 @@ fun ConversationsScreen(
|
||||
|
||||
Column {
|
||||
AnimatedVisibility(
|
||||
visible = isListScrollingUp,
|
||||
visible = listState.isScrollingUp(),
|
||||
enter = slideIn { IntOffset(0, 600) } + fadeIn(tween(200)),
|
||||
exit = slideOut { IntOffset(0, 600) } + fadeOut(tween(200))
|
||||
) {
|
||||
@@ -351,10 +346,7 @@ fun ConversationsScreen(
|
||||
.nestedScroll(pullToRefreshState.nestedScrollConnection)
|
||||
) {
|
||||
ConversationsListComposable(
|
||||
onConversationsClick = { id ->
|
||||
onConversationItemClicked(id)
|
||||
|
||||
},
|
||||
onConversationsClick = onConversationItemClicked,
|
||||
onConversationsLongClick = onConversationItemLongClicked,
|
||||
screenState = screenState,
|
||||
state = listState,
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.meloda.app.fast.datastore.SettingsController
|
||||
import com.meloda.app.fast.datastore.SettingsKeys
|
||||
import com.meloda.app.fast.datastore.UserSettings
|
||||
import com.meloda.app.fast.datastore.isDebugSettingsShown
|
||||
import com.meloda.app.fast.datastore.model.LongPollState
|
||||
import com.meloda.app.fast.model.database.AccountEntity
|
||||
import com.meloda.app.fast.settings.model.SettingsItem
|
||||
import com.meloda.app.fast.settings.model.SettingsScreenState
|
||||
@@ -161,7 +162,14 @@ class SettingsViewModelImpl(
|
||||
when (key) {
|
||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND -> {
|
||||
val isEnabled = (newValue as? Boolean) == true
|
||||
userSettings.setLongPollBackground(isEnabled)
|
||||
userSettings.setLongPollStateToApply(
|
||||
userSettings.longPollStateToApply.value.let { state ->
|
||||
if (state.isLaunched()) {
|
||||
if (isEnabled) LongPollState.Background
|
||||
else LongPollState.InApp
|
||||
} else state
|
||||
}
|
||||
)
|
||||
|
||||
if (isEnabled) {
|
||||
// TODO: 26/11/2023, Danil Nikolaev: implement
|
||||
|
||||
Reference in New Issue
Block a user