mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-10 10:00:44 +09:00
App | Feature | Object snippet as title (#1907)
This commit is contained in:
parent
ad4b32d8f1
commit
e422b9a99e
15 changed files with 73 additions and 41 deletions
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<DashboardView>.addAndSortByIds(
|
||||
ids: List<String>,
|
||||
|
@ -50,7 +51,7 @@ fun List<DashboardView>.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
|
||||
|
|
|
@ -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<Id, Block.Fields>.updateFields(update: Map<Id, Block.Fields>): Map<Id, Block.Fields> {
|
||||
val result = this.toMutableMap()
|
||||
|
@ -9,4 +10,13 @@ fun Map<Id, Block.Fields>.updateFields(update: Map<Id, Block.Fields>): Map<Id, B
|
|||
result[key] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun Map<Id, Block.Fields>.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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -142,8 +142,10 @@ private fun getProperTypeName(url: String?, types: List<ObjectType>) =
|
|||
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()
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<ColumnView>.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<String, Any?>.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<String, Any?>.buildObjectViews(
|
|||
objects.add(
|
||||
ObjectView.Default(
|
||||
id = id,
|
||||
name = details[id]?.name.orEmpty(),
|
||||
name = wrapper.getProperName(),
|
||||
icon = ObjectIcon.from(
|
||||
obj = wrapper,
|
||||
layout = wrapper.layout,
|
||||
|
|
|
@ -75,7 +75,7 @@ class DashboardViewExtensionKtTest {
|
|||
isArchived = false,
|
||||
id = id2,
|
||||
target = target2,
|
||||
title = null,
|
||||
title = "",
|
||||
emoji = "emoji777"
|
||||
),
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue