Using qualifier annotation for bindings of SelectUsersPresenter

This commit is contained in:
Maxime NATUREL 2023-03-15 17:23:15 +01:00 committed by Florian Renaud
parent f3c4c828b2
commit c58311272d
11 changed files with 79 additions and 57 deletions

View file

@ -0,0 +1,24 @@
/*
* 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.api
import io.element.android.libraries.architecture.Presenter
const val SINGLE_SELECTION_USERS_VARIANT = "single_selection_users"
const val MULTI_SELECTION_USERS_VARIANT = "multi_selection_users"
interface SelectUsersPresenter : Presenter<SelectUsersState>

View file

@ -17,17 +17,18 @@
package io.element.android.features.selectusers.impl
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.selectusers.api.SelectMultipleUsersPresenter
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
// TODO add unit tests
@ContributesBinding(
scope = SessionScope::class,
boundType = SelectMultipleUsersPresenter::class,
boundType = SelectUsersPresenter::class
)
@Named(MULTI_SELECTION_USERS_VARIANT)
class DefaultSelectMultipleUsersPresenter @Inject constructor() :
DefaultSelectUsersPresenter,
SelectMultipleUsersPresenter {
override val isMultiSelectionEnabled: Boolean = true
}
SelectUsersPresenter by DefaultSelectUsersPresenter(isMultiSelectionEnabled = true)

View file

@ -17,16 +17,16 @@
package io.element.android.features.selectusers.impl
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.selectusers.api.SelectSingleUserPresenter
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 = SelectSingleUserPresenter::class,
boundType = SelectUsersPresenter::class
)
@Named(SINGLE_SELECTION_USERS_VARIANT)
class DefaultSelectSingleUserPresenter @Inject constructor() :
DefaultSelectUsersPresenter,
SelectSingleUserPresenter {
override val isMultiSelectionEnabled: Boolean = false
}
SelectUsersPresenter by DefaultSelectUsersPresenter(isMultiSelectionEnabled = false)

View file

@ -25,8 +25,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import io.element.android.features.selectusers.api.SelectUsersEvents
import io.element.android.features.selectusers.api.SelectUsersPresenter
import io.element.android.features.selectusers.api.SelectUsersState
import io.element.android.libraries.architecture.Presenter
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
@ -37,9 +37,7 @@ import kotlinx.collections.immutable.persistentSetOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableSet
interface DefaultSelectUsersPresenter : Presenter<SelectUsersState> {
val isMultiSelectionEnabled: Boolean
class DefaultSelectUsersPresenter(private val isMultiSelectionEnabled: Boolean) : SelectUsersPresenter {
@Composable
override fun present(): SelectUsersState {