mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2066 Templates | Fix | Default template doesn't apply (#723)
This commit is contained in:
parent
56c5f397bd
commit
b52219a99e
9 changed files with 17 additions and 18 deletions
|
@ -74,7 +74,7 @@ class LibraryFragment : BaseComposeFragment() {
|
|||
onCreateObjectLongClicked = {
|
||||
val dialog = CreateObjectOfTypeFragment().apply {
|
||||
onTypeSelected = {
|
||||
vm.onCreateObjectOfTypeClicked(it.uniqueKey)
|
||||
vm.onCreateObjectOfTypeClicked(it)
|
||||
}
|
||||
}
|
||||
dialog.show(childFragmentManager, "library-create-object-of-type-dialog")
|
||||
|
|
|
@ -57,7 +57,7 @@ class CollectionFragment : BaseComposeFragment() {
|
|||
onCreateObjectLongClicked = {
|
||||
val dialog = CreateObjectOfTypeFragment().apply {
|
||||
onTypeSelected = {
|
||||
vm.onAddClicked(it.uniqueKey)
|
||||
vm.onAddClicked(it)
|
||||
}
|
||||
}
|
||||
dialog.show(childFragmentManager, "fullscreen-widget-create-object-of-type-dialog")
|
||||
|
|
|
@ -134,7 +134,7 @@ fun ScreenContent(
|
|||
backClick = { vm.onPrevClicked() },
|
||||
homeClick = { vm.onHomeClicked() },
|
||||
searchClick = { vm.onSearchClicked() },
|
||||
addDocClick = { vm.onAddClicked() },
|
||||
addDocClick = { vm.onAddClicked(null) },
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onProfileClicked = vm::onProfileClicked,
|
||||
profileIcon = vm.icon.collectAsState().value
|
||||
|
|
|
@ -3232,7 +3232,7 @@ class EditorViewModel(
|
|||
objType: ObjectWrapper.Type?
|
||||
) {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams(objType?.defaultTemplateId)
|
||||
viewModelScope.launch {
|
||||
createObject.async(params = params).fold(
|
||||
onSuccess = { result ->
|
||||
|
|
|
@ -1062,7 +1062,7 @@ class HomeScreenViewModel(
|
|||
Timber.d("onCreateNewObjectClicked, type:[${objType?.uniqueKey}]")
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams(objType?.defaultTemplateId)
|
||||
createObject.stream(params).collect { createObjectResponse ->
|
||||
createObjectResponse.fold(
|
||||
onSuccess = { result ->
|
||||
|
|
|
@ -189,16 +189,14 @@ class LibraryViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onCreateObjectOfTypeClicked(type: Key) {
|
||||
proceedWithCreateDoc(
|
||||
typeKey = TypeKey(type)
|
||||
)
|
||||
fun onCreateObjectOfTypeClicked(objType: ObjectWrapper.Type) {
|
||||
proceedWithCreateDoc(objType)
|
||||
}
|
||||
|
||||
private fun proceedWithCreateDoc(
|
||||
typeKey: TypeKey? = null
|
||||
objType: ObjectWrapper.Type? = null
|
||||
) {
|
||||
val params = typeKey?.key.getCreateObjectParams()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams(objType?.defaultTemplateId)
|
||||
viewModelScope.launch {
|
||||
createObject.async(params).fold(
|
||||
onSuccess = { result -> proceedWithOpeningObject(result.obj) },
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.anytypeio.anytype.presentation.objects
|
||||
|
||||
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.ObjectTypeIds
|
||||
|
@ -96,9 +97,8 @@ fun ObjectState.DataView.isCreateObjectAllowed(objectType: ObjectWrapper.Type? =
|
|||
*
|
||||
* @return [CreateObject.Param] with the necessary parameters for creating an object.
|
||||
*/
|
||||
fun Key?.getCreateObjectParams(): CreateObject.Param {
|
||||
fun Key?.getCreateObjectParams(defaultTemplate: Id?): CreateObject.Param {
|
||||
val key = this
|
||||
val objTypeKey = this
|
||||
val flags = buildList {
|
||||
add(InternalFlags.ShouldEmptyDelete)
|
||||
|
||||
|
@ -106,13 +106,14 @@ fun Key?.getCreateObjectParams(): CreateObject.Param {
|
|||
add(InternalFlags.ShouldSelectTemplate)
|
||||
}
|
||||
|
||||
if (objTypeKey == null) {
|
||||
if (key == null) {
|
||||
add(InternalFlags.ShouldSelectType)
|
||||
}
|
||||
}
|
||||
|
||||
return CreateObject.Param(
|
||||
type = key?.let { TypeKey(it) },
|
||||
internalFlags = flags
|
||||
internalFlags = flags,
|
||||
template = defaultTemplate
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1421,7 +1421,7 @@ class ObjectSetViewModel(
|
|||
Timber.d("onAddNewDocumentClicked, ")
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams(objType?.defaultTemplateId)
|
||||
jobs += viewModelScope.launch {
|
||||
createObject.async(params).fold(
|
||||
onSuccess = { result ->
|
||||
|
|
|
@ -824,7 +824,7 @@ class CollectionViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onAddClicked(type: Key? = null) {
|
||||
fun onAddClicked(objType: ObjectWrapper.Type?) {
|
||||
viewModelScope.sendEvent(
|
||||
analytics = analytics,
|
||||
eventName = EventsDictionary.createObjectCollectionsNavBar,
|
||||
|
@ -832,7 +832,7 @@ class CollectionViewModel(
|
|||
)
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
val params = type.getCreateObjectParams()
|
||||
val params = objType?.uniqueKey.getCreateObjectParams(objType?.defaultTemplateId)
|
||||
viewModelScope.launch {
|
||||
createObject.execute(params).fold(
|
||||
onSuccess = { result ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue