diff --git a/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt index d1d6ecb8df..324fd61f27 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt @@ -554,14 +554,16 @@ open class ObjectSetFragment : } } - private fun bindHeader(title: BlockView.Title.Basic) { - this.title.pauseTextWatchers { - this.title.setText(title.text) + private fun bindHeader(header: BlockView.Title.Basic) { + if (title.text.toString() != header.text) { + title.pauseTextWatchers { + title.setText(header.text) + } } - binding.topToolbar.root.findViewById(R.id.tvTopToolbarTitle).text = title.text + binding.topToolbar.root.findViewById(R.id.tvTopToolbarTitle).text = header.text binding.objectHeader.root.findViewById(R.id.docEmojiIconContainer).apply { - if (title.emoji != null) visible() else gone() + if (header.emoji != null) visible() else gone() jobs += this.clicks() .throttleFirst() .onEach { vm.onIconClicked() } @@ -569,7 +571,7 @@ open class ObjectSetFragment : } binding.objectHeader.root.findViewById(R.id.imageIcon).apply { - if (title.image != null) visible() else gone() + if (header.image != null) visible() else gone() jobs += this.clicks() .throttleFirst() .onEach { vm.onIconClicked() } @@ -577,13 +579,13 @@ open class ObjectSetFragment : } binding.objectHeader.root.findViewById(R.id.emojiIcon) - .setEmojiOrNull(title.emoji) + .setEmojiOrNull(header.emoji) - if (title.image != null) { + if (header.image != null) { binding.objectHeader.root.findViewById(R.id.imageIcon).apply { Glide .with(this) - .load(title.image) + .load(header.image) .centerCrop() .into(this) } @@ -592,9 +594,9 @@ open class ObjectSetFragment : } setCover( - coverColor = title.coverColor, - coverGradient = title.coverGradient, - coverImage = title.coverImage + coverColor = header.coverColor, + coverGradient = header.coverGradient, + coverImage = header.coverImage ) } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt index c6a3c0dcd6..a996e0f03d 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt @@ -11,7 +11,6 @@ import com.anytypeio.anytype.core_models.DVViewerType import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relation -import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.core_utils.ext.CURRENT_MONTH import com.anytypeio.anytype.core_utils.ext.CURRENT_WEEK import com.anytypeio.anytype.core_utils.ext.EXACT_DAY @@ -24,6 +23,7 @@ import com.anytypeio.anytype.core_utils.ext.NUMBER_OF_DAYS_FROM_NOW import com.anytypeio.anytype.core_utils.ext.TODAY import com.anytypeio.anytype.core_utils.ext.TOMORROW import com.anytypeio.anytype.core_utils.ext.YESTERDAY +import com.anytypeio.anytype.core_utils.ext.orNull import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.objects.ObjectStore import com.anytypeio.anytype.domain.objects.StoreOfRelations @@ -195,20 +195,18 @@ fun title( urlBuilder: UrlBuilder, details: Map ): BlockView.Title.Basic { - + val wrapper = ObjectWrapper.Basic(details[ctx]?.map ?: emptyMap()) val objectDetails = details[ctx] - val coverContainer = BlockFieldsCoverWrapper(objectDetails) - .getCover(urlBuilder, coverImageHashProvider) - + val coverContainer = BlockFieldsCoverWrapper(objectDetails).getCover( + urlBuilder = urlBuilder, + coverImageHashProvider = coverImageHashProvider + ) return BlockView.Title.Basic( id = title.id, - text = title.content().text, - emoji = objectDetails?.iconEmoji?.ifEmpty { null }, - image = objectDetails?.iconImage?.let { hash -> - if (hash.isNotEmpty()) - urlBuilder.thumbnail(hash = hash) - else - null + text = wrapper.name.orEmpty(), + emoji = wrapper.iconEmoji.orNull(), + image = wrapper.iconImage.orNull()?.let { hash -> + urlBuilder.thumbnail(hash = hash) }, coverImage = coverContainer.coverImage, coverColor = coverContainer.coverColor, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt index bde2b0c579..128bb73d3b 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt @@ -161,6 +161,7 @@ class ObjectSetViewModel( viewModelScope.launch { stateReducer.state .filterIsInstance() + .distinctUntilChanged() .collectLatest { state -> featured.value = state.featuredRelations( ctx = context, @@ -221,7 +222,8 @@ class ObjectSetViewModel( .mapLatest { params -> updateText(params).process( failure = { e -> Timber.e(e, "Error while updating title") }, - success = { Timber.d("Sets' title updated successfully") } + success = { + Timber.d("Sets' title updated successfully") } ) } .collect() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt index 48bfe158c3..6f477ab5ad 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt @@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.RelationLink +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.Relations.ID import com.anytypeio.anytype.core_models.Relations.LAYOUT import com.anytypeio.anytype.core_models.StubRelationObject @@ -76,7 +77,13 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { stubInterceptEvents() stubInterceptThreadStatus() - val rootObject = ObjectWrapper.Basic(map = mapOf(ID to root, LAYOUT to COLLECTION_LAYOUT)) + val rootObject = ObjectWrapper.Basic( + map = mapOf( + ID to root, + Relations.NAME to objectCollection.details.details[root]?.name, + LAYOUT to COLLECTION_LAYOUT + ) + ) stubOpenObject( doc = listOf( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt index 4cfad5527e..5ed37103fb 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt @@ -17,6 +17,7 @@ import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.StubTitle import com.anytypeio.anytype.presentation.sets.subscription.DefaultDataViewSubscription +import com.anytypeio.anytype.test_utils.MockDataFactory import net.bytebuddy.utility.RandomString class MockCollection(context: String) { @@ -201,6 +202,7 @@ class MockCollection(context: String) { root to Block.Fields( mapOf( Relations.ID to root, + Relations.NAME to MockDataFactory.randomString(), Relations.LAYOUT to ObjectType.Layout.COLLECTION.code.toDouble() ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt index 4d7e8dc3c9..f4cda67d2c 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt @@ -61,7 +61,7 @@ class ObjectStateCollectionViewTest : ObjectSetViewModelTestSetup() { assertIs(stateFlow.awaitItem()) assertEquals( - expected = mockObjectCollection.title.content.asText().text, + expected = mockObjectCollection.details.details[mockObjectCollection.root]?.name, actual = headerFlow.awaitItem()?.text ) viewerFlow.expectNoEvents()