mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3590 Vault | Space counters, part 1 (#2453)
This commit is contained in:
parent
5567b2c41e
commit
cd938cd380
3 changed files with 119 additions and 45 deletions
|
@ -15,6 +15,7 @@ import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
|
|||
import com.anytypeio.anytype.core_models.primitives.Space
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
import com.anytypeio.anytype.domain.chats.ChatPreviewContainer
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.misc.DeepLinkResolver
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
|
@ -47,7 +48,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.emitAll
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onCompletion
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
|
@ -69,7 +72,8 @@ class VaultViewModel(
|
|||
private val deepLinkToObjectDelegate: DeepLinkToObjectDelegate,
|
||||
private val appActionManager: AppActionManager,
|
||||
private val spaceInviteResolver: SpaceInviteResolver,
|
||||
private val profileContainer: ProfileSubscriptionManager
|
||||
private val profileContainer: ProfileSubscriptionManager,
|
||||
private val chatPreviewContainer: ChatPreviewContainer
|
||||
) : NavigationViewModel<VaultViewModel.Navigation>(), DeepLinkToObjectDelegate by deepLinkToObjectDelegate {
|
||||
|
||||
val spaces = MutableStateFlow<List<VaultSpaceView>>(emptyList())
|
||||
|
@ -90,45 +94,53 @@ class VaultViewModel(
|
|||
Timber.i("VaultViewModel, init")
|
||||
viewModelScope.launch {
|
||||
val wallpapers = getSpaceWallpapers.async(Unit).getOrNull() ?: emptyMap()
|
||||
spaceViewSubscriptionContainer
|
||||
.observe()
|
||||
.take(1)
|
||||
.onCompletion {
|
||||
emitAll(
|
||||
spaceViewSubscriptionContainer
|
||||
.observe()
|
||||
.debounce(SPACE_VAULT_DEBOUNCE_DURATION)
|
||||
)
|
||||
}
|
||||
.combine(observeVaultSettings.flow()) { spaces, settings ->
|
||||
spaces
|
||||
.filter { space -> (space.isActive || space.isLoading) }
|
||||
.distinctBy { it.id }
|
||||
.map { space ->
|
||||
VaultSpaceView(
|
||||
space = space,
|
||||
icon = space.spaceIcon(
|
||||
builder = urlBuilder,
|
||||
spaceGradientProvider = SpaceGradientProvider.Default
|
||||
),
|
||||
wallpaper = wallpapers.getOrDefault(
|
||||
key = space.targetSpaceId,
|
||||
defaultValue = Wallpaper.Default
|
||||
)
|
||||
)
|
||||
}.sortedBy { space ->
|
||||
val idx = settings.orderOfSpaces.indexOf(
|
||||
space.space.id
|
||||
)
|
||||
if (idx == -1) {
|
||||
Int.MIN_VALUE
|
||||
} else {
|
||||
idx
|
||||
}
|
||||
combine(
|
||||
spaceViewSubscriptionContainer
|
||||
.observe()
|
||||
.take(1)
|
||||
.onCompletion {
|
||||
emitAll(
|
||||
spaceViewSubscriptionContainer
|
||||
.observe()
|
||||
.debounce(SPACE_VAULT_DEBOUNCE_DURATION)
|
||||
)
|
||||
},
|
||||
observeVaultSettings.flow(),
|
||||
chatPreviewContainer.observePreviews()
|
||||
) { spaces, settings, chatPreviews ->
|
||||
spaces
|
||||
.filter { space -> (space.isActive || space.isLoading) }
|
||||
.map { space ->
|
||||
val chatPreview = space.targetSpaceId?.let { spaceId ->
|
||||
chatPreviews.find { it.space.id == spaceId }
|
||||
}
|
||||
}.collect {
|
||||
spaces.value = it
|
||||
}
|
||||
|
||||
VaultSpaceView(
|
||||
space = space,
|
||||
icon = space.spaceIcon(
|
||||
builder = urlBuilder,
|
||||
spaceGradientProvider = SpaceGradientProvider.Default
|
||||
),
|
||||
wallpaper = wallpapers.getOrDefault(
|
||||
key = space.targetSpaceId,
|
||||
defaultValue = Wallpaper.Default
|
||||
),
|
||||
unreadMessageCount = chatPreview?.state?.unreadMessages?.counter ?: 0,
|
||||
unreadMentionCount = chatPreview?.state?.unreadMentions?.counter ?: 0
|
||||
)
|
||||
}.sortedBy { space ->
|
||||
val idx = settings.orderOfSpaces.indexOf(
|
||||
space.space.id
|
||||
)
|
||||
if (idx == -1) {
|
||||
Int.MIN_VALUE
|
||||
} else {
|
||||
idx
|
||||
}
|
||||
}
|
||||
}.collect {
|
||||
spaces.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +365,8 @@ class VaultViewModel(
|
|||
private val deepLinkToObjectDelegate: DeepLinkToObjectDelegate,
|
||||
private val appActionManager: AppActionManager,
|
||||
private val spaceInviteResolver: SpaceInviteResolver,
|
||||
private val profileContainer: ProfileSubscriptionManager
|
||||
private val profileContainer: ProfileSubscriptionManager,
|
||||
private val chatPreviewContainer: ChatPreviewContainer
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(
|
||||
|
@ -372,14 +385,17 @@ class VaultViewModel(
|
|||
deepLinkToObjectDelegate = deepLinkToObjectDelegate,
|
||||
appActionManager = appActionManager,
|
||||
spaceInviteResolver = spaceInviteResolver,
|
||||
profileContainer = profileContainer
|
||||
profileContainer = profileContainer,
|
||||
chatPreviewContainer = chatPreviewContainer
|
||||
) as T
|
||||
}
|
||||
|
||||
data class VaultSpaceView(
|
||||
val space: ObjectWrapper.SpaceView,
|
||||
val icon: SpaceIconView,
|
||||
val wallpaper: Wallpaper = Wallpaper.Default
|
||||
val wallpaper: Wallpaper = Wallpaper.Default,
|
||||
val unreadMessageCount: Int = 0,
|
||||
val unreadMentionCount: Int = 0,
|
||||
)
|
||||
|
||||
sealed class Command {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue