mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3484 Primitives | Plural names, part 1 (#2228)
This commit is contained in:
parent
23cfa42680
commit
7c74976d1a
21 changed files with 77 additions and 22 deletions
|
@ -26,6 +26,7 @@ sealed class ObjectWrapper {
|
|||
val lastOpenedDate: Any? by default
|
||||
|
||||
val name: String? by default
|
||||
val pluralName: String? by default
|
||||
|
||||
val iconEmoji: String? by default
|
||||
val iconImage: String? = getSingleValue(Relations.ICON_IMAGE)
|
||||
|
@ -163,6 +164,7 @@ sealed class ObjectWrapper {
|
|||
val id: Id by default
|
||||
val uniqueKey: String by default
|
||||
val name: String? by default
|
||||
val pluralName: String? by default
|
||||
val sourceObject: Id? get() = getSingleValue(Relations.SOURCE_OBJECT)
|
||||
val description: String? = getSingleValue(Relations.DESCRIPTION)
|
||||
val isArchived: Boolean? by default
|
||||
|
|
|
@ -15,6 +15,7 @@ object Relations {
|
|||
const val LAYOUT = "resolvedLayout"
|
||||
const val LEGACY_LAYOUT = "layout"
|
||||
const val NAME = "name"
|
||||
const val PLURAL_NAME = "pluralName"
|
||||
const val ICON_EMOJI = "iconEmoji"
|
||||
const val ICON_OPTION = "iconOption"
|
||||
const val ICON_NAME = "iconName"
|
||||
|
|
|
@ -70,6 +70,7 @@ class GetDefaultObjectType @Inject constructor(
|
|||
keys = listOf(
|
||||
Relations.ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.UNIQUE_KEY,
|
||||
Relations.SPACE_ID,
|
||||
Relations.DEFAULT_TEMPLATE_ID
|
||||
|
@ -113,6 +114,7 @@ class GetDefaultObjectType @Inject constructor(
|
|||
keys = listOf(
|
||||
Relations.ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.UNIQUE_KEY,
|
||||
Relations.SPACE_ID,
|
||||
Relations.DEFAULT_TEMPLATE_ID
|
||||
|
|
|
@ -114,6 +114,7 @@ interface ActiveSpaceMemberSubscriptionContainer {
|
|||
Relations.PARTICIPANT_STATUS,
|
||||
Relations.LAYOUT,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.GLOBAL_NAME
|
||||
)
|
||||
|
|
|
@ -45,6 +45,7 @@ class CheckIsUserSpaceMember @Inject constructor(
|
|||
keys = listOf(
|
||||
Relations.ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.SPACE_ID,
|
||||
Relations.PARTICIPANT_PERMISSIONS,
|
||||
Relations.PARTICIPANT_STATUS,
|
||||
|
|
|
@ -44,6 +44,7 @@ class GetSpaceMemberByIdentity @Inject constructor(
|
|||
Relations.PARTICIPANT_PERMISSIONS,
|
||||
Relations.PARTICIPANT_STATUS,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.LAYOUT
|
||||
)
|
||||
|
|
|
@ -117,6 +117,7 @@ interface SpaceViewSubscriptionContainer {
|
|||
Relations.READERS_LIMIT,
|
||||
Relations.WRITERS_LIMIT,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.CREATED_DATE,
|
||||
Relations.CREATOR,
|
||||
Relations.ICON_IMAGE,
|
||||
|
|
|
@ -38,6 +38,9 @@ interface FieldParser {
|
|||
|
||||
fun getObjectName(objectWrapper: ObjectWrapper.Basic): String
|
||||
fun getObjectName(objectWrapper: ObjectWrapper.Type): String
|
||||
fun getObjectPluralName(objectWrapper: ObjectWrapper.Type): String
|
||||
fun getObjectPluralName(objectWrapper: ObjectWrapper.Basic): String
|
||||
fun getObjectNameOrPluralsForTypes(objectWrapper: ObjectWrapper.Basic, ): String
|
||||
fun getObjectTypeIdAndName(
|
||||
objectWrapper: ObjectWrapper.Basic,
|
||||
types: List<ObjectWrapper.Type>
|
||||
|
@ -183,6 +186,32 @@ class FieldParserImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getObjectPluralName(objectWrapper: ObjectWrapper.Type): String {
|
||||
val name = objectWrapper.pluralName?.takeIf { it.isNotEmpty() } ?: objectWrapper.name
|
||||
return if (name.isNullOrBlank()) {
|
||||
stringResourceProvider.getUntitledObjectTitle()
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
override fun getObjectPluralName(objectWrapper: ObjectWrapper.Basic): String {
|
||||
val name = objectWrapper.pluralName?.takeIf { it.isNotEmpty() } ?: objectWrapper.name
|
||||
return if (name.isNullOrBlank()) {
|
||||
stringResourceProvider.getUntitledObjectTitle()
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
override fun getObjectNameOrPluralsForTypes(objectWrapper: ObjectWrapper.Basic): String {
|
||||
return if (objectWrapper.layout == ObjectType.Layout.OBJECT_TYPE) {
|
||||
objectWrapper.pluralName?.takeIf { it.isNotEmpty() } ?: getObjectName(objectWrapper)
|
||||
} else {
|
||||
getObjectName(objectWrapper)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getObjectTypeIdAndName(
|
||||
objectWrapper: ObjectWrapper.Basic,
|
||||
types: List<ObjectWrapper.Type>
|
||||
|
|
|
@ -101,6 +101,7 @@ class ObjectTypesSubscriptionManager (
|
|||
keys = listOf(
|
||||
Relations.ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.IS_HIDDEN,
|
||||
Relations.IS_DELETED,
|
||||
Relations.IS_ARCHIVED,
|
||||
|
|
|
@ -72,6 +72,7 @@ class GetTemplates(
|
|||
Relations.ID,
|
||||
Relations.SPACE_ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.LAYOUT,
|
||||
Relations.ICON_EMOJI,
|
||||
Relations.ICON_NAME,
|
||||
|
|
|
@ -205,7 +205,8 @@ class ObjectTypeViewModel(
|
|||
mapObjectTypeToUi(
|
||||
objType = objType,
|
||||
objectPermissions = objectPermissions,
|
||||
conflictingFields = conflictingFields
|
||||
conflictingFields = conflictingFields,
|
||||
fieldParser = fieldParser
|
||||
)
|
||||
} else {
|
||||
Timber.w(
|
||||
|
@ -307,13 +308,14 @@ class ObjectTypeViewModel(
|
|||
private suspend fun mapObjectTypeToUi(
|
||||
objType: ObjectWrapper.Type,
|
||||
objectPermissions: ObjectPermissions,
|
||||
conflictingFields: List<Id>
|
||||
conflictingFields: List<Id>,
|
||||
fieldParser: FieldParser
|
||||
) {
|
||||
_objTypeState.value = objType
|
||||
_objectTypePermissionsState.value = objectPermissions
|
||||
|
||||
uiTitleState.value = UiTitleState(
|
||||
title = objType.name.orEmpty(),
|
||||
title = fieldParser.getObjectPluralName(objectWrapper = objType),
|
||||
isEditable = objectPermissions.canEditDetails
|
||||
)
|
||||
uiIconState.value = UiIconState(
|
||||
|
|
|
@ -167,6 +167,7 @@ object Flags {
|
|||
const val FLAG_REFRESH: Flag = 0
|
||||
val skipRefreshKeys = listOf(
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.LAST_MODIFIED_DATE,
|
||||
Relations.SNIPPET,
|
||||
Relations.SYNC_DATE,
|
||||
|
|
|
@ -1641,7 +1641,7 @@ class DefaultBlockViewRenderer @Inject constructor(
|
|||
ObjectIcon.None
|
||||
}
|
||||
|
||||
val name = fieldParser.getObjectName(obj)
|
||||
val name = fieldParser.getObjectNameOrPluralsForTypes(obj)
|
||||
|
||||
val description = when (inEditorAppearance.description) {
|
||||
InEditor.Description.NONE -> null
|
||||
|
|
|
@ -1653,6 +1653,7 @@ class HomeScreenViewModel(
|
|||
add(Relations.ID)
|
||||
add(Relations.UNIQUE_KEY)
|
||||
add(Relations.NAME)
|
||||
add(Relations.PLURAL_NAME)
|
||||
},
|
||||
filters = buildList {
|
||||
add(
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.anytypeio.anytype.presentation.search.ObjectSearchConstants
|
|||
import com.anytypeio.anytype.presentation.search.ObjectSearchViewModel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class LinkToObjectViewModel(
|
||||
private val vmParams: VmParams,
|
||||
|
@ -41,6 +42,10 @@ class LinkToObjectViewModel(
|
|||
|
||||
val commands = MutableSharedFlow<Command>(replay = 0)
|
||||
|
||||
init {
|
||||
Timber.d("LinkToObjectViewModel init")
|
||||
}
|
||||
|
||||
override suspend fun getSearchObjectsParams(ignore: Id?) = SearchObjects.Params(
|
||||
space = vmParams.space,
|
||||
limit = SEARCH_LIMIT,
|
||||
|
|
|
@ -22,8 +22,8 @@ suspend fun List<ObjectWrapper.Basic>.toViews(
|
|||
storeOfObjectTypes: StoreOfObjectTypes
|
||||
): List<DefaultObjectView> = map { obj ->
|
||||
obj.toView(
|
||||
urlBuilder,
|
||||
objectTypes,
|
||||
urlBuilder = urlBuilder,
|
||||
objectTypes = objectTypes,
|
||||
fieldParser = fieldParser,
|
||||
storeOfObjectTypes = storeOfObjectTypes
|
||||
)
|
||||
|
@ -43,7 +43,7 @@ suspend fun ObjectWrapper.Basic.toView(
|
|||
val layout = obj.getProperLayout()
|
||||
return DefaultObjectView(
|
||||
id = obj.id,
|
||||
name = fieldParser.getObjectName(obj),
|
||||
name = fieldParser.getObjectNameOrPluralsForTypes(obj),
|
||||
description = obj.description,
|
||||
type = objTypeId,
|
||||
typeName = objTypeName,
|
||||
|
@ -70,7 +70,7 @@ suspend fun List<ObjectWrapper.Basic>.toLinkToView(
|
|||
val layout = obj.getProperLayout()
|
||||
LinkToItemView.Object(
|
||||
id = obj.id,
|
||||
title = fieldParser.getObjectName(obj),
|
||||
title = fieldParser.getObjectNameOrPluralsForTypes(obj),
|
||||
subtitle = getProperTypeName(id = typeUrl, types = objectTypes),
|
||||
type = typeUrl,
|
||||
layout = layout,
|
||||
|
@ -92,7 +92,7 @@ suspend fun ObjectWrapper.Basic.toLinkToObjectView(
|
|||
val layout = this.getProperLayout()
|
||||
return LinkToItemView.LinkedTo.Object(
|
||||
id = this.id,
|
||||
title = fieldParser.getObjectName(this),
|
||||
title = fieldParser.getObjectNameOrPluralsForTypes(this),
|
||||
subtitle = getProperTypeName(id = typeUrl, types = objectTypes),
|
||||
type = typeUrl,
|
||||
layout = layout,
|
||||
|
|
|
@ -102,6 +102,7 @@ class LimitObjectTypeViewModel(
|
|||
keys = listOf(
|
||||
Relations.ID,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.SNIPPET,
|
||||
Relations.DESCRIPTION,
|
||||
Relations.ICON_EMOJI,
|
||||
|
|
|
@ -661,6 +661,7 @@ object ObjectSearchConstants {
|
|||
Relations.TARGET_SPACE_ID,
|
||||
Relations.UNIQUE_KEY,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.ICON_EMOJI,
|
||||
Relations.ICON_NAME,
|
||||
|
@ -707,6 +708,7 @@ object ObjectSearchConstants {
|
|||
Relations.TARGET_SPACE_ID,
|
||||
Relations.IDENTITY_PROFILE_LINK,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.ICON_EMOJI,
|
||||
Relations.ICON_NAME,
|
||||
|
@ -734,6 +736,7 @@ object ObjectSearchConstants {
|
|||
Relations.TARGET_SPACE_ID,
|
||||
Relations.UNIQUE_KEY,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.DESCRIPTION,
|
||||
Relations.ICON_EMOJI,
|
||||
Relations.ICON_NAME,
|
||||
|
@ -977,6 +980,7 @@ object ObjectSearchConstants {
|
|||
Relations.ID,
|
||||
Relations.UNIQUE_KEY,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.DESCRIPTION,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.ICON_EMOJI,
|
||||
|
@ -1288,6 +1292,7 @@ object ObjectSearchConstants {
|
|||
Relations.IDENTITY,
|
||||
Relations.IDENTITY_PROFILE_LINK,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.DESCRIPTION,
|
||||
Relations.ICON_IMAGE,
|
||||
Relations.PARTICIPANT_STATUS,
|
||||
|
|
|
@ -77,6 +77,7 @@ class DefaultObjectTypeTemplatesContainer(
|
|||
Relations.SPACE_ID,
|
||||
Relations.TYPE_UNIQUE_KEY,
|
||||
Relations.NAME,
|
||||
Relations.PLURAL_NAME,
|
||||
Relations.ICON_EMOJI,
|
||||
Relations.ICON_NAME,
|
||||
Relations.ICON_IMAGE,
|
||||
|
|
|
@ -75,7 +75,7 @@ class DataViewListWidgetContainer(
|
|||
name = when(val source = widget.source) {
|
||||
is Widget.Source.Bundled -> WidgetView.Name.Bundled(source = source)
|
||||
is Widget.Source.Default -> WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -89,7 +89,7 @@ class DataViewListWidgetContainer(
|
|||
isExpanded = !isCollapsed,
|
||||
isLoading = true,
|
||||
name = WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(widget.source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(widget.source.obj)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class DataViewListWidgetContainer(
|
|||
name = when(val source = widget.source) {
|
||||
is Widget.Source.Bundled -> WidgetView.Name.Bundled(source = source)
|
||||
is Widget.Source.Default -> WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -145,7 +145,7 @@ class DataViewListWidgetContainer(
|
|||
elements = emptyList(),
|
||||
isExpanded = false,
|
||||
name = WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -270,7 +270,7 @@ class DataViewListWidgetContainer(
|
|||
null
|
||||
},
|
||||
name = WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(obj)
|
||||
)
|
||||
)
|
||||
},
|
||||
|
@ -280,7 +280,7 @@ class DataViewListWidgetContainer(
|
|||
name = when(val source = widget.source) {
|
||||
is Widget.Source.Bundled -> WidgetView.Name.Bundled(source = source)
|
||||
is Widget.Source.Default -> WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -312,7 +312,7 @@ class DataViewListWidgetContainer(
|
|||
objType = storeOfObjectTypes.getTypeOfObject(obj)
|
||||
),
|
||||
name = WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(obj)
|
||||
)
|
||||
)
|
||||
},
|
||||
|
@ -321,7 +321,7 @@ class DataViewListWidgetContainer(
|
|||
name = when(val source = widget.source) {
|
||||
is Widget.Source.Bundled -> WidgetView.Name.Bundled(source = source)
|
||||
is Widget.Source.Default -> WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -340,7 +340,7 @@ class DataViewListWidgetContainer(
|
|||
name = when(val source = widget.source) {
|
||||
is Widget.Source.Bundled -> WidgetView.Name.Bundled(source = source)
|
||||
is Widget.Source.Default -> WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(source.obj)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -352,7 +352,7 @@ class DataViewListWidgetContainer(
|
|||
isExpanded = true,
|
||||
view = null,
|
||||
name = WidgetView.Name.Default(
|
||||
prettyPrintName = fieldParser.getObjectName(widget.source.obj)
|
||||
prettyPrintName = fieldParser.getObjectPluralName(widget.source.obj)
|
||||
)
|
||||
)
|
||||
is Widget.Link, is Widget.Tree -> {
|
||||
|
|
|
@ -5,7 +5,6 @@ import androidx.lifecycle.ViewModelProvider
|
|||
import androidx.lifecycle.asFlow
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.Block.Content.DataView.Filter
|
||||
import com.anytypeio.anytype.core_models.DVFilter
|
||||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
|
@ -50,7 +49,7 @@ class SelectWidgetSourceViewModel(
|
|||
private val analyticSpaceHelperDelegate: AnalyticSpaceHelperDelegate,
|
||||
private val storeOfObjectTypes: StoreOfObjectTypes,
|
||||
private val getSuggestedWidgetTypes: GetSuggestedWidgetTypes,
|
||||
fieldParser: FieldParser
|
||||
private val fieldParser: FieldParser
|
||||
) : ObjectSearchViewModel(
|
||||
vmParams = vmParams,
|
||||
urlBuilder = urlBuilder,
|
||||
|
@ -189,7 +188,7 @@ class SelectWidgetSourceViewModel(
|
|||
suggested.value = types.map { type ->
|
||||
SuggestWidgetObjectType(
|
||||
id = type.id,
|
||||
name = type.name.orEmpty(),
|
||||
name = fieldParser.getObjectPluralName(type),
|
||||
objectIcon = type.objectIcon()
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue