From eb648cef1a98958e98f3db4d82f8e303dcb95cc2 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 19 Jan 2023 19:57:43 +0100 Subject: [PATCH] Initial feature template module --- features/template/.gitignore | 1 + features/template/build.gradle.kts | 58 +++++++++++++++++++ features/template/consumer-rules.pro | 0 features/template/proguard-rules.pro | 21 +++++++ .../template/src/main/AndroidManifest.xml | 20 +++++++ .../x/features/template/TemplateEvents.kt | 21 +++++++ .../x/features/template/TemplateNode.kt | 50 ++++++++++++++++ .../x/features/template/TemplatePresenter.kt | 38 ++++++++++++ .../x/features/template/TemplateState.kt | 21 +++++++ .../x/features/template/TemplateView.kt | 42 ++++++++++++++ .../template/TemplatePresenterTests.kt | 40 +++++++++++++ settings.gradle.kts | 1 + 12 files changed, 313 insertions(+) create mode 100644 features/template/.gitignore create mode 100644 features/template/build.gradle.kts create mode 100644 features/template/consumer-rules.pro create mode 100644 features/template/proguard-rules.pro create mode 100644 features/template/src/main/AndroidManifest.xml create mode 100644 features/template/src/main/kotlin/io/element/android/x/features/template/TemplateEvents.kt create mode 100644 features/template/src/main/kotlin/io/element/android/x/features/template/TemplateNode.kt create mode 100644 features/template/src/main/kotlin/io/element/android/x/features/template/TemplatePresenter.kt create mode 100644 features/template/src/main/kotlin/io/element/android/x/features/template/TemplateState.kt create mode 100644 features/template/src/main/kotlin/io/element/android/x/features/template/TemplateView.kt create mode 100644 features/template/src/test/kotlin/io/element/android/x/features/template/TemplatePresenterTests.kt diff --git a/features/template/.gitignore b/features/template/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/features/template/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/features/template/build.gradle.kts b/features/template/build.gradle.kts new file mode 100644 index 0000000000..6550ff8e56 --- /dev/null +++ b/features/template/build.gradle.kts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 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. + */ + +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") +plugins { + id("io.element.android-compose-library") + alias(libs.plugins.ksp) + alias(libs.plugins.anvil) +} + +android { + namespace = "io.element.android.x.features.template" +} + +anvil { + generateDaggerFactories.set(true) +} + +dependencies { + anvil(project(":anvilcodegen")) + implementation(project(":anvilannotations")) + + implementation(project(":libraries:di")) + implementation(project(":libraries:core")) + implementation(project(":libraries:architecture")) + implementation(project(":libraries:matrix")) + implementation(project(":libraries:matrixui")) + implementation(project(":libraries:designsystem")) + implementation(project(":libraries:elementresources")) + implementation(project(":libraries:ui-strings")) + + implementation(libs.appyx.core) + + testImplementation(libs.test.junit) + testImplementation(libs.coroutines.test) + testImplementation(libs.molecule.runtime) + testImplementation(libs.test.truth) + testImplementation(libs.test.turbine) + testImplementation(project(":libraries:matrixtest")) + + androidTestImplementation(libs.test.junitext) + + ksp(libs.showkase.processor) +} diff --git a/features/template/consumer-rules.pro b/features/template/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/features/template/proguard-rules.pro b/features/template/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/features/template/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/features/template/src/main/AndroidManifest.xml b/features/template/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..e9c0841b6b --- /dev/null +++ b/features/template/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateEvents.kt b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateEvents.kt new file mode 100644 index 0000000000..3f82f79cd4 --- /dev/null +++ b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateEvents.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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.x.features.template + +sealed interface TemplateEvents { + +} diff --git a/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateNode.kt b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateNode.kt new file mode 100644 index 0000000000..45b9de8164 --- /dev/null +++ b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateNode.kt @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 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.x.features.template + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import com.bumble.appyx.core.modality.BuildContext +import com.bumble.appyx.core.node.Node +import com.bumble.appyx.core.plugin.Plugin +import dagger.assisted.Assisted +import dagger.assisted.AssistedInject +import io.element.android.x.anvilannotations.ContributesNode +import io.element.android.x.architecture.presenterConnector +import io.element.android.x.di.AppScope + +// TODO: use the right Scope for your feature +@ContributesNode(AppScope::class) +class TemplateNode @AssistedInject constructor( + @Assisted buildContext: BuildContext, + @Assisted plugins: List, + presenter: TemplatePresenter, +) : Node(buildContext, plugins = plugins) { + + private val presenterConnector = presenterConnector(presenter) + + @Composable + override fun View(modifier: Modifier) { + val state by presenterConnector.stateFlow.collectAsState() + TemplateView( + state = state, + modifier = modifier + ) + } +} diff --git a/features/template/src/main/kotlin/io/element/android/x/features/template/TemplatePresenter.kt b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplatePresenter.kt new file mode 100644 index 0000000000..f306fecbf7 --- /dev/null +++ b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplatePresenter.kt @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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.x.features.template + +import androidx.compose.runtime.Composable +import io.element.android.x.architecture.Presenter +import javax.inject.Inject + +class TemplatePresenter @Inject constructor() : Presenter { + + @Composable + override fun present(): TemplateState { + + fun handleEvents(event: TemplateEvents) { + when (event) { + else -> Unit + } + } + + return TemplateState( + eventSink = ::handleEvents + ) + } +} diff --git a/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateState.kt b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateState.kt new file mode 100644 index 0000000000..cd05023a31 --- /dev/null +++ b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateState.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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.x.features.template + +data class TemplateState( + val eventSink: (TemplateEvents) -> Unit = {} +) diff --git a/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateView.kt b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateView.kt new file mode 100644 index 0000000000..015be504bd --- /dev/null +++ b/features/template/src/main/kotlin/io/element/android/x/features/template/TemplateView.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 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.x.features.template + +import androidx.compose.foundation.layout.Box +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview + +@Composable +fun TemplateView( + state: TemplateState, + modifier: Modifier = Modifier, +) { + Box(modifier, contentAlignment = Alignment.Center) { + Text("Template feature view") + } +} + +@Composable +@Preview +fun TemplateViewPreview() { + TemplateView( + state = TemplateState(), + ) +} diff --git a/features/template/src/test/kotlin/io/element/android/x/features/template/TemplatePresenterTests.kt b/features/template/src/test/kotlin/io/element/android/x/features/template/TemplatePresenterTests.kt new file mode 100644 index 0000000000..e470489bce --- /dev/null +++ b/features/template/src/test/kotlin/io/element/android/x/features/template/TemplatePresenterTests.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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.x.features.template + +import app.cash.molecule.RecompositionClock +import app.cash.molecule.moleculeFlow +import app.cash.turbine.test +import com.google.common.truth.Truth +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class TemplatePresenterTests { + + @Test + fun `present - `() = runTest { + + val presenter = TemplatePresenter() + moleculeFlow(RecompositionClock.Immediate) { + presenter.present() + }.test { + val initialState = awaitItem() + Truth.assertThat(initialState) + } + + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 2971994ca8..13bdc4ca01 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -55,3 +55,4 @@ include(":anvilannotations") include(":anvilcodegen") include(":libraries:architecture") include(":libraries:matrixtest") +include(":features:template")