mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2052 Create objets | Fix | Navigation to sets (#703)
This commit is contained in:
parent
ba76dc3535
commit
ecb75efbe7
10 changed files with 154 additions and 102 deletions
|
@ -614,7 +614,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
.onEach {
|
||||
val dialog = CreateObjectOfTypeFragment().apply {
|
||||
onTypeSelected = {
|
||||
vm.onAddNewDocumentClicked(it.uniqueKey)
|
||||
vm.onAddNewDocumentClicked(it)
|
||||
}
|
||||
}
|
||||
dialog.show(childFragmentManager, "editor-create-object-of-type-dialog")
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.anytypeio.anytype.ui.relations.REQUEST_UNINSTALL_RELATION_ARG_ID
|
|||
import com.anytypeio.anytype.ui.relations.REQUEST_UNINSTALL_RELATION_ARG_NAME
|
||||
import com.anytypeio.anytype.ui.relations.RelationCreateFromScratchForObjectFragment
|
||||
import com.anytypeio.anytype.ui.relations.RelationEditFragment
|
||||
import com.anytypeio.anytype.ui.sets.ObjectSetFragment
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
import com.anytypeio.anytype.ui.spaces.SelectSpaceFragment
|
||||
import com.anytypeio.anytype.ui.types.create.CreateObjectTypeFragment
|
||||
|
@ -139,7 +140,7 @@ class LibraryFragment : BaseComposeFragment() {
|
|||
R.id.pageSearchFragment
|
||||
)
|
||||
}
|
||||
is LibraryViewModel.Navigation.CreateDoc -> {
|
||||
is LibraryViewModel.Navigation.OpenEditor -> {
|
||||
findNavController().safeNavigate(
|
||||
R.id.libraryFragment,
|
||||
R.id.objectNavigation,
|
||||
|
@ -154,6 +155,16 @@ class LibraryFragment : BaseComposeFragment() {
|
|||
args = SelectSpaceFragment.args(exitHomeWhenSpaceIsSelected = true)
|
||||
)
|
||||
}
|
||||
|
||||
is LibraryViewModel.Navigation.OpenSetOrCollection -> {
|
||||
findNavController().safeNavigate(
|
||||
R.id.libraryFragment,
|
||||
R.id.dataViewNavigation,
|
||||
bundleOf(
|
||||
ObjectSetFragment.CONTEXT_ID_KEY to it.id
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ open class ObjectSetFragment :
|
|||
.onEach {
|
||||
val dialog = CreateObjectOfTypeFragment().apply {
|
||||
onTypeSelected = {
|
||||
vm.onAddNewDocumentClicked(it.uniqueKey)
|
||||
vm.onAddNewDocumentClicked(it)
|
||||
}
|
||||
}
|
||||
dialog.show(childFragmentManager, "set-create-object-of-type-dialog")
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.anytypeio.anytype.domain.page
|
|||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
|
@ -66,7 +67,8 @@ class CreateObject @Inject constructor(
|
|||
objectId = result.id,
|
||||
event = result.event,
|
||||
appliedTemplate = template,
|
||||
typeKey = typeKey
|
||||
typeKey = typeKey,
|
||||
obj = ObjectWrapper.Basic(result.details)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -81,6 +83,7 @@ class CreateObject @Inject constructor(
|
|||
val objectId: Id,
|
||||
val event: Payload,
|
||||
val appliedTemplate: String? = null,
|
||||
val typeKey: TypeKey
|
||||
val typeKey: TypeKey,
|
||||
val obj: ObjectWrapper.Basic
|
||||
)
|
||||
}
|
|
@ -220,6 +220,8 @@ import com.anytypeio.anytype.presentation.extension.sendAnalyticsStyleMenuEvent
|
|||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsUpdateTextMarkupEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendHideKeyboardEvent
|
||||
import com.anytypeio.anytype.presentation.home.HomeScreenViewModel.Companion.HOME_SCREEN_PROFILE_OBJECT_SUBSCRIPTION
|
||||
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
|
||||
import com.anytypeio.anytype.presentation.home.navigation
|
||||
import com.anytypeio.anytype.presentation.mapper.mark
|
||||
import com.anytypeio.anytype.presentation.mapper.style
|
||||
import com.anytypeio.anytype.presentation.navigation.AppNavigation
|
||||
|
@ -228,6 +230,7 @@ import com.anytypeio.anytype.presentation.navigation.SupportNavigation
|
|||
import com.anytypeio.anytype.presentation.objects.ObjectIcon
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectTypeView
|
||||
import com.anytypeio.anytype.presentation.objects.SupportedLayouts
|
||||
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
|
||||
import com.anytypeio.anytype.presentation.objects.getObjectTypeViewsForSBPage
|
||||
import com.anytypeio.anytype.presentation.objects.getProperType
|
||||
import com.anytypeio.anytype.presentation.objects.isTemplatesAllowed
|
||||
|
@ -3202,18 +3205,9 @@ class EditorViewModel(
|
|||
}
|
||||
|
||||
|
||||
fun onAddNewDocumentClicked(type: Key? = null) {
|
||||
Timber.d("onAddNewDocumentClicked, ")
|
||||
proceedWithCreatingNewObject(
|
||||
internalFlags = buildList {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
if (type.isNullOrEmpty()) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
},
|
||||
typeKey = type?.let { TypeKey(it) }
|
||||
)
|
||||
fun onAddNewDocumentClicked(objType: ObjectWrapper.Type? = null) {
|
||||
Timber.d("onAddNewDocumentClicked, objType:[$objType]")
|
||||
proceedWithCreatingNewObject(objType)
|
||||
}
|
||||
|
||||
fun onProceedWithApplyingTemplateByObjectId(template: Id?) {
|
||||
|
@ -3235,29 +3229,24 @@ class EditorViewModel(
|
|||
}
|
||||
|
||||
private fun proceedWithCreatingNewObject(
|
||||
internalFlags: List<InternalFlags> = emptyList(),
|
||||
typeKey: TypeKey? = null
|
||||
objType: ObjectWrapper.Type?
|
||||
) {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
viewModelScope.launch {
|
||||
val params = CreateObject.Param(
|
||||
internalFlags = internalFlags,
|
||||
type = typeKey
|
||||
createObject.async(params = params).fold(
|
||||
onSuccess = { result ->
|
||||
sendAnalyticsObjectCreateEvent(
|
||||
analytics = analytics,
|
||||
type = result.typeKey.key,
|
||||
storeOfObjectTypes = storeOfObjectTypes,
|
||||
route = EventsDictionary.Routes.objPowerTool,
|
||||
startTime = startTime
|
||||
)
|
||||
proceedWithCloseCurrentAndOpenObject(result.obj)
|
||||
},
|
||||
onFailure = { e -> Timber.e(e, "Error while creating a new object") }
|
||||
)
|
||||
createObject.async(params = params)
|
||||
.fold(
|
||||
onSuccess = { result ->
|
||||
sendAnalyticsObjectCreateEvent(
|
||||
analytics = analytics,
|
||||
type = result.typeKey.key,
|
||||
storeOfObjectTypes = storeOfObjectTypes,
|
||||
route = EventsDictionary.Routes.objPowerTool,
|
||||
startTime = startTime
|
||||
)
|
||||
proceedWithOpeningObject(result.objectId)
|
||||
},
|
||||
onFailure = { e -> Timber.e(e, "Error while creating a new object") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4244,6 +4233,32 @@ class EditorViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun proceedWithCloseCurrentAndOpenObject(obj: ObjectWrapper.Basic) {
|
||||
jobs += viewModelScope.launch {
|
||||
closePage.async(context).fold(
|
||||
onSuccess = { proceedWithOpeningObject(obj) },
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while closing object: $context")
|
||||
proceedWithOpeningObject(obj)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedWithOpeningObject(obj: ObjectWrapper.Basic) {
|
||||
when (val navigation = obj.navigation()) {
|
||||
is OpenObjectNavigation.OpenDataView -> {
|
||||
navigate(EventWrapper(AppNavigation.Command.OpenSetOrCollection(navigation.target)))
|
||||
}
|
||||
is OpenObjectNavigation.OpenEditor -> {
|
||||
navigate(EventWrapper(AppNavigation.Command.OpenObject(navigation.target)))
|
||||
}
|
||||
is OpenObjectNavigation.UnexpectedLayoutError -> {
|
||||
sendToast("Unexpected layout: ${navigation.layout}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun proceedWithOpeningDataViewObject(target: Id, isPopUpToDashboard: Boolean = false) {
|
||||
viewModelScope.launch {
|
||||
closePage.async(context).fold(
|
||||
|
|
|
@ -11,8 +11,6 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
|
||||
import com.anytypeio.anytype.core_models.ObjectView
|
||||
|
@ -66,6 +64,7 @@ import com.anytypeio.anytype.presentation.extension.sendReorderWidgetEvent
|
|||
import com.anytypeio.anytype.presentation.extension.sendSelectHomeTabEvent
|
||||
import com.anytypeio.anytype.presentation.home.Command.ChangeWidgetType.Companion.UNDEFINED_LAYOUT_CODE
|
||||
import com.anytypeio.anytype.presentation.navigation.NavigationViewModel
|
||||
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
||||
import com.anytypeio.anytype.presentation.profile.profileIcon
|
||||
import com.anytypeio.anytype.presentation.search.Subscriptions
|
||||
|
@ -1063,16 +1062,7 @@ class HomeScreenViewModel(
|
|||
Timber.d("onCreateNewObjectClicked, type:[${objType?.uniqueKey}]")
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
val params = CreateObject.Param(
|
||||
internalFlags = buildList {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
if (objType == null) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
},
|
||||
type = if (objType != null) TypeKey(key = objType.uniqueKey) else null
|
||||
)
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
createObject.stream(params).collect { createObjectResponse ->
|
||||
createObjectResponse.fold(
|
||||
onSuccess = { result ->
|
||||
|
@ -1093,11 +1083,7 @@ class HomeScreenViewModel(
|
|||
route = EventsDictionary.Routes.longTap
|
||||
)
|
||||
}
|
||||
if (objType?.uniqueKey == ObjectTypeUniqueKeys.SET || objType?.uniqueKey == ObjectTypeUniqueKeys.COLLECTION) {
|
||||
navigate(Navigation.OpenSet(result.objectId))
|
||||
} else {
|
||||
navigate(Navigation.OpenObject(result.objectId))
|
||||
}
|
||||
proceedWithOpeningObject(result.obj)
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while creating object")
|
||||
|
|
|
@ -10,8 +10,8 @@ import com.anytypeio.anytype.analytics.base.EventsDictionary.libraryView
|
|||
import com.anytypeio.anytype.analytics.base.sendEvent
|
||||
import com.anytypeio.anytype.analytics.props.Props
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.primitives.TypeKey
|
||||
import com.anytypeio.anytype.core_utils.ext.allUniqueBy
|
||||
|
@ -28,11 +28,14 @@ import com.anytypeio.anytype.domain.workspace.RemoveObjectsFromWorkspace
|
|||
import com.anytypeio.anytype.domain.workspace.SpaceManager
|
||||
import com.anytypeio.anytype.presentation.BuildConfig
|
||||
import com.anytypeio.anytype.presentation.home.HomeScreenViewModel.Companion.HOME_SCREEN_PROFILE_OBJECT_SUBSCRIPTION
|
||||
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
|
||||
import com.anytypeio.anytype.presentation.home.navigation
|
||||
import com.anytypeio.anytype.presentation.library.delegates.LibraryRelationsDelegate
|
||||
import com.anytypeio.anytype.presentation.library.delegates.LibraryTypesDelegate
|
||||
import com.anytypeio.anytype.presentation.library.delegates.MyRelationsDelegate
|
||||
import com.anytypeio.anytype.presentation.library.delegates.MyTypesDelegate
|
||||
import com.anytypeio.anytype.presentation.navigation.NavigationViewModel
|
||||
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
||||
import com.anytypeio.anytype.presentation.profile.profileIcon
|
||||
import javax.inject.Inject
|
||||
|
@ -195,27 +198,29 @@ class LibraryViewModel(
|
|||
private fun proceedWithCreateDoc(
|
||||
typeKey: TypeKey? = null
|
||||
) {
|
||||
val params = typeKey?.key.getCreateObjectParams()
|
||||
viewModelScope.launch {
|
||||
createObject.async(
|
||||
CreateObject.Param(
|
||||
type = typeKey,
|
||||
internalFlags = buildList {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
if (typeKey == null) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
}
|
||||
)
|
||||
).fold(
|
||||
onSuccess = { result ->
|
||||
navigate(Navigation.CreateDoc(result.objectId))
|
||||
},
|
||||
onFailure = { e -> Timber.e(e, "Error while creating a new page") }
|
||||
createObject.async(params).fold(
|
||||
onSuccess = { result -> proceedWithOpeningObject(result.obj) },
|
||||
onFailure = { e -> Timber.e(e, "Error while creating a new object") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedWithOpeningObject(obj: ObjectWrapper.Basic) {
|
||||
when (val navigation = obj.navigation()) {
|
||||
is OpenObjectNavigation.OpenDataView -> {
|
||||
navigate(Navigation.OpenSetOrCollection(navigation.target))
|
||||
}
|
||||
is OpenObjectNavigation.OpenEditor -> {
|
||||
navigate(Navigation.OpenEditor(navigation.target))
|
||||
}
|
||||
is OpenObjectNavigation.UnexpectedLayoutError -> {
|
||||
sendToast("Unexpected layout: ${navigation.layout}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedQueryEvent(event: LibraryEvent.Query) {
|
||||
when (event) {
|
||||
is LibraryEvent.Query.MyTypes -> {
|
||||
|
@ -524,7 +529,9 @@ class LibraryViewModel(
|
|||
|
||||
class Search : Navigation()
|
||||
|
||||
class CreateDoc(val id: Id) : Navigation()
|
||||
class OpenEditor(val id: Id) : Navigation()
|
||||
|
||||
class OpenSetOrCollection(val id: Id) : Navigation()
|
||||
}
|
||||
|
||||
sealed class Effect {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.anytypeio.anytype.presentation.objects
|
||||
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.BOOKMARK
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.COLLECTION
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.SET
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.primitives.TypeKey
|
||||
import com.anytypeio.anytype.core_models.restrictions.DataViewRestriction
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
import com.anytypeio.anytype.presentation.mapper.toObjectTypeView
|
||||
import com.anytypeio.anytype.presentation.objects.SupportedLayouts.editorLayouts
|
||||
import com.anytypeio.anytype.presentation.objects.SupportedLayouts.fileLayouts
|
||||
|
@ -85,4 +89,30 @@ fun ObjectState.DataView.isCreateObjectAllowed(objectType: ObjectWrapper.Type? =
|
|||
|
||||
val skipLayouts = fileLayouts + systemLayouts
|
||||
return !skipLayouts.contains(objectType?.recommendedLayout)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the parameters for creating an object from + button(single click).
|
||||
*
|
||||
* @return [CreateObject.Param] with the necessary parameters for creating an object.
|
||||
*/
|
||||
fun Key?.getCreateObjectParams(): CreateObject.Param {
|
||||
val key = this
|
||||
val objTypeKey = this
|
||||
val flags = buildList {
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
|
||||
if (key != SET && key != COLLECTION) {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
}
|
||||
|
||||
if (objTypeKey == null) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
}
|
||||
|
||||
return CreateObject.Param(
|
||||
type = key?.let { TypeKey(it) },
|
||||
internalFlags = flags
|
||||
)
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ import com.anytypeio.anytype.presentation.mapper.toTemplateObjectTypeViewItems
|
|||
import com.anytypeio.anytype.presentation.navigation.AppNavigation
|
||||
import com.anytypeio.anytype.presentation.navigation.SupportNavigation
|
||||
import com.anytypeio.anytype.presentation.objects.SupportedLayouts
|
||||
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
|
||||
import com.anytypeio.anytype.presentation.objects.isCreateObjectAllowed
|
||||
import com.anytypeio.anytype.presentation.objects.isTemplatesAllowed
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
||||
|
@ -1307,6 +1308,7 @@ class ObjectSetViewModel(
|
|||
//region NAVIGATION
|
||||
|
||||
private suspend fun proceedWithOpeningObject(target: Id, layout: ObjectType.Layout? = null) {
|
||||
Timber.d("proceedWithOpeningObject, target:[$target], layout:[$layout]")
|
||||
if (target == context) {
|
||||
toast("You are already here")
|
||||
Timber.d("proceedWithOpeningObject, target == context")
|
||||
|
@ -1434,25 +1436,18 @@ class ObjectSetViewModel(
|
|||
proceedWithExiting()
|
||||
}
|
||||
|
||||
fun onAddNewDocumentClicked(type: Key? = null) {
|
||||
fun onAddNewDocumentClicked(objType: ObjectWrapper.Type? = null) {
|
||||
Timber.d("onAddNewDocumentClicked, ")
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
jobs += viewModelScope.launch {
|
||||
createObject.async(
|
||||
CreateObject.Param(
|
||||
type = type?.let { TypeKey(it) },
|
||||
internalFlags = buildList {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
if (type.isNullOrBlank()) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
}
|
||||
)
|
||||
).fold(
|
||||
createObject.async(params).fold(
|
||||
onSuccess = { result ->
|
||||
proceedWithOpeningObject(result.objectId)
|
||||
proceedWithOpeningObject(
|
||||
target = result.objectId,
|
||||
layout = result.obj.layout
|
||||
)
|
||||
sendAnalyticsObjectCreateEvent(
|
||||
analytics = analytics,
|
||||
startTime = startTime,
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.anytypeio.anytype.analytics.base.sendEvent
|
|||
import com.anytypeio.anytype.analytics.props.Props
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
|
@ -18,7 +17,6 @@ import com.anytypeio.anytype.core_models.Payload
|
|||
import com.anytypeio.anytype.core_models.Position
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.ext.process
|
||||
import com.anytypeio.anytype.core_models.primitives.TypeKey
|
||||
import com.anytypeio.anytype.core_utils.ext.cancel
|
||||
import com.anytypeio.anytype.core_utils.ext.replace
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
|
@ -45,8 +43,11 @@ import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectCreateEve
|
|||
import com.anytypeio.anytype.presentation.extension.sendDeletionWarning
|
||||
import com.anytypeio.anytype.presentation.extension.sendScreenHomeEvent
|
||||
import com.anytypeio.anytype.presentation.home.HomeScreenViewModel.Companion.HOME_SCREEN_PROFILE_OBJECT_SUBSCRIPTION
|
||||
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
|
||||
import com.anytypeio.anytype.presentation.home.navigation
|
||||
import com.anytypeio.anytype.presentation.navigation.DefaultObjectView
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectAction
|
||||
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
|
||||
import com.anytypeio.anytype.presentation.objects.getProperName
|
||||
import com.anytypeio.anytype.presentation.objects.mapFileObjectToView
|
||||
import com.anytypeio.anytype.presentation.objects.toViews
|
||||
|
@ -831,19 +832,9 @@ class CollectionViewModel(
|
|||
)
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
launch {
|
||||
createObject.execute(
|
||||
CreateObject.Param(
|
||||
type = type?.let { TypeKey(it) },
|
||||
internalFlags = buildList {
|
||||
add(InternalFlags.ShouldSelectTemplate)
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
if (type.isNullOrEmpty()) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
}
|
||||
)
|
||||
).fold(
|
||||
val params = type.getCreateObjectParams()
|
||||
viewModelScope.launch {
|
||||
createObject.execute(params).fold(
|
||||
onSuccess = { result ->
|
||||
sendAnalyticsObjectCreateEvent(
|
||||
analytics = analytics,
|
||||
|
@ -852,13 +843,27 @@ class CollectionViewModel(
|
|||
route = EventsDictionary.Routes.objCreateHome,
|
||||
startTime = startTime
|
||||
)
|
||||
commands.emit(Command.LaunchDocument(result.objectId))
|
||||
proceedWithOpeningObject(result.obj)
|
||||
},
|
||||
onFailure = { e -> Timber.e(e, "Error while creating a new page") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun proceedWithOpeningObject(obj: ObjectWrapper.Basic) {
|
||||
when (val navigation = obj.navigation()) {
|
||||
is OpenObjectNavigation.OpenDataView -> {
|
||||
commands.emit(Command.LaunchObjectSet(navigation.target))
|
||||
}
|
||||
is OpenObjectNavigation.OpenEditor -> {
|
||||
commands.emit(Command.LaunchDocument(navigation.target))
|
||||
}
|
||||
is OpenObjectNavigation.UnexpectedLayoutError -> {
|
||||
toasts.emit("Unexpected layout: ${navigation.layout}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
private suspend fun filesSubscriptionFlow(): Flow<List<CollectionView>> {
|
||||
return combine(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue