1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3426 All objects | Tabs Type and Relations removed (#2248)

This commit is contained in:
Konstantin Ivanov 2025-04-07 14:42:58 +02:00 committed by GitHub
parent cd8eb2b1e9
commit 95249d4f9d
Signed by: github
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 277 deletions

View file

@ -15,14 +15,12 @@ import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
import com.anytypeio.anytype.domain.misc.LocaleProvider
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
import com.anytypeio.anytype.domain.page.CreateObject
import com.anytypeio.anytype.domain.primitives.FieldParser
import com.anytypeio.anytype.domain.search.SearchObjects
import com.anytypeio.anytype.domain.search.SubscriptionEventChannel
import com.anytypeio.anytype.domain.types.CreateObjectType
import com.anytypeio.anytype.domain.workspace.RemoveObjectsFromWorkspace
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModelFactory
@ -128,14 +126,6 @@ object AllContentModule {
dispatchers: AppCoroutineDispatchers
): SetObjectListIsArchived = SetObjectListIsArchived(repo, dispatchers)
@JvmStatic
@Provides
@PerScreen
fun provideUpdateDetailUseCase(
repository: BlockRepository,
dispatchers: AppCoroutineDispatchers
): SetObjectDetails = SetObjectDetails(repository, dispatchers)
@Provides
@PerScreen
@JvmStatic
@ -144,14 +134,6 @@ object AllContentModule {
dispatchers: AppCoroutineDispatchers
): RemoveObjectsFromWorkspace = RemoveObjectsFromWorkspace(repo, dispatchers)
@Provides
@PerScreen
@JvmStatic
fun createObjectType(
repo: BlockRepository,
dispatchers: AppCoroutineDispatchers
): CreateObjectType = CreateObjectType(repo, dispatchers)
@Module
interface Declarations {
@PerScreen

View file

@ -30,7 +30,7 @@ import com.anytypeio.anytype.presentation.objects.getProperType
//region STATE
@Immutable
enum class AllContentTab {
PAGES, LISTS, MEDIA, BOOKMARKS, FILES, TYPES, RELATIONS
PAGES, LISTS, MEDIA, BOOKMARKS, FILES
}
sealed class AllContentMenuMode {
@ -286,8 +286,6 @@ fun AllContentTab.toAnalyticsTabType(): String {
AllContentTab.MEDIA -> "Media"
AllContentTab.BOOKMARKS -> "Bookmarks"
AllContentTab.FILES -> "Files"
AllContentTab.TYPES -> "Types"
AllContentTab.RELATIONS -> "Relations"
}
}

View file

@ -1,19 +1,14 @@
package com.anytypeio.anytype.feature_allcontent.models
import com.anytypeio.anytype.core_models.DVFilter
import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.DVSort
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.domain.library.StoreSearchParams
import com.anytypeio.anytype.presentation.objects.ObjectsListSort
import com.anytypeio.anytype.presentation.objects.toDVSort
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultKeys
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultKeysObjectType
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultRelationKeys
import com.anytypeio.anytype.presentation.search.buildDeletedFilter
import com.anytypeio.anytype.presentation.search.buildLayoutFilter
import com.anytypeio.anytype.presentation.search.buildLimitedObjectIdsFilter
@ -56,11 +51,6 @@ fun createSubscriptionParams(
limit: Int,
subscriptionId: String
): StoreSearchParams {
val keys = when (activeTab) {
AllContentTab.TYPES -> defaultKeysObjectType
AllContentTab.RELATIONS -> defaultRelationKeys
else -> defaultKeys
}
val (filters, sorts) = activeTab.filtersForSubscribe(
spaces = listOf(spaceId),
activeSort = activeSort,
@ -71,7 +61,7 @@ fun createSubscriptionParams(
space = SpaceId(spaceId),
filters = filters,
sorts = sorts,
keys = keys,
keys = defaultKeys,
limit = limit,
subscription = subscriptionId
)
@ -107,70 +97,6 @@ fun AllContentTab.filtersForSubscribe(
val sorts = listOf(activeSort.toDVSort())
return filters to sorts
}
AllContentTab.TYPES -> {
val filters = buildList {
addAll(buildDeletedFilter())
add(buildSpaceIdFilter(spaces))
if (limitedObjectIds.isNotEmpty()) {
add(buildLimitedObjectIdsFilter(limitedObjectIds = limitedObjectIds))
}
add(
DVFilter(
relation = Relations.LAYOUT,
condition = DVFilterCondition.NOT_EQUAL,
value = ObjectType.Layout.PARTICIPANT.code.toDouble()
)
)
add(
DVFilter(
relation = Relations.LAYOUT,
condition = DVFilterCondition.EQUAL,
value = ObjectType.Layout.OBJECT_TYPE.code.toDouble()
)
)
add(
DVFilter(
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_EQUAL,
value = ObjectTypeIds.CHAT_DERIVED
)
)
add(
DVFilter(
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_EQUAL,
value = ObjectTypeIds.CHAT
)
)
}
val sorts = listOf(activeSort.toDVSort())
return filters to sorts
}
AllContentTab.RELATIONS -> {
val filters = buildList {
addAll(buildDeletedFilter())
add(buildSpaceIdFilter(spaces))
if (limitedObjectIds.isNotEmpty()) {
add(buildLimitedObjectIdsFilter(limitedObjectIds = limitedObjectIds))
}
add(
DVFilter(
relation = Relations.LAYOUT,
condition = DVFilterCondition.EQUAL,
value = ObjectType.Layout.RELATION.code.toDouble()
),
)
add(
DVFilter(
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_EQUAL,
value = ObjectTypeIds.CHAT_DERIVED
)
)
}
val sorts = listOf(activeSort.toDVSort())
return filters to sorts
}
}
}

View file

@ -13,7 +13,6 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_ui.extensions.simpleIcon
import com.anytypeio.anytype.core_utils.ext.orNull
import com.anytypeio.anytype.domain.all_content.RestoreAllContentState
import com.anytypeio.anytype.domain.all_content.UpdateAllContentState
import com.anytypeio.anytype.domain.base.fold
@ -21,13 +20,11 @@ import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
import com.anytypeio.anytype.domain.misc.LocaleProvider
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
import com.anytypeio.anytype.domain.page.CreateObject
import com.anytypeio.anytype.domain.primitives.FieldParser
import com.anytypeio.anytype.domain.search.SearchObjects
import com.anytypeio.anytype.domain.types.CreateObjectType
import com.anytypeio.anytype.domain.workspace.RemoveObjectsFromWorkspace
import com.anytypeio.anytype.feature_allcontent.models.AllContentBottomMenu
import com.anytypeio.anytype.feature_allcontent.models.AllContentMenuMode
@ -46,8 +43,6 @@ import com.anytypeio.anytype.feature_allcontent.models.toAllContentItem
import com.anytypeio.anytype.feature_allcontent.models.toAnalyticsModeType
import com.anytypeio.anytype.feature_allcontent.models.toAnalyticsSortType
import com.anytypeio.anytype.feature_allcontent.models.toAnalyticsTabType
import com.anytypeio.anytype.feature_allcontent.models.toUiContentRelations
import com.anytypeio.anytype.feature_allcontent.models.toUiContentTypes
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel.Command.*
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel.Command.SendToast.*
import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
@ -110,11 +105,9 @@ class AllContentViewModel(
private val localeProvider: LocaleProvider,
private val createObject: CreateObject,
private val setObjectListIsArchived: SetObjectListIsArchived,
private val setObjectDetails: SetObjectDetails,
private val removeObjectsFromWorkspace: RemoveObjectsFromWorkspace,
private val userPermissionProvider: UserPermissionProvider,
private val fieldParser: FieldParser,
private val createObjectType: CreateObjectType
private val fieldParser: FieldParser
) : ViewModel(), AnalyticSpaceHelperDelegate by analyticSpaceHelperDelegate {
private val searchResultIds = MutableStateFlow<List<Id>>(emptyList())
@ -273,7 +266,7 @@ class AllContentViewModel(
Timber.d("Restart subscription: with params: $searchParams")
}
.map { objWrappers ->
handleData(objWrappers, activeSort, activeTab)
handleData(objWrappers, activeSort)
}.catch { e ->
handleError(e)
}
@ -281,8 +274,7 @@ class AllContentViewModel(
private suspend fun handleData(
objWrappers: List<ObjectWrapper.Basic>,
activeSort: ObjectsListSort,
activeTab: AllContentTab
activeSort: ObjectsListSort
): List<UiContentItem> {
canPaginate.value = objWrappers.size == itemsLimit
@ -290,7 +282,6 @@ class AllContentViewModel(
val items = mapToUiContentItems(
objectWrappers = objWrappers,
activeSort = activeSort,
activeTab = activeTab
)
uiContentState.value = if (items.isEmpty()) {
@ -312,77 +303,51 @@ class AllContentViewModel(
private suspend fun mapToUiContentItems(
objectWrappers: List<ObjectWrapper.Basic>,
activeSort: ObjectsListSort,
activeTab: AllContentTab
activeSort: ObjectsListSort
): List<UiContentItem> {
val isOwnerOrEditor = permission.value?.isOwnerOrEditor() == true
return when (activeTab) {
AllContentTab.TYPES -> {
val items = objectWrappers
.map { ObjectWrapper.Type(it.map) }
.toUiContentTypes(
urlBuilder = urlBuilder,
isOwnerOrEditor = isOwnerOrEditor
)
buildList {
if (isOwnerOrEditor) add(UiContentItem.NewType)
addAll(items)
}
val items = objectWrappers.map { obj ->
obj.toAllContentItem(
space = vmParams.spaceId,
urlBuilder = urlBuilder,
isOwnerOrEditor = isOwnerOrEditor,
fieldParser = fieldParser,
objectTypes = storeOfObjectTypes.getAll(),
storeOfObjectTypes = storeOfObjectTypes
)
}
val result = when (activeSort) {
is ObjectsListSort.ByDateCreated -> {
groupItemsByDate(
items = items,
isSortByDateCreated = true,
activeSort = activeSort
)
}
AllContentTab.RELATIONS -> {
val items = objectWrappers.toUiContentRelations(isOwnerOrEditor = isOwnerOrEditor)
buildList {
if (isOwnerOrEditor) add(UiContentItem.NewRelation)
addAll(items)
}
is ObjectsListSort.ByDateUpdated -> {
groupItemsByDate(
items = items,
isSortByDateCreated = false,
activeSort = activeSort
)
}
else -> {
val items = objectWrappers.map { obj ->
obj.toAllContentItem(
space = vmParams.spaceId,
urlBuilder = urlBuilder,
isOwnerOrEditor = isOwnerOrEditor,
fieldParser = fieldParser,
objectTypes = storeOfObjectTypes.getAll(),
storeOfObjectTypes = storeOfObjectTypes
)
}
val result = when (activeSort) {
is ObjectsListSort.ByDateCreated -> {
groupItemsByDate(
items = items,
isSortByDateCreated = true,
activeSort = activeSort
)
}
is ObjectsListSort.ByDateUpdated -> {
groupItemsByDate(
items = items,
isSortByDateCreated = false,
activeSort = activeSort
)
}
is ObjectsListSort.ByName -> {
items
}
is ObjectsListSort.ByDateUsed -> {
items
}
}
if (uiTitleState.value == UiTitleState.OnlyUnlinked) {
buildList {
add(UiContentItem.UnlinkedDescription)
addAll(result)
}
} else {
result
}
is ObjectsListSort.ByName -> {
items
}
is ObjectsListSort.ByDateUsed -> {
items
}
}
return if (uiTitleState.value == UiTitleState.OnlyUnlinked) {
buildList {
add(UiContentItem.UnlinkedDescription)
addAll(result)
}
} else {
result
}
}
@ -516,43 +481,21 @@ class AllContentViewModel(
}
fun AllContentTab.sorts(activeSort: ObjectsListSort): List<MenuSortsItem.Sort> {
return when (this) {
AllContentTab.TYPES -> {
listOf(
MenuSortsItem.Sort(
sort = ObjectsListSort.ByName(isSelected = activeSort is ObjectsListSort.ByName)
),
MenuSortsItem.Sort(
sort = ObjectsListSort.ByDateUsed(isSelected = activeSort is ObjectsListSort.ByDateUsed)
)
)
}
AllContentTab.RELATIONS -> {
listOf(
MenuSortsItem.Sort(
sort = ObjectsListSort.ByName(isSelected = activeSort is ObjectsListSort.ByName)
)
)
}
else -> {
listOf(
MenuSortsItem.Sort(
sort = ObjectsListSort.ByDateUpdated(isSelected = activeSort is ObjectsListSort.ByDateUpdated)
),
MenuSortsItem.Sort(
sort = ObjectsListSort.ByDateCreated(isSelected = activeSort is ObjectsListSort.ByDateCreated)
),
MenuSortsItem.Sort(
sort = ObjectsListSort.ByName(isSelected = activeSort is ObjectsListSort.ByName)
)
)
}
}
return listOf(
MenuSortsItem.Sort(
sort = ObjectsListSort.ByDateUpdated(isSelected = activeSort is ObjectsListSort.ByDateUpdated)
),
MenuSortsItem.Sort(
sort = ObjectsListSort.ByDateCreated(isSelected = activeSort is ObjectsListSort.ByDateCreated)
),
MenuSortsItem.Sort(
sort = ObjectsListSort.ByName(isSelected = activeSort is ObjectsListSort.ByName)
)
)
}
fun AllContentTab.menu(uiTitleState: UiTitleState): List<AllContentMenuMode> {
return when (this) {
AllContentTab.TYPES, AllContentTab.RELATIONS -> listOf()
else -> {
listOf(
AllContentMenuMode.AllContent(isSelected = uiTitleState == UiTitleState.AllContent),
@ -562,25 +505,8 @@ class AllContentViewModel(
}
}
private fun AllContentTab.updateInitialState() {
return when (this) {
AllContentTab.TYPES -> {
sortState.value = ObjectsListSort.ByName()
userInput.value = DEFAULT_QUERY
uiTitleState.value = UiTitleState.AllContent
}
AllContentTab.RELATIONS -> {
sortState.value = ObjectsListSort.ByName()
userInput.value = DEFAULT_QUERY
uiTitleState.value = UiTitleState.AllContent
}
else -> {}
}
}
fun onTabClicked(tab: AllContentTab) {
Timber.d("onTabClicked: $tab")
tab.updateInitialState()
shouldScrollToTopItems = true
resetLimit()
uiItemsState.value = UiItemsState.Empty
@ -642,11 +568,6 @@ class AllContentViewModel(
}
private fun proceedWithSortSaving(activeTab: UiTabsState, sort: ObjectsListSort) {
if (activeTab.selectedTab == AllContentTab.TYPES
|| activeTab.selectedTab == AllContentTab.RELATIONS
) {
return
}
viewModelScope.launch {
val params = UpdateAllContentState.Params(
spaceId = vmParams.spaceId,
@ -986,27 +907,6 @@ class AllContentViewModel(
)
//region Types and Relations action
fun updateObject(id: String, name: String, icon: String?) {
viewModelScope.launch {
setObjectDetails.execute(
SetObjectDetails.Params(
ctx = id,
details = mapOf(
Relations.NAME to name,
Relations.ICON_EMOJI to icon.orNull(),
)
)
).fold(
onFailure = {
Timber.e(it, "Error while updating object details")
},
onSuccess = {
// do nothing
}
)
}
}
fun uninstallObject(id: Id, tab: AllContentTab, name: String) {
viewModelScope.launch {
removeObjectsFromWorkspace.execute(
@ -1017,17 +917,7 @@ class AllContentViewModel(
commands.emit(Command.SendToast.Error("Error while uninstalling object"))
},
onSuccess = {
when (tab) {
AllContentTab.TYPES -> {
commands.emit(Command.SendToast.TypeRemoved(name))
}
AllContentTab.RELATIONS -> {
commands.emit(Command.SendToast.RelationRemoved(name))
}
else -> {
//do nothing
}
}
//do nothing
}
)
}
@ -1074,8 +964,4 @@ class AllContentViewModel(
val DEFAULT_INITIAL_TAB = AllContentTab.PAGES
val DEFAULT_QUERY = ""
}
enum class LibraryItem {
TYPE, RELATION
}
}

View file

@ -9,13 +9,11 @@ import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
import com.anytypeio.anytype.domain.misc.LocaleProvider
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
import com.anytypeio.anytype.domain.page.CreateObject
import com.anytypeio.anytype.domain.primitives.FieldParser
import com.anytypeio.anytype.domain.search.SearchObjects
import com.anytypeio.anytype.domain.types.CreateObjectType
import com.anytypeio.anytype.domain.workspace.RemoveObjectsFromWorkspace
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel.VmParams
import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
@ -34,11 +32,9 @@ class AllContentViewModelFactory @Inject constructor(
private val localeProvider: LocaleProvider,
private val createObject: CreateObject,
private val setObjectListIsArchived: SetObjectListIsArchived,
private val setObjectDetails: SetObjectDetails,
private val removeObjectsFromWorkspace: RemoveObjectsFromWorkspace,
private val userPermissionProvider: UserPermissionProvider,
private val fieldParser: FieldParser,
private val createObjectType: CreateObjectType
private val fieldParser: FieldParser
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T =
@ -55,10 +51,8 @@ class AllContentViewModelFactory @Inject constructor(
localeProvider = localeProvider,
createObject = createObject,
setObjectListIsArchived = setObjectListIsArchived,
setObjectDetails = setObjectDetails,
removeObjectsFromWorkspace = removeObjectsFromWorkspace,
userPermissionProvider = userPermissionProvider,
fieldParser = fieldParser,
createObjectType = createObjectType
fieldParser = fieldParser
) as T
}

View file

@ -600,7 +600,6 @@ fun PreviewMainScreen() {
uiTabsState = UiTabsState(
tabs = listOf(
AllContentTab.PAGES,
AllContentTab.TYPES,
AllContentTab.LISTS
), selectedTab = AllContentTab.LISTS
),

View file

@ -258,9 +258,7 @@ private fun getTabText(tab: AllContentTab): String {
AllContentTab.FILES -> stringResource(id = R.string.all_content_title_tab_files)
AllContentTab.MEDIA -> stringResource(id = R.string.all_content_title_tab_media)
AllContentTab.BOOKMARKS -> stringResource(id = R.string.all_content_title_tab_bookmarks)
AllContentTab.TYPES -> stringResource(id = R.string.all_content_title_tab_objetc_types)
AllContentTab.LISTS -> stringResource(id = R.string.all_content_title_tab_lists)
AllContentTab.RELATIONS -> stringResource(id = R.string.all_content_title_tab_relations)
}
}
@ -273,9 +271,7 @@ private fun AllContentTabsPreview() {
AllContentTab.PAGES,
AllContentTab.FILES,
AllContentTab.MEDIA,
AllContentTab.BOOKMARKS,
AllContentTab.TYPES,
AllContentTab.RELATIONS
AllContentTab.BOOKMARKS
),
selectedTab = AllContentTab.MEDIA
),