Remove named injection and provide presenter through a factory

This commit is contained in:
Florian Renaud 2023-03-22 11:31:38 +01:00
parent a1fe191b64
commit d08a131429
11 changed files with 68 additions and 117 deletions

View file

@ -1,33 +0,0 @@
/*
* 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.selectusers.impl
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.selectusers.api.MULTI_SELECTION_USERS_VARIANT
import io.element.android.features.selectusers.api.SelectUsersPresenter
import io.element.android.libraries.di.SessionScope
import javax.inject.Inject
import javax.inject.Named
@ContributesBinding(
scope = SessionScope::class,
boundType = SelectUsersPresenter::class
)
@Named(MULTI_SELECTION_USERS_VARIANT)
class DefaultSelectMultipleUsersPresenter @Inject constructor() :
SelectUsersPresenter by DefaultSelectUsersPresenter(isMultiSelectionEnabled = true)

View file

@ -1,32 +0,0 @@
/*
* 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.selectusers.impl
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.selectusers.api.SINGLE_SELECTION_USERS_VARIANT
import io.element.android.features.selectusers.api.SelectUsersPresenter
import io.element.android.libraries.di.SessionScope
import javax.inject.Inject
import javax.inject.Named
@ContributesBinding(
scope = SessionScope::class,
boundType = SelectUsersPresenter::class
)
@Named(SINGLE_SELECTION_USERS_VARIANT)
class DefaultSelectSingleUserPresenter @Inject constructor() :
SelectUsersPresenter by DefaultSelectUsersPresenter(isMultiSelectionEnabled = false)

View file

@ -27,9 +27,15 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import com.squareup.anvil.annotations.ContributesBinding
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import io.element.android.features.selectusers.api.SelectUsersEvents
import io.element.android.features.selectusers.api.SelectUsersPresenter
import io.element.android.features.selectusers.api.SelectUsersPresenterArgs
import io.element.android.features.selectusers.api.SelectUsersState
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.core.MatrixPatterns
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.ui.model.MatrixUser
@ -42,7 +48,15 @@ import kotlinx.collections.immutable.toImmutableSet
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
class DefaultSelectUsersPresenter(private val isMultiSelectionEnabled: Boolean) : SelectUsersPresenter {
class DefaultSelectUsersPresenter @AssistedInject constructor(
@Assisted val args: SelectUsersPresenterArgs,
) : SelectUsersPresenter {
@AssistedFactory
@ContributesBinding(SessionScope::class)
interface DefaultSelectUsersFactory : SelectUsersPresenter.Factory {
override fun create(args: SelectUsersPresenterArgs): DefaultSelectUsersPresenter
}
@Composable
override fun present(): SelectUsersState {
@ -88,7 +102,7 @@ class DefaultSelectUsersPresenter(private val isMultiSelectionEnabled: Boolean)
selectedUsers = selectedUsers.value.reversed().toImmutableSet(),
selectedUsersListState = selectedUsersListState,
isSearchActive = isSearchActive,
isMultiSelectionEnabled = isMultiSelectionEnabled,
isMultiSelectionEnabled = args.isMultiSelectionEnabled,
eventSink = ::handleEvents,
)
}

View file

@ -22,6 +22,7 @@ import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.features.selectusers.api.SelectUsersEvents
import io.element.android.features.selectusers.api.SelectUsersPresenterArgs
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.ui.components.aMatrixUser
import io.element.android.libraries.matrix.ui.model.MatrixUser
@ -36,7 +37,7 @@ class DefaultSelectUsersPresenterTests {
@Test
fun `present - initial state for single selection`() = runTest {
val presenter = DefaultSelectUsersPresenter(isMultiSelectionEnabled = false)
val presenter = DefaultSelectUsersPresenter(SelectUsersPresenterArgs(isMultiSelectionEnabled = false))
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
@ -51,7 +52,7 @@ class DefaultSelectUsersPresenterTests {
@Test
fun `present - initial state for multiple selection`() = runTest {
val presenter = DefaultSelectUsersPresenter(isMultiSelectionEnabled = true)
val presenter = DefaultSelectUsersPresenter(SelectUsersPresenterArgs(isMultiSelectionEnabled = true))
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
@ -66,7 +67,7 @@ class DefaultSelectUsersPresenterTests {
@Test
fun `present - update search query`() = runTest {
val presenter = DefaultSelectUsersPresenter(isMultiSelectionEnabled = false)
val presenter = DefaultSelectUsersPresenter(SelectUsersPresenterArgs(isMultiSelectionEnabled = false))
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
@ -95,7 +96,7 @@ class DefaultSelectUsersPresenterTests {
mockkConstructor(LazyListState::class)
coJustRun { anyConstructed<LazyListState>().scrollToItem(index = any()) }
val presenter = DefaultSelectUsersPresenter(isMultiSelectionEnabled = false)
val presenter = DefaultSelectUsersPresenter(SelectUsersPresenterArgs(isMultiSelectionEnabled = false))
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {