Move RoomAliasResolver classes to their own module.

This commit is contained in:
Benoit Marty
2024-04-17 23:01:37 +02:00
committed by Benoit Marty
parent 1ed3e0c365
commit 0310b5df0f
13 changed files with 194 additions and 25 deletions

View File

@@ -36,8 +36,8 @@ import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
import io.element.android.appnav.room.joined.JoinedRoomFlowNode
import io.element.android.appnav.room.joined.JoinedRoomLoadedFlowNode
import io.element.android.appnav.room.resolver.RoomAliasResolverNode
import io.element.android.features.joinroom.api.JoinRoomEntryPoint
import io.element.android.features.roomaliasesolver.api.RoomAliasResolverEntryPoint
import io.element.android.features.roomdirectory.api.RoomDescription
import io.element.android.libraries.architecture.BackstackView
import io.element.android.libraries.architecture.BaseFlowNode
@@ -68,6 +68,7 @@ class RoomFlowNode @AssistedInject constructor(
private val client: MatrixClient,
private val roomMembershipObserver: RoomMembershipObserver,
private val joinRoomEntryPoint: JoinRoomEntryPoint,
private val roomAliasResolverEntryPoint: RoomAliasResolverEntryPoint,
) : BaseFlowNode<RoomFlowNode.NavTarget>(
backstack = BackStack(
initialElement = NavTarget.Loading,
@@ -144,13 +145,16 @@ class RoomFlowNode @AssistedInject constructor(
return when (navTarget) {
is NavTarget.Loading -> loadingNode(buildContext)
is NavTarget.Resolving -> {
val callback = object : RoomAliasResolverNode.Callback {
val callback = object : RoomAliasResolverEntryPoint.Callback {
override fun onAliasResolved(roomId: RoomId) {
backstack.newRoot(NavTarget.JoinRoom(roomId))
}
}
val params = RoomAliasResolverNode.Inputs(navTarget.roomAlias)
createNode<RoomAliasResolverNode>(buildContext, listOf(callback, params))
val params = RoomAliasResolverEntryPoint.Params(navTarget.roomAlias)
roomAliasResolverEntryPoint.nodeBuilder(this, buildContext)
.callback(callback)
.params(params)
.build()
}
is NavTarget.JoinRoom -> {
val inputs = JoinRoomEntryPoint.Inputs(

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("io.element.android-library")
}
android {
namespace = "io.element.android.features.roomaliasresolver.api"
}
dependencies {
implementation(projects.libraries.architecture)
implementation(projects.libraries.matrix.api)
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.roomaliasesolver.api
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import io.element.android.libraries.architecture.FeatureEntryPoint
import io.element.android.libraries.architecture.NodeInputs
import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId
interface RoomAliasResolverEntryPoint : FeatureEntryPoint {
fun nodeBuilder(parentNode: Node, buildContext: BuildContext): NodeBuilder
interface NodeBuilder {
fun callback(callback: Callback): NodeBuilder
fun params(params: Params): NodeBuilder
fun build(): Node
}
interface Callback : Plugin {
fun onAliasResolved(roomId: RoomId)
}
data class Params(
val roomAlias: RoomAlias
) : NodeInputs
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("io.element.android-compose-library")
alias(libs.plugins.anvil)
alias(libs.plugins.ksp)
id("kotlin-parcelize")
}
android {
namespace = "io.element.android.features.roomaliasresolver.impl"
}
anvil {
generateDaggerFactories.set(true)
}
dependencies {
implementation(projects.anvilannotations)
anvil(projects.anvilcodegen)
api(projects.features.roomaliasresolver.api)
implementation(projects.libraries.core)
implementation(projects.libraries.architecture)
implementation(projects.libraries.androidutils)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.matrixui)
implementation(projects.libraries.designsystem)
implementation(projects.libraries.uiStrings)
testImplementation(libs.test.junit)
testImplementation(libs.coroutines.test)
testImplementation(libs.molecule.runtime)
testImplementation(libs.test.truth)
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.tests.testutils)
ksp(libs.showkase.processor)
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.roomaliasresolver.impl
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.roomaliasesolver.api.RoomAliasResolverEntryPoint
import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.di.AppScope
import javax.inject.Inject
@ContributesBinding(AppScope::class)
class DefaultRoomAliasResolverEntryPoint @Inject constructor() : RoomAliasResolverEntryPoint {
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext): RoomAliasResolverEntryPoint.NodeBuilder {
val plugins = ArrayList<Plugin>()
return object : RoomAliasResolverEntryPoint.NodeBuilder {
override fun callback(callback: RoomAliasResolverEntryPoint.Callback): RoomAliasResolverEntryPoint.NodeBuilder {
plugins += callback
return this
}
override fun params(params: RoomAliasResolverEntryPoint.Params): RoomAliasResolverEntryPoint.NodeBuilder {
plugins += params
return this
}
override fun build(): Node {
return parentNode.createNode<RoomAliasResolverNode>(buildContext, plugins)
}
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
sealed interface RoomAliasResolverEvents {
data object Retry : RoomAliasResolverEvents

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@@ -25,10 +25,9 @@ import com.bumble.appyx.core.plugin.plugins
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
import io.element.android.libraries.architecture.NodeInputs
import io.element.android.features.roomaliasesolver.api.RoomAliasResolverEntryPoint
import io.element.android.libraries.architecture.inputs
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId
@ContributesNode(SessionScope::class)
@@ -37,22 +36,14 @@ class RoomAliasResolverNode @AssistedInject constructor(
@Assisted plugins: List<Plugin>,
presenterFactory: RoomAliasResolverPresenter.Factory,
) : Node(buildContext, plugins = plugins) {
data class Inputs(
val roomAlias: RoomAlias
) : NodeInputs
private val inputs = inputs<Inputs>()
private val inputs = inputs<RoomAliasResolverEntryPoint.Params>()
private val presenter = presenterFactory.create(
inputs.roomAlias
)
interface Callback : Plugin {
fun onAliasResolved(roomId: RoomId)
}
private fun onAliasResolved(roomId: RoomId) {
plugins<Callback>().forEach { it.onAliasResolved(roomId) }
plugins<RoomAliasResolverEntryPoint.Callback>().forEach { it.onAliasResolved(roomId) }
}
@Composable

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import androidx.compose.runtime.Immutable
import io.element.android.libraries.architecture.AsyncData

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.architecture.AsyncData

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column

View File

@@ -14,18 +14,19 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl.di
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import io.element.android.features.roomaliasresolver.impl.RoomAliasResolverPresenter
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.core.RoomAlias
@Module
@ContributesTo(SessionScope::class)
object ResolveRoomModule {
object RoomAliasResolverModule {
@Provides
fun providesJoinRoomPresenterFactory(
client: MatrixClient,

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.appnav.room.resolver
package io.element.android.features.roomaliasresolver.impl
import app.cash.molecule.RecompositionMode
import app.cash.molecule.moleculeFlow