Remove NodeBuilder to ensure that Params and Callback are always provided.

This commit is contained in:
Benoit Marty 2025-10-30 11:37:59 +01:00 committed by Benoit Marty
parent be03c50aaf
commit 02dc71c4c3
115 changed files with 954 additions and 1174 deletions

View file

@ -9,7 +9,6 @@ package io.element.android.features.userprofile.impl
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import dev.zacsweers.metro.AppScope
import dev.zacsweers.metro.ContributesBinding
import io.element.android.features.userprofile.api.UserProfileEntryPoint
@ -17,23 +16,15 @@ import io.element.android.libraries.architecture.createNode
@ContributesBinding(AppScope::class)
class DefaultUserProfileEntryPoint : UserProfileEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext): UserProfileEntryPoint.NodeBuilder {
return object : UserProfileEntryPoint.NodeBuilder {
val plugins = ArrayList<Plugin>()
override fun params(params: UserProfileEntryPoint.Params): UserProfileEntryPoint.NodeBuilder {
plugins += params
return this
}
override fun callback(callback: UserProfileEntryPoint.Callback): UserProfileEntryPoint.NodeBuilder {
plugins += callback
return this
}
override fun build(): Node {
return parentNode.createNode<UserProfileFlowNode>(buildContext, plugins)
}
}
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
params: UserProfileEntryPoint.Params,
callback: UserProfileEntryPoint.Callback,
): Node {
return parentNode.createNode<UserProfileFlowNode>(
buildContext = buildContext,
plugins = listOf(params, callback),
)
}
}

View file

@ -107,22 +107,40 @@ class UserProfileFlowNode(
// Cannot happen
}
}
mediaViewerEntryPoint.nodeBuilder(this, buildContext)
.avatar(
filename = navTarget.name,
avatarUrl = navTarget.avatarUrl
)
.callback(callback)
.build()
val params = mediaViewerEntryPoint.createParamsForAvatar(
filename = navTarget.name,
avatarUrl = navTarget.avatarUrl,
)
mediaViewerEntryPoint.createNode(
parentNode = this,
buildContext = buildContext,
params = params,
callback = callback,
)
}
is NavTarget.VerifyUser -> {
val params = OutgoingVerificationEntryPoint.Params(
showDeviceVerifiedScreen = false,
verificationRequest = VerificationRequest.Outgoing.User(userId = navTarget.userId)
)
outgoingVerificationEntryPoint.nodeBuilder(this, buildContext)
.params(params)
.build()
outgoingVerificationEntryPoint.createNode(
parentNode = this,
buildContext = buildContext,
params = params,
callback = object : OutgoingVerificationEntryPoint.Callback {
override fun navigateToLearnMoreAboutEncryption() {
// No op
}
override fun onBack() {
// No op
}
override fun onDone() {
// No op
}
}
)
}
}
}

View file

@ -59,10 +59,21 @@ class DefaultUserProfileEntryPointTest {
) = lambdaError()
},
mediaViewerEntryPoint = object : MediaViewerEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
override fun createParamsForAvatar(filename: String, avatarUrl: String) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
params: MediaViewerEntryPoint.Params,
callback: MediaViewerEntryPoint.Callback
) = lambdaError()
},
outgoingVerificationEntryPoint = object : OutgoingVerificationEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
params: OutgoingVerificationEntryPoint.Params,
callback: OutgoingVerificationEntryPoint.Callback,
) = lambdaError()
},
)
}
@ -74,10 +85,12 @@ class DefaultUserProfileEntryPointTest {
val params = UserProfileEntryPoint.Params(
userId = A_USER_ID,
)
val result = entryPoint.nodeBuilder(parentNode, BuildContext.root(null))
.params(params)
.callback(callback)
.build()
val result = entryPoint.createNode(
parentNode = parentNode,
buildContext = BuildContext.root(null),
params = params,
callback = callback,
)
assertThat(result).isInstanceOf(UserProfileFlowNode::class.java)
assertThat(result.plugins).contains(params)
assertThat(result.plugins).contains(callback)