[Architecture] use FeatureEntryPoint on Preferences

This commit is contained in:
ganfra
2023-03-02 15:59:25 +01:00
parent 9d730d8b74
commit 15ed58b756
17 changed files with 94 additions and 33 deletions

View File

@@ -36,7 +36,7 @@ import com.bumble.appyx.navmodel.backstack.operation.push
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
import io.element.android.features.preferences.PreferencesFlowNode
import io.element.android.features.preferences.api.PreferencesEntryPoint
import io.element.android.features.roomlist.api.RoomListEntryPoint
import io.element.android.libraries.architecture.NodeInputs
import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler
@@ -59,6 +59,7 @@ class LoggedInFlowNode(
plugins: List<Plugin>,
private val backstack: BackStack<NavTarget>,
private val roomListEntryPoint: RoomListEntryPoint,
private val preferencesEntryPoint: PreferencesEntryPoint,
) : ParentNode<LoggedInFlowNode.NavTarget>(
navModel = backstack,
buildContext = buildContext,
@@ -70,10 +71,12 @@ class LoggedInFlowNode(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
roomListEntryPoint: RoomListEntryPoint,
preferencesEntryPoint: PreferencesEntryPoint,
) : this(
buildContext = buildContext,
plugins = plugins,
roomListEntryPoint = roomListEntryPoint,
preferencesEntryPoint = preferencesEntryPoint,
backstack = BackStack(
initialElement = NavTarget.RoomList,
savedStateMap = buildContext.savedStateMap,
@@ -149,12 +152,12 @@ class LoggedInFlowNode(
}
}
NavTarget.Settings -> {
val callback = object : PreferencesFlowNode.Callback {
val callback = object : PreferencesEntryPoint.Callback {
override fun onOpenBugReport() {
plugins<Callback>().forEach { it.onOpenBugReport() }
}
}
createNode<PreferencesFlowNode>(buildContext, plugins = listOf(callback))
preferencesEntryPoint.node(this, buildContext, plugins = listOf(callback))
}
}
}

View File

@@ -42,7 +42,7 @@ import kotlinx.parcelize.Parcelize
import timber.log.Timber
@ContributesNode(SessionScope::class)
class RoomFlowNode(
class RoomFlowNode private constructor(
buildContext: BuildContext,
plugins: List<Plugin>,
private val backstack: BackStack<NavTarget>,

View File

@@ -16,6 +16,6 @@
package io.element.android.features.login.api
import io.element.android.libraries.architecture.EntryPoint
import io.element.android.libraries.architecture.FeatureEntryPoint
interface LoginEntryPoint : EntryPoint
interface LoginEntryPoint : FeatureEntryPoint

View File

@@ -17,9 +17,9 @@
package io.element.android.features.onboarding.api
import com.bumble.appyx.core.plugin.Plugin
import io.element.android.libraries.architecture.EntryPoint
import io.element.android.libraries.architecture.FeatureEntryPoint
interface OnBoardingEntryPoint : EntryPoint {
interface OnBoardingEntryPoint : FeatureEntryPoint {
interface Callback : Plugin {
fun onSignUp()
fun onSignIn()

View File

@@ -0,0 +1,26 @@
/*
* 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.features.preferences.api
import com.bumble.appyx.core.plugin.Plugin
import io.element.android.libraries.architecture.FeatureEntryPoint
interface PreferencesEntryPoint: FeatureEntryPoint {
interface Callback : Plugin {
fun onOpenBugReport()
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.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 com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.preferences.api.PreferencesEntryPoint
import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.di.AppScope
import javax.inject.Inject
@ContributesBinding(AppScope::class)
class DefaultPreferencesEntryPoint @Inject constructor() : PreferencesEntryPoint {
override fun node(parentNode: Node, buildContext: BuildContext, plugins: List<Plugin>): Node {
return parentNode.createNode<PreferencesFlowNode>(buildContext, plugins)
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences
package io.element.android.features.preferences.impl
import android.os.Parcelable
import androidx.compose.runtime.Composable
@@ -29,7 +29,8 @@ import com.bumble.appyx.navmodel.backstack.BackStack
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
import io.element.android.features.preferences.root.PreferencesRootNode
import io.element.android.features.preferences.api.PreferencesEntryPoint
import io.element.android.features.preferences.impl.root.PreferencesRootNode
import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler
import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.di.SessionScope
@@ -56,16 +57,6 @@ class PreferencesFlowNode(
)
)
interface Callback : Plugin {
fun onOpenBugReport()
}
private val preferencesRootNodeCallback = object : PreferencesRootNode.Callback {
override fun onOpenBugReport() {
plugins<Callback>().forEach { it.onOpenBugReport() }
}
}
sealed interface NavTarget : Parcelable {
@Parcelize
object Root : NavTarget
@@ -73,7 +64,14 @@ class PreferencesFlowNode(
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
return when (navTarget) {
NavTarget.Root -> createNode<PreferencesRootNode>(buildContext, plugins = listOf(preferencesRootNodeCallback))
NavTarget.Root -> {
val callback = object : PreferencesRootNode.Callback {
override fun onOpenBugReport() {
plugins<PreferencesEntryPoint.Callback>().forEach { it.onOpenBugReport() }
}
}
createNode<PreferencesRootNode>(buildContext, plugins = listOf(callback))
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.root
package io.element.android.features.preferences.impl.root
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.root
package io.element.android.features.preferences.impl.root
import androidx.compose.runtime.Composable
import io.element.android.features.logout.LogoutPreferencePresenter

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.root
package io.element.android.features.preferences.impl.root
import io.element.android.features.logout.LogoutPreferenceState
import io.element.android.features.rageshake.preferences.RageshakePreferencesState

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.root
package io.element.android.features.preferences.impl.root
import io.element.android.features.logout.aLogoutPreferenceState
import io.element.android.features.rageshake.preferences.aRageshakePreferencesState

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.root
package io.element.android.features.preferences.impl.root
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@@ -22,7 +22,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import io.element.android.features.logout.LogoutPreferenceView
import io.element.android.features.preferences.user.UserPreferences
import io.element.android.features.preferences.impl.user.UserPreferences
import io.element.android.features.rageshake.preferences.RageshakePreferencesView
import io.element.android.libraries.architecture.Async
import io.element.android.libraries.designsystem.components.preferences.PreferenceView

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.features.preferences.user
package io.element.android.features.preferences.impl.user
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height

View File

@@ -23,6 +23,7 @@ import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.features.logout.LogoutPreferencePresenter
import io.element.android.features.preferences.impl.root.PreferencesRootPresenter
import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter
import io.element.android.libraries.architecture.Async
import io.element.android.libraries.matrixtest.FakeMatrixClient

View File

@@ -17,9 +17,9 @@
package io.element.android.features.rageshake.bugreport
import com.bumble.appyx.core.plugin.Plugin
import io.element.android.libraries.architecture.EntryPoint
import io.element.android.libraries.architecture.FeatureEntryPoint
interface BugReportEntryPoint : EntryPoint {
interface BugReportEntryPoint : FeatureEntryPoint {
interface Callback : Plugin {
fun onBugReportSent()
}

View File

@@ -17,10 +17,10 @@
package io.element.android.features.roomlist.api
import com.bumble.appyx.core.plugin.Plugin
import io.element.android.libraries.architecture.EntryPoint
import io.element.android.libraries.architecture.FeatureEntryPoint
import io.element.android.libraries.matrix.core.RoomId
interface RoomListEntryPoint : EntryPoint {
interface RoomListEntryPoint : FeatureEntryPoint {
interface Callback : Plugin {
fun onRoomClicked(roomId: RoomId)
fun onSettingsClicked()

View File

@@ -20,6 +20,6 @@ import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
interface EntryPoint {
interface FeatureEntryPoint {
fun node(parentNode: Node, buildContext: BuildContext, plugins: List<Plugin> = emptyList()): Node
}