mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-735 Widgets | Enhancement | Foundations + basic API (#2792)
This commit is contained in:
parent
39faff3e2a
commit
8d38f94b13
26 changed files with 441 additions and 15 deletions
|
@ -34,7 +34,8 @@ fun Rpc.Account.Create.Response.toAccountSetup() : AccountSetup {
|
|||
home = info.homeObjectId,
|
||||
profile = info.profileObjectId,
|
||||
gateway = info.gatewayUrl,
|
||||
workspace = info.accountSpaceId
|
||||
workspace = info.accountSpaceId,
|
||||
widgets = info.widgetsId
|
||||
),
|
||||
status = status.core()
|
||||
)
|
||||
|
@ -67,7 +68,8 @@ fun Rpc.Account.Select.Response.toAccountSetup(): AccountSetup {
|
|||
home = info.homeObjectId,
|
||||
profile = info.profileObjectId,
|
||||
gateway = info.gatewayUrl,
|
||||
workspace = info.accountSpaceId
|
||||
workspace = info.accountSpaceId,
|
||||
widgets = info.widgetsId
|
||||
),
|
||||
status = status.core()
|
||||
)
|
||||
|
|
|
@ -663,4 +663,9 @@ class BlockMiddleware(
|
|||
override suspend fun createBlockLinkWithObject(
|
||||
command: Command.CreateBlockLinkWithObject
|
||||
): CreateBlockLinkWithObjectResult = middleware.blockLinkCreateWithObject(command)
|
||||
|
||||
override suspend fun createWidget(ctx: Id, source: Id): Payload = middleware.createWidgetBlock(
|
||||
ctx = ctx,
|
||||
source = source
|
||||
)
|
||||
}
|
|
@ -1810,6 +1810,26 @@ class Middleware(
|
|||
return response.objectIds
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun createWidgetBlock(
|
||||
ctx: Id,
|
||||
source: Id
|
||||
): Payload {
|
||||
val request = Rpc.Block.CreateWidget.Request(
|
||||
contextId = ctx,
|
||||
widgetLayout = Block.Content.Widget.Layout.Tree,
|
||||
block = Block(
|
||||
link = Block.Content.Link(
|
||||
targetBlockId = source
|
||||
)
|
||||
)
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.blockCreateWidget(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.event.toPayload()
|
||||
}
|
||||
|
||||
private fun logRequest(any: Any) {
|
||||
logger.logRequest(any)
|
||||
}
|
||||
|
|
|
@ -56,3 +56,6 @@ typealias MRelationOption = anytype.model.Relation.Option
|
|||
typealias MObjectRestriction = anytype.model.Restrictions.ObjectRestriction
|
||||
typealias MDVRestrictions = anytype.model.Restrictions.DataviewRestrictions
|
||||
typealias MDVRestriction = anytype.model.Restrictions.DataviewRestriction
|
||||
|
||||
typealias MWidget = anytype.model.Block.Content.Widget
|
||||
typealias MWidgetLayout = anytype.model.Block.Content.Widget.Layout
|
||||
|
|
|
@ -23,7 +23,7 @@ fun ResponseEvent?.toPayload(): Payload {
|
|||
)
|
||||
}
|
||||
|
||||
fun MObjectView.toPayload() : Payload {
|
||||
fun MObjectView.toPayload(): Payload {
|
||||
val type = type.toCoreModel()
|
||||
return Payload(
|
||||
context = rootId,
|
||||
|
@ -48,7 +48,7 @@ fun MObjectView.toPayload() : Payload {
|
|||
)
|
||||
}
|
||||
|
||||
fun MObjectView.toCore() : ObjectView {
|
||||
fun MObjectView.toCore(): ObjectView {
|
||||
val type = type.toCoreModel()
|
||||
return ObjectView(
|
||||
root = rootId,
|
||||
|
@ -211,6 +211,15 @@ fun List<MBlock>.toCoreModels(
|
|||
backgroundColor = block.backgroundColor
|
||||
)
|
||||
}
|
||||
block.widget != null -> {
|
||||
Block(
|
||||
id = block.id,
|
||||
fields = block.toCoreModelsFields(),
|
||||
children = block.childrenIds,
|
||||
content = block.toCoreWidget(),
|
||||
backgroundColor = block.backgroundColor
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
Block(
|
||||
id = block.id,
|
||||
|
@ -330,7 +339,7 @@ fun MBlock.toCoreModelsBookmark(): Block.Content.Bookmark {
|
|||
)
|
||||
}
|
||||
|
||||
fun MBookmarkState.toCoreModelsBookmarkState() : Block.Content.Bookmark.State {
|
||||
fun MBookmarkState.toCoreModelsBookmarkState(): Block.Content.Bookmark.State {
|
||||
return when (this) {
|
||||
MBookmarkState.Empty -> Block.Content.Bookmark.State.EMPTY
|
||||
MBookmarkState.Fetching -> Block.Content.Bookmark.State.FETCHING
|
||||
|
@ -363,6 +372,16 @@ fun MBlock.toCoreModelsTableRowBlock(): Block.Content.TableRow {
|
|||
)
|
||||
}
|
||||
|
||||
fun MBlock.toCoreWidget(): Block.Content.Widget {
|
||||
val content = checkNotNull(widget)
|
||||
return Block.Content.Widget(
|
||||
layout = when (content.layout) {
|
||||
MWidgetLayout.Link -> Block.Content.Widget.Layout.LINK
|
||||
MWidgetLayout.Tree -> Block.Content.Widget.Layout.TREE
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun MBFileState.toCoreModels(): Block.Content.File.State = when (this) {
|
||||
MBFileState.Empty -> Block.Content.File.State.EMPTY
|
||||
MBFileState.Uploading -> Block.Content.File.State.UPLOADING
|
||||
|
|
|
@ -370,6 +370,13 @@ interface MiddlewareService {
|
|||
|
||||
//endregion
|
||||
|
||||
//region WIDGETS commands
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun blockCreateWidget(request: Rpc.Block.CreateWidget.Request): Rpc.Block.CreateWidget.Response
|
||||
|
||||
//endregion
|
||||
|
||||
//region WORKSPACE
|
||||
|
||||
@Throws(Exception::class)
|
||||
|
|
|
@ -149,6 +149,19 @@ class MiddlewareServiceImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun blockCreateWidget(request: Rpc.Block.CreateWidget.Request): Rpc.Block.CreateWidget.Response {
|
||||
val encoded = Service.blockCreateWidget(
|
||||
Rpc.Block.CreateWidget.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.Block.CreateWidget.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.Block.CreateWidget.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun blockDataViewActiveSet(request: Rpc.BlockDataview.View.SetActive.Request): Rpc.BlockDataview.View.SetActive.Response {
|
||||
val encoded = Service.blockDataviewViewSetActive(
|
||||
Rpc.BlockDataview.View.SetActive.Request.ADAPTER.encode(request)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue