diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/DashboardView.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/DashboardView.kt index 3eb898e6cd..a4269b9226 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/DashboardView.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/DashboardView.kt @@ -24,7 +24,7 @@ sealed class DashboardView { data class Document( override val id: Id, val target: Id, - val title: String? = null, + val title: String = "", val emoji: String? = null, val image: String? = null, val layout: ObjectType.Layout? = null, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/HomeDashboardViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/HomeDashboardViewModel.kt index 5acf5222a9..73ffb380e4 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/HomeDashboardViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/dashboard/HomeDashboardViewModel.kt @@ -47,6 +47,7 @@ import com.anytypeio.anytype.presentation.navigation.AppNavigation import com.anytypeio.anytype.presentation.navigation.SupportNavigation import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.presentation.objects.SupportedLayouts +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.search.ObjectSearchConstants import com.anytypeio.anytype.presentation.settings.EditorSettings import kotlinx.coroutines.channels.Channel @@ -408,7 +409,7 @@ class HomeDashboardViewModel( DashboardView.Document( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = true, isLoading = false, emoji = obj.iconEmoji, @@ -447,7 +448,7 @@ class HomeDashboardViewModel( DashboardView.ObjectSet( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = obj.isArchived ?: false, isLoading = false, icon = ObjectIcon.from( @@ -460,7 +461,7 @@ class HomeDashboardViewModel( DashboardView.Document( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = obj.isArchived ?: false, isLoading = false, emoji = obj.iconEmoji, @@ -500,7 +501,7 @@ class HomeDashboardViewModel( DashboardView.ObjectSet( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = obj.isArchived ?: false, isLoading = false, icon = ObjectIcon.from( @@ -513,7 +514,7 @@ class HomeDashboardViewModel( DashboardView.Document( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = obj.isArchived ?: false, isLoading = false, emoji = obj.iconEmoji, @@ -550,7 +551,7 @@ class HomeDashboardViewModel( DashboardView.ObjectSet( id = obj.id, target = obj.id, - title = obj.name, + title = obj.getProperName(), isArchived = obj.isArchived ?: false, isLoading = false, icon = ObjectIcon.from( diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt index f1f77471ca..686fa3e2e7 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt @@ -1,13 +1,13 @@ package com.anytypeio.anytype.presentation.editor.editor.ext import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.ext.replaceRangeWithWord import com.anytypeio.anytype.presentation.editor.editor.Markup import com.anytypeio.anytype.presentation.editor.editor.Markup.Companion.NON_EXISTENT_OBJECT_MENTION_NAME import com.anytypeio.anytype.presentation.editor.editor.Markup.Mark.Companion.IS_DELETED_VALUE import com.anytypeio.anytype.presentation.editor.editor.Markup.Mark.Companion.KEY_IS_DELETED +import com.anytypeio.anytype.presentation.extension.getProperObjectName import com.anytypeio.anytype.presentation.extension.shift import timber.log.Timber @@ -26,15 +26,10 @@ fun Block.Content.Text.getTextAndMarks( try { updatedMarks.forEach { mark -> if (mark.type != Markup.Type.MENTION || mark.param == null) return@forEach - val layoutCode = details.details[mark.param]?.layout?.toInt() var newName = if (mark.extras[KEY_IS_DELETED] == IS_DELETED_VALUE) { NON_EXISTENT_OBJECT_MENTION_NAME } else { - if (layoutCode == ObjectType.Layout.NOTE.code) { - details.details[mark.param]?.snippet?.replace("\n", "") - } else { - details.details[mark.param]?.name - } ?: return@forEach + details.details.getProperObjectName(id = mark.param) ?: return@forEach } val oldName = updatedText.substring(mark.from, mark.to) if (newName != oldName) { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt index ff16241694..47639f2746 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider import com.anytypeio.anytype.presentation.editor.editor.ext.getTextAndMarks import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.toggle.ToggleStateHolder +import com.anytypeio.anytype.presentation.extension.getProperObjectName import com.anytypeio.anytype.presentation.mapper.* import com.anytypeio.anytype.presentation.relations.DocumentRelationView import com.anytypeio.anytype.presentation.relations.view @@ -1189,7 +1190,7 @@ class DefaultBlockViewRenderer( else null }, - text = getProperPageName(id = content.target, details = details), + text = details.details.getProperObjectName(id = content.target), indent = indent, isLoading = !details.details.containsKey(content.target), isSelected = checkIfSelected( @@ -1221,7 +1222,7 @@ class DefaultBlockViewRenderer( else null }, - text = details.details[content.target]?.name, + text = details.details.getProperObjectName(id = content.target), indent = indent, isSelected = checkIfSelected( mode = mode, @@ -1403,13 +1404,4 @@ class DefaultBlockViewRenderer( val layoutCode = details.details[root.id]?.layout?.toInt() return layoutCode == ObjectType.Layout.NOTE.code } - - private fun getProperPageName(id: Id, details: Block.Details): String? { - val layoutCode = details.details[id]?.layout?.toInt() - return if (layoutCode == ObjectType.Layout.NOTE.code) { - details.details[id]?.snippet?.replace("\n", "") - } else { - details.details[id]?.name - } - } } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtension.kt index 8714cc078e..bf7c7afe98 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtension.kt @@ -6,6 +6,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.presentation.dashboard.DashboardView import com.anytypeio.anytype.presentation.objects.ObjectIcon +import com.anytypeio.anytype.presentation.objects.getProperName fun List.addAndSortByIds( ids: List, @@ -50,7 +51,7 @@ fun List.updateDetails( if (view.target == target) { val obj = ObjectWrapper.Basic(details.map) view.copy( - title = details.name, + title = obj.getProperName(), emoji = details.iconEmoji?.let { name -> if (name.isNotEmpty()) name diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/MapExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/MapExtension.kt index c9d05c65f4..0abbd6c64b 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/MapExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/MapExtension.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.extension import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id +import com.anytypeio.anytype.core_models.ObjectType fun Map.updateFields(update: Map): Map { val result = this.toMutableMap() @@ -9,4 +10,13 @@ fun Map.updateFields(update: Map): Map.getProperObjectName(id: Id): String? { + val layoutCode = this[id]?.layout?.toInt() + return if (layoutCode == ObjectType.Layout.NOTE.code) { + this[id]?.snippet?.replace("\n", " ")?.take(30) + } else { + this[id]?.name + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt index 9ea7f1fe01..3f7e713d37 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt @@ -12,6 +12,7 @@ import com.anytypeio.anytype.presentation.navigation.ObjectView import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.presentation.objects.ObjectLayoutView import com.anytypeio.anytype.presentation.objects.ObjectTypeView +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.relations.type import com.anytypeio.anytype.presentation.sets.buildGridRow import com.anytypeio.anytype.presentation.sets.model.* @@ -391,7 +392,7 @@ fun Block.Content.Link.toPageView( return DashboardView.Document( id = id, target = target, - title = obj.name, + title = obj.getProperName(), emoji = details.details[target]?.iconEmoji?.let { unicode -> if (unicode.isNotEmpty()) unicode else null }, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectWrapperMapper.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectWrapperMapper.kt index 7214b6a579..4674c449a4 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectWrapperMapper.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectWrapperMapper.kt @@ -142,8 +142,10 @@ private fun getProperTypeName(url: String?, types: List) = private fun ObjectWrapper.Basic.getProperFileImage(urlBuilder: UrlBuilder): String? = iconImage?.let { if (it.isBlank()) null else urlBuilder.thumbnail(it) } -private fun ObjectWrapper.Basic.getProperName() = if (layout == ObjectType.Layout.NOTE) { - snippet.orEmpty() -} else { - name.orEmpty() +fun ObjectWrapper.Basic.getProperName(): String { + return if (layout == ObjectType.Layout.NOTE) { + snippet?.replace("\n", " ")?.take(30).orEmpty() + } else { + name.orEmpty() + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/AddObjectRelationValueViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/AddObjectRelationValueViewModel.kt index 55a51f67ab..f7614e2e8c 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/AddObjectRelationValueViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/AddObjectRelationValueViewModel.kt @@ -18,6 +18,7 @@ import com.anytypeio.anytype.domain.relations.AddObjectRelationOption import com.anytypeio.anytype.presentation.common.BaseViewModel import com.anytypeio.anytype.presentation.editor.editor.ThemeColor import com.anytypeio.anytype.presentation.objects.ObjectIcon +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.relations.providers.ObjectDetailProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider @@ -151,7 +152,7 @@ abstract class AddObjectRelationValueViewModel( items.add( RelationValueView.Object.Default( id = id, - name = wrapper.name.orEmpty(), + name = wrapper.getProperName(), typeName = objectType?.name, type = type, icon = ObjectIcon.from( @@ -172,7 +173,7 @@ abstract class AddObjectRelationValueViewModel( items.add( RelationValueView.Object.Default( id = value, - name = wrapper.name.orEmpty(), + name = wrapper.getProperName(), typeName = objectType?.name, type = type, icon = ObjectIcon.from( 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 72d0208da7..6ebc45308b 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 @@ -10,6 +10,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.extension.isValueRequired import com.anytypeio.anytype.presentation.mapper.* import com.anytypeio.anytype.presentation.objects.ObjectIcon +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.sets.ObjectSet import com.anytypeio.anytype.presentation.sets.ObjectSetViewState import com.anytypeio.anytype.presentation.sets.filter.CreateFilterView @@ -434,7 +435,7 @@ fun Relation.toObjects( list.add( ObjectView.Default( id = id, - name = details[id]?.name.orEmpty(), + name = wrapper.getProperName(), icon = ObjectIcon.from( obj = wrapper, layout = wrapper.layout, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/RelationValueBaseViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/RelationValueBaseViewModel.kt index c59924bb5d..ca612e0247 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/RelationValueBaseViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/RelationValueBaseViewModel.kt @@ -18,6 +18,7 @@ import com.anytypeio.anytype.domain.relations.AddFileToRecord import com.anytypeio.anytype.presentation.common.BaseViewModel import com.anytypeio.anytype.presentation.navigation.AppNavigation import com.anytypeio.anytype.presentation.objects.ObjectIcon +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.relations.providers.ObjectDetailProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider @@ -133,7 +134,7 @@ abstract class RelationValueBaseViewModel( items.add( RelationValueView.Object.Default( id = id, - name = detail?.name.orEmpty(), + name = wrapper.getProperName(), typeName = objectType?.name, type = objectType?.url, icon = ObjectIcon.from( @@ -163,7 +164,7 @@ abstract class RelationValueBaseViewModel( items.add( RelationValueView.Object.Default( id = value, - name = detail?.name.orEmpty(), + name = wrapper.getProperName(), typeName = objectType?.name, type = objectType?.url, icon = ObjectIcon.from( diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt index 1d8adad9f8..a4691c3ffd 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.* import com.anytypeio.anytype.core_utils.ext.typeOf import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.presentation.objects.ObjectIcon +import com.anytypeio.anytype.presentation.objects.getProperName import com.anytypeio.anytype.presentation.relations.DateParser import com.anytypeio.anytype.presentation.relations.NumberParser import com.anytypeio.anytype.presentation.relations.ObjectSetConfig @@ -20,7 +21,7 @@ fun List.buildGridRow( val obj = ObjectWrapper.Basic(record) val type = obj.type.firstOrNull() - val name = obj.name + val name = obj.getProperName() val emoji = obj.iconEmoji val image = obj.iconImage val done = obj.done @@ -217,7 +218,7 @@ fun Map.buildObjectViews( objects.add( ObjectView.Default( id = value, - name = details[value]?.name.orEmpty(), + name = wrapper.getProperName(), icon = ObjectIcon.from( obj = wrapper, layout = wrapper.layout, @@ -236,7 +237,7 @@ fun Map.buildObjectViews( objects.add( ObjectView.Default( id = id, - name = details[id]?.name.orEmpty(), + name = wrapper.getProperName(), icon = ObjectIcon.from( obj = wrapper, layout = wrapper.layout, diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtensionKtTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtensionKtTest.kt index 069d80aacd..041ca5a64b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtensionKtTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/extension/DashboardViewExtensionKtTest.kt @@ -75,7 +75,7 @@ class DashboardViewExtensionKtTest { isArchived = false, id = id2, target = target2, - title = null, + title = "", emoji = "emoji777" ), diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/ObjectWrapperExtensionsKtTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/ObjectWrapperExtensionsKtTest.kt index ed6bfba87c..449504d621 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/ObjectWrapperExtensionsKtTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/ObjectWrapperExtensionsKtTest.kt @@ -180,7 +180,7 @@ class ObjectWrapperExtensionsKtTest { } @Test - fun `should map to view with snippet as name when layout is not note`() { + fun `should map to view with name as name when layout is not note`() { val imageHash = "ycd79" @@ -202,6 +202,30 @@ class ObjectWrapperExtensionsKtTest { ) } + @Test + fun `should map to view proper snippet max 30 characters`() { + + val obj = ObjectWrapper.Basic( + mapOf( + "id" to "Ef6", + "name" to "LmL7R", + "snippet" to "Anytype\nis\nnext-generation software that\n" + + "works like\nyour brain does. It solves everyday\n" + + "problems\nwhile respecting your privacy and\n" + + "data rights.", + "layout" to ObjectType.Layout.NOTE.code.toDouble() + ) + + ) + + val result = listOf(obj).toView(urlBuilder, objectTypes = listOf()) + + assertEquals( + expected = "Anytype is next-generation sof", + actual = result.first().name + ) + } + fun stubUrlBuilder(hash: String?) { if (hash == null) { urlBuilder.stub { diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/TagAndStatusTests.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/TagAndStatusTests.kt index b97d7bda08..8155503873 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/TagAndStatusTests.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/TagAndStatusTests.kt @@ -139,6 +139,7 @@ class TagAndStatusTests { val expected = Viewer.GridView.Row( id = recordId, + name = "", type = "Type111", cells = listOf( CellView.Description( @@ -286,6 +287,7 @@ class TagAndStatusTests { val expected = Viewer.GridView.Row( id = recordId, + name = "", type = "Type111", cells = listOf( CellView.Description(