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.preferences.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.preferences.api.PreferencesEntryPoint
@ -17,24 +16,16 @@ import io.element.android.libraries.architecture.createNode
@ContributesBinding(AppScope::class)
class DefaultPreferencesEntryPoint : PreferencesEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext): PreferencesEntryPoint.NodeBuilder {
return object : PreferencesEntryPoint.NodeBuilder {
val plugins = ArrayList<Plugin>()
override fun params(params: PreferencesEntryPoint.Params): PreferencesEntryPoint.NodeBuilder {
plugins += params
return this
}
override fun callback(callback: PreferencesEntryPoint.Callback): PreferencesEntryPoint.NodeBuilder {
plugins += callback
return this
}
override fun build(): Node {
return parentNode.createNode<PreferencesFlowNode>(buildContext, plugins)
}
}
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
params: PreferencesEntryPoint.Params,
callback: PreferencesEntryPoint.Callback,
): Node {
return parentNode.createNode<PreferencesFlowNode>(
buildContext = buildContext,
plugins = listOf(params, callback)
)
}
}

View file

@ -215,8 +215,10 @@ class PreferencesFlowNode(
createNode<NotificationSettingsNode>(buildContext, listOf(notificationSettingsCallback))
}
NavTarget.TroubleshootNotifications -> {
notificationTroubleShootEntryPoint.nodeBuilder(this, buildContext)
.callback(object : NotificationTroubleShootEntryPoint.Callback {
notificationTroubleShootEntryPoint.createNode(
parentNode = this,
buildContext = buildContext,
callback = object : NotificationTroubleShootEntryPoint.Callback {
override fun onDone() {
if (backstack.canPop()) {
backstack.pop()
@ -228,12 +230,14 @@ class PreferencesFlowNode(
override fun navigateToBlockedUsers() {
backstack.push(NavTarget.BlockedUsers)
}
})
.build()
},
)
}
NavTarget.PushHistory -> {
pushHistoryEntryPoint.nodeBuilder(this, buildContext)
.callback(object : PushHistoryEntryPoint.Callback {
pushHistoryEntryPoint.createNode(
this,
buildContext,
object : PushHistoryEntryPoint.Callback {
override fun onDone() {
if (backstack.canPop()) {
backstack.pop()
@ -245,8 +249,8 @@ class PreferencesFlowNode(
override fun navigateToEvent(roomId: RoomId, eventId: EventId) {
callback.navigateToEvent(roomId, eventId)
}
})
.build()
},
)
}
is NavTarget.EditDefaultNotificationSetting -> {
val callback = object : EditDefaultNotificationSettingNode.Callback {
@ -265,7 +269,16 @@ class PreferencesFlowNode(
createNode<EditUserProfileNode>(buildContext, listOf(inputs))
}
NavTarget.LockScreenSettings -> {
lockScreenEntryPoint.nodeBuilder(this, buildContext, LockScreenEntryPoint.Target.Settings).build()
lockScreenEntryPoint.createNode(
parentNode = this,
buildContext = buildContext,
navTarget = LockScreenEntryPoint.Target.Settings,
callback = object : LockScreenEntryPoint.Callback {
override fun onSetupDone() {
// No op
}
}
)
}
NavTarget.BlockedUsers -> {
createNode<BlockedUsersNode>(buildContext)
@ -276,9 +289,11 @@ class PreferencesFlowNode(
callback.navigateToSecureBackup()
}
}
logoutEntryPoint.nodeBuilder(this, buildContext)
.callback(callBack)
.build()
logoutEntryPoint.createNode(
parentNode = this,
buildContext = buildContext,
callback = callBack,
)
}
is NavTarget.OssLicenses -> {
openSourceLicensesEntryPoint.createNode(this, buildContext)

View file

@ -42,17 +42,35 @@ class DefaultPreferencesEntryPointTest {
buildContext = buildContext,
plugins = plugins,
lockScreenEntryPoint = object : LockScreenEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext, navTarget: LockScreenEntryPoint.Target) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
navTarget: LockScreenEntryPoint.Target,
callback: LockScreenEntryPoint.Callback,
) = lambdaError()
override fun pinUnlockIntent(context: Context) = lambdaError()
},
notificationTroubleShootEntryPoint = object : NotificationTroubleShootEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
callback: NotificationTroubleShootEntryPoint.Callback,
) = lambdaError()
},
pushHistoryEntryPoint = object : PushHistoryEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
callback: PushHistoryEntryPoint.Callback,
) = lambdaError()
},
logoutEntryPoint = object : LogoutEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
override fun createNode(
parentNode: Node,
buildContext: BuildContext,
callback: LogoutEntryPoint.Callback,
) = lambdaError()
},
openSourceLicensesEntryPoint = object : OpenSourceLicensesEntryPoint {
override fun createNode(parentNode: Node, buildContext: BuildContext) = lambdaError()
@ -72,10 +90,12 @@ class DefaultPreferencesEntryPointTest {
val params = PreferencesEntryPoint.Params(
initialElement = PreferencesEntryPoint.InitialTarget.NotificationSettings,
)
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(PreferencesFlowNode::class.java)
assertThat(result.plugins).contains(params)
assertThat(result.plugins).contains(callback)