From 0310b5df0f253a37cd1d3fae464ed58aeb4b60de Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 17 Apr 2024 23:01:37 +0200 Subject: [PATCH] Move RoomAliasResolver classes to their own module. --- .../android/appnav/room/RoomFlowNode.kt | 12 +++-- .../roomaliasresolver/api/build.gradle.kts | 28 ++++++++++ .../api/RoomAliasResolverEntryPoint.kt | 43 +++++++++++++++ .../roomaliasresolver/impl/build.gradle.kts | 53 +++++++++++++++++++ .../DefaultRoomAliasResolverEntryPoint.kt | 49 +++++++++++++++++ .../impl}/RoomAliasResolverEvents.kt | 2 +- .../impl}/RoomAliasResolverNode.kt | 17 ++---- .../impl}/RoomAliasResolverPresenter.kt | 2 +- .../impl}/RoomAliasResolverState.kt | 2 +- .../impl}/RoomAliasResolverStateProvider.kt | 2 +- .../impl}/RoomAliasResolverView.kt | 2 +- .../impl/di/RoomAliasResolverModule.kt | 5 +- .../impl}/RoomAliasResolverPresenterTest.kt | 2 +- 13 files changed, 194 insertions(+), 25 deletions(-) create mode 100644 features/roomaliasresolver/api/build.gradle.kts create mode 100644 features/roomaliasresolver/api/src/main/kotlin/io/element/android/features/roomaliasesolver/api/RoomAliasResolverEntryPoint.kt create mode 100644 features/roomaliasresolver/impl/build.gradle.kts create mode 100644 features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/DefaultRoomAliasResolverEntryPoint.kt rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverEvents.kt (92%) rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverNode.kt (80%) rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverPresenter.kt (97%) rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverState.kt (94%) rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverStateProvider.kt (96%) rename {appnav/src/main/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverView.kt (99%) rename appnav/src/main/kotlin/io/element/android/appnav/room/resolver/ResolveRoomModule.kt => features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/di/RoomAliasResolverModule.kt (88%) rename {appnav/src/test/kotlin/io/element/android/appnav/room/resolver => features/roomaliasresolver/impl/src/test/kotlin/io/element/android/features/roomaliasresolver/impl}/RoomAliasResolverPresenterTest.kt (98%) diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt b/appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt index d0fc830892..932e36811b 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt @@ -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( 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(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( diff --git a/features/roomaliasresolver/api/build.gradle.kts b/features/roomaliasresolver/api/build.gradle.kts new file mode 100644 index 0000000000..631c9e2dbf --- /dev/null +++ b/features/roomaliasresolver/api/build.gradle.kts @@ -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) +} diff --git a/features/roomaliasresolver/api/src/main/kotlin/io/element/android/features/roomaliasesolver/api/RoomAliasResolverEntryPoint.kt b/features/roomaliasresolver/api/src/main/kotlin/io/element/android/features/roomaliasesolver/api/RoomAliasResolverEntryPoint.kt new file mode 100644 index 0000000000..8c0cc10f64 --- /dev/null +++ b/features/roomaliasresolver/api/src/main/kotlin/io/element/android/features/roomaliasesolver/api/RoomAliasResolverEntryPoint.kt @@ -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 +} diff --git a/features/roomaliasresolver/impl/build.gradle.kts b/features/roomaliasresolver/impl/build.gradle.kts new file mode 100644 index 0000000000..eaf2773231 --- /dev/null +++ b/features/roomaliasresolver/impl/build.gradle.kts @@ -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) +} diff --git a/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/DefaultRoomAliasResolverEntryPoint.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/DefaultRoomAliasResolverEntryPoint.kt new file mode 100644 index 0000000000..46bb6cf6c1 --- /dev/null +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/DefaultRoomAliasResolverEntryPoint.kt @@ -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() + + 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(buildContext, plugins) + } + } + } +} diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverEvents.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverEvents.kt similarity index 92% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverEvents.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverEvents.kt index 1eb3c8ffe9..60ac90d762 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverEvents.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverEvents.kt @@ -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 diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverNode.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverNode.kt similarity index 80% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverNode.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverNode.kt index c429ec1a95..a4dbcc40b5 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverNode.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverNode.kt @@ -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, presenterFactory: RoomAliasResolverPresenter.Factory, ) : Node(buildContext, plugins = plugins) { - data class Inputs( - val roomAlias: RoomAlias - ) : NodeInputs - - private val inputs = inputs() + private val inputs = inputs() private val presenter = presenterFactory.create( inputs.roomAlias ) - interface Callback : Plugin { - fun onAliasResolved(roomId: RoomId) - } - private fun onAliasResolved(roomId: RoomId) { - plugins().forEach { it.onAliasResolved(roomId) } + plugins().forEach { it.onAliasResolved(roomId) } } @Composable diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenter.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenter.kt similarity index 97% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenter.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenter.kt index 5e9e3382d5..775be7d6ff 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenter.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenter.kt @@ -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 diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverState.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverState.kt similarity index 94% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverState.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverState.kt index 4f800a76cd..638214da3f 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverState.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverState.kt @@ -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 diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverStateProvider.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverStateProvider.kt similarity index 96% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverStateProvider.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverStateProvider.kt index 9584bb21b8..3c5599628c 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverStateProvider.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverStateProvider.kt @@ -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 diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverView.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverView.kt similarity index 99% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverView.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverView.kt index e208119a16..fa61012ec0 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverView.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverView.kt @@ -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 diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/ResolveRoomModule.kt b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/di/RoomAliasResolverModule.kt similarity index 88% rename from appnav/src/main/kotlin/io/element/android/appnav/room/resolver/ResolveRoomModule.kt rename to features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/di/RoomAliasResolverModule.kt index 687fefc5c5..538cc57f32 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/resolver/ResolveRoomModule.kt +++ b/features/roomaliasresolver/impl/src/main/kotlin/io/element/android/features/roomaliasresolver/impl/di/RoomAliasResolverModule.kt @@ -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, diff --git a/appnav/src/test/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenterTest.kt b/features/roomaliasresolver/impl/src/test/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenterTest.kt similarity index 98% rename from appnav/src/test/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenterTest.kt rename to features/roomaliasresolver/impl/src/test/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenterTest.kt index 79e44cd627..2c64690600 100644 --- a/appnav/src/test/kotlin/io/element/android/appnav/room/resolver/RoomAliasResolverPresenterTest.kt +++ b/features/roomaliasresolver/impl/src/test/kotlin/io/element/android/features/roomaliasresolver/impl/RoomAliasResolverPresenterTest.kt @@ -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