From 107ccf98f5447b9fb5671346c034032a236caa5a Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Tue, 22 Oct 2024 17:19:25 +0200 Subject: [PATCH] DROID-2973 Vault | Fix | Set max space count to 50 (#1716) --- .../anytypeio/anytype/ui/vault/VaultScreen.kt | 30 +++++++++++-------- .../drawable/ic_vault_top_toolbar_plus.xml | 10 +++++++ .../viewmodel/GalleryInstallationViewModel.kt | 4 +++ .../spaces/SelectSpaceViewModel.kt | 15 ++++++++-- 4 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 core-ui/src/main/res/drawable/ic_vault_top_toolbar_plus.xml diff --git a/app/src/main/java/com/anytypeio/anytype/ui/vault/VaultScreen.kt b/app/src/main/java/com/anytypeio/anytype/ui/vault/VaultScreen.kt index 7a59517ad6..187bb2caef 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/vault/VaultScreen.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/vault/VaultScreen.kt @@ -57,6 +57,7 @@ import com.anytypeio.anytype.core_ui.views.Relations3 import com.anytypeio.anytype.core_ui.views.Title1 import com.anytypeio.anytype.core_utils.insets.EDGE_TO_EDGE_MIN_SDK import com.anytypeio.anytype.presentation.editor.cover.CoverGradient +import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel import com.anytypeio.anytype.presentation.spaces.SpaceIconView import com.anytypeio.anytype.presentation.vault.VaultViewModel.VaultSpaceView import com.anytypeio.anytype.presentation.wallpaper.WallpaperColor @@ -106,7 +107,8 @@ fun VaultScreen( VaultScreenToolbar( onPlusClicked = onCreateSpaceClicked, - onSettingsClicked = onSettingsClicked + onSettingsClicked = onSettingsClicked, + spaceCountLimitReached = spaces.size >= SelectSpaceViewModel.MAX_SPACE_COUNT ) LazyColumn( @@ -141,7 +143,7 @@ fun VaultScreen( icon = item.icon ) } - if (idx == spaces.lastIndex) { + if (idx == spaces.lastIndex && spaces.size < SelectSpaceViewModel.MAX_SPACE_COUNT) { VaultSpaceAddCard( onCreateSpaceClicked = onCreateSpaceClicked ) @@ -163,6 +165,7 @@ fun VaultScreen( @Composable fun VaultScreenToolbar( + spaceCountLimitReached: Boolean = false, onPlusClicked: () -> Unit, onSettingsClicked: () -> Unit ) { @@ -187,17 +190,18 @@ fun VaultScreenToolbar( onSettingsClicked() } ) - Image( - // TODO change icon - painter = painterResource(id = R.drawable.ic_plus), - contentDescription = "Plus button", - modifier = Modifier - .align(Alignment.CenterEnd) - .padding(end = 16.dp) - .noRippleClickable { - onPlusClicked() - } - ) + if (!spaceCountLimitReached) { + Image( + painter = painterResource(id = R.drawable.ic_vault_top_toolbar_plus), + contentDescription = "Plus button", + modifier = Modifier + .align(Alignment.CenterEnd) + .padding(end = 16.dp) + .noRippleClickable { + onPlusClicked() + } + ) + } } } diff --git a/core-ui/src/main/res/drawable/ic_vault_top_toolbar_plus.xml b/core-ui/src/main/res/drawable/ic_vault_top_toolbar_plus.xml new file mode 100644 index 0000000000..f68f51da41 --- /dev/null +++ b/core-ui/src/main/res/drawable/ic_vault_top_toolbar_plus.xml @@ -0,0 +1,10 @@ + + + diff --git a/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt b/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt index 661cc67c1e..e1a6e3b0c9 100644 --- a/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt +++ b/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt @@ -28,6 +28,7 @@ import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationNaviga import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationSpacesState import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationState import com.anytypeio.anytype.gallery_experience.models.GallerySpaceView +import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider import com.anytypeio.anytype.presentation.spaces.spaceIcon import kotlinx.coroutines.flow.MutableSharedFlow @@ -119,6 +120,9 @@ class GalleryInstallationViewModel( viewModelScope.launch { command.emit(GalleryInstallationNavigation.CloseSpaces) val state = (mainState.value as? GalleryInstallationState.Success) ?: return@launch + if (spacesViewState.value.spaces.size >= SelectSpaceViewModel.MAX_SPACE_COUNT) { + return@launch + } val manifestInfo = state.info mainState.value = state.copy(isLoading = true) val params = CreateSpace.Params( diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/SelectSpaceViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/SelectSpaceViewModel.kt index 27ed8eca49..01a863de43 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/SelectSpaceViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/SelectSpaceViewModel.kt @@ -102,7 +102,9 @@ class SelectSpaceViewModel( val (active, others) = spaceViews.partition { view -> view.view.isSelected } addAll(active) addAll(others) - add(SelectSpaceView.Create) + if (size < MAX_SPACE_COUNT) { + add(SelectSpaceView.Create) + } } } .catch { @@ -161,8 +163,13 @@ class SelectSpaceViewModel( } fun onCreateSpaceClicked() { - viewModelScope.launch { - commands.emit(Command.CreateSpace) + val count = views.value.count { view -> view is SelectSpaceView.Space } + if (count >= MAX_SPACE_COUNT) { + sendToast(SPACE_COUNT_EXCEEDED_ERROR) + } else { + viewModelScope.launch { + commands.emit(Command.CreateSpace) + } } } @@ -201,6 +208,8 @@ class SelectSpaceViewModel( companion object { const val SELECT_SPACE_SUBSCRIPTION = "select_space_subscription.spaces" + const val SPACE_COUNT_EXCEEDED_ERROR = "Space max count exceeded. You cannot create more." + const val MAX_SPACE_COUNT = 50 } }