Rename callbacks for clarity and consistency

This commit is contained in:
Florian Renaud 2023-04-14 16:46:45 +02:00
parent 5c74920a33
commit 064d4a9a7c
5 changed files with 14 additions and 17 deletions

View file

@ -56,10 +56,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.ui.di.MatrixUIBindings import io.element.android.libraries.matrix.ui.di.MatrixUIBindings
import io.element.android.services.appnavstate.api.AppNavigationStateService import io.element.android.services.appnavstate.api.AppNavigationStateService
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import kotlin.coroutines.coroutineContext
@ContributesNode(AppScope::class) @ContributesNode(AppScope::class)
class LoggedInFlowNode @AssistedInject constructor( class LoggedInFlowNode @AssistedInject constructor(
@ -201,7 +198,7 @@ class LoggedInFlowNode @AssistedInject constructor(
} }
NavTarget.CreateRoom -> { NavTarget.CreateRoom -> {
val callback = object : CreateRoomEntryPoint.Callback { val callback = object : CreateRoomEntryPoint.Callback {
override fun onOpenRoom(roomId: RoomId) { override fun onSuccess(roomId: RoomId) {
backstack.replace(NavTarget.Room(roomId)) backstack.replace(NavTarget.Room(roomId))
} }
} }

View file

@ -31,6 +31,6 @@ interface CreateRoomEntryPoint : FeatureEntryPoint {
} }
interface Callback : Plugin { interface Callback : Plugin {
fun onOpenRoom(roomId: RoomId) fun onSuccess(roomId: RoomId)
} }
} }

View file

@ -68,16 +68,16 @@ class CreateRoomFlowNode @AssistedInject constructor(
backstack.push(NavTarget.NewRoom) backstack.push(NavTarget.NewRoom)
} }
override fun onOpenRoom(roomId: RoomId) { override fun onStartChatSuccess(roomId: RoomId) {
plugins<CreateRoomEntryPoint.Callback>().forEach { it.onOpenRoom(roomId) } plugins<CreateRoomEntryPoint.Callback>().forEach { it.onSuccess(roomId) }
} }
} }
createNode<CreateRoomRootNode>(context = buildContext, plugins = listOf(callback)) createNode<CreateRoomRootNode>(context = buildContext, plugins = listOf(callback))
} }
NavTarget.NewRoom -> { NavTarget.NewRoom -> {
val callback = object : ConfigureRoomNode.Callback { val callback = object : ConfigureRoomNode.Callback {
override fun onRoomCreated(roomId: RoomId) { override fun onCreateRoomSuccess(roomId: RoomId) {
plugins<CreateRoomEntryPoint.Callback>().forEach { it.onOpenRoom(roomId) } plugins<CreateRoomEntryPoint.Callback>().forEach { it.onSuccess(roomId) }
} }
} }
createNode<ConfigureRoomFlowNode>(context = buildContext, plugins = listOf(callback)) createNode<ConfigureRoomFlowNode>(context = buildContext, plugins = listOf(callback))

View file

@ -36,12 +36,12 @@ class ConfigureRoomNode @AssistedInject constructor(
) : Node(buildContext, plugins = plugins) { ) : Node(buildContext, plugins = plugins) {
interface Callback : Plugin { interface Callback : Plugin {
fun onRoomCreated(roomId: RoomId) fun onCreateRoomSuccess(roomId: RoomId)
} }
private val callback = object : Callback { private val callback = object : Callback {
override fun onRoomCreated(roomId: RoomId) { override fun onCreateRoomSuccess(roomId: RoomId) {
plugins<Callback>().forEach { it.onRoomCreated(roomId) } plugins<Callback>().forEach { it.onCreateRoomSuccess(roomId) }
} }
} }
@ -52,7 +52,7 @@ class ConfigureRoomNode @AssistedInject constructor(
state = state, state = state,
modifier = modifier, modifier = modifier,
onBackPressed = this::navigateUp, onBackPressed = this::navigateUp,
onRoomCreated = callback::onRoomCreated onRoomCreated = callback::onCreateRoomSuccess
) )
} }
} }

View file

@ -37,7 +37,7 @@ class CreateRoomRootNode @AssistedInject constructor(
interface Callback : Plugin { interface Callback : Plugin {
fun onCreateNewRoom() fun onCreateNewRoom()
fun onOpenRoom(roomId: RoomId) fun onStartChatSuccess(roomId: RoomId)
} }
private val callback = object : Callback { private val callback = object : Callback {
@ -45,8 +45,8 @@ class CreateRoomRootNode @AssistedInject constructor(
plugins<Callback>().forEach { it.onCreateNewRoom() } plugins<Callback>().forEach { it.onCreateNewRoom() }
} }
override fun onOpenRoom(roomId: RoomId) { override fun onStartChatSuccess(roomId: RoomId) {
plugins<Callback>().forEach { it.onOpenRoom(roomId) } plugins<Callback>().forEach { it.onStartChatSuccess(roomId) }
} }
} }
@ -58,7 +58,7 @@ class CreateRoomRootNode @AssistedInject constructor(
modifier = modifier, modifier = modifier,
onClosePressed = this::navigateUp, onClosePressed = this::navigateUp,
onNewRoomClicked = callback::onCreateNewRoom, onNewRoomClicked = callback::onCreateNewRoom,
onOpenDM = callback::onOpenRoom, onOpenDM = callback::onStartChatSuccess,
) )
} }
} }