From de63e10b026bffe8d136e7d69c9634b24bb2c484 Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Thu, 3 Oct 2024 23:25:13 +0200 Subject: [PATCH] DROID-2897 All Content | Search, subscription fixes (#1627) --- .../anytype/ui/allcontent/AllContentFragment.kt | 5 +++++ .../presentation/AllContentViewModel.kt | 17 +++++++++++++---- .../feature_allcontent/ui/AllContentScreen.kt | 6 +++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt index 12db76978c..43e8591825 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt @@ -139,6 +139,11 @@ class AllContentFragment : BaseComposeFragment() { } } + override fun onStart() { + vm.onStart() + super.onStart() + } + override fun onStop() { vm.onStop() super.onStop() diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt index 225efdd5c6..28231e41b2 100644 --- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt +++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt @@ -112,7 +112,6 @@ class AllContentViewModel( init { Timber.d("AllContentViewModel init, spaceId:[${vmParams.spaceId.id}]") setupInitialStateParams() - setupUiStateFlow() setupSearchStateFlow() setupMenuFlow() } @@ -152,8 +151,13 @@ class AllContentViewModel( searchObjects(searchParams).process( success = { searchResults -> Timber.d("Search objects by query:[$query], size: : ${searchResults.size}") - searchResultIds.value = searchResults.map { it.id } - restartSubscription.value++ + if (searchResults.isEmpty()) { + uiItemsState.value = emptyList() + uiContentState.value = UiContentState.Empty + } else { + searchResultIds.value = searchResults.map { it.id } + restartSubscription.value++ + } }, failure = { Timber.e(it, "Error searching objects by query") @@ -169,7 +173,7 @@ class AllContentViewModel( viewModelScope.launch { restartSubscription.flatMapLatest { loadData() - }.collect { items -> + }.collectLatest { items -> uiItemsState.value = items } } @@ -506,6 +510,11 @@ class AllContentViewModel( } } + fun onStart() { + Timber.d("onStart") + setupUiStateFlow() + } + fun onStop() { Timber.d("onStop") viewModelScope.launch { diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt index 8cb19c03fe..4f14c1fc19 100644 --- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt +++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt @@ -3,7 +3,6 @@ package com.anytypeio.anytype.feature_allcontent.ui import android.os.Build import androidx.compose.animation.core.animateFloatAsState import androidx.compose.foundation.background -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Column @@ -53,6 +52,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.anytypeio.anytype.core_ui.common.DefaultPreviews import com.anytypeio.anytype.core_ui.foundation.Divider +import com.anytypeio.anytype.core_ui.foundation.noRippleClickable import com.anytypeio.anytype.core_ui.views.ButtonSize import com.anytypeio.anytype.core_ui.views.Caption1Regular import com.anytypeio.anytype.core_ui.views.PreviewTitle1Medium @@ -292,7 +292,7 @@ private fun ContentItems( .padding(horizontal = 16.dp) .bottomBorder() .animateItem() - .clickable { + .noRippleClickable { onItemClicked(item) }, item = item @@ -305,7 +305,7 @@ private fun ContentItems( .padding(horizontal = 16.dp) .bottomBorder() .animateItem() - .clickable { + .noRippleClickable { onTypeClicked(item) }, item = item