Adding multi/single selection variants
This commit is contained in:
parent
2bdd528842
commit
f536c6308d
12 changed files with 242 additions and 156 deletions
|
|
@ -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.selectusers.impl
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.features.selectusers.api.SelectMultipleUsersPresenter
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO add unit tests
|
||||
@ContributesBinding(
|
||||
scope = SessionScope::class,
|
||||
boundType = SelectMultipleUsersPresenter::class,
|
||||
)
|
||||
class DefaultSelectMultipleUsersPresenter @Inject constructor() :
|
||||
DefaultSelectUsersPresenter,
|
||||
SelectMultipleUsersPresenter {
|
||||
override val isMultiSelectionEnabled: Boolean = true
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.SelectSingleUserPresenter
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(
|
||||
scope = SessionScope::class,
|
||||
boundType = SelectSingleUserPresenter::class,
|
||||
)
|
||||
class DefaultSelectSingleUserPresenter @Inject constructor() :
|
||||
DefaultSelectUsersPresenter,
|
||||
SelectSingleUserPresenter {
|
||||
override val isMultiSelectionEnabled: Boolean = false
|
||||
}
|
||||
|
|
@ -24,26 +24,26 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
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.di.SessionScope
|
||||
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
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(SessionScope::class)
|
||||
class DefaultSelectUsersPresenter @Inject constructor() : SelectUsersPresenter {
|
||||
interface DefaultSelectUsersPresenter : Presenter<SelectUsersState> {
|
||||
|
||||
val isMultiSelectionEnabled: Boolean
|
||||
|
||||
@Composable
|
||||
override fun present(): SelectUsersState {
|
||||
var isSearchActive by rememberSaveable { mutableStateOf(false) }
|
||||
val selectedUsers: MutableState<ImmutableList<MatrixUser>> = remember { mutableStateOf(persistentListOf()) }
|
||||
val selectedUsers: MutableState<ImmutableList<MatrixUser>> = remember {
|
||||
mutableStateOf(persistentListOf())
|
||||
}
|
||||
var searchQuery by rememberSaveable { mutableStateOf("") }
|
||||
val searchResults: MutableState<ImmutableList<MatrixUser>> = remember {
|
||||
mutableStateOf(persistentListOf())
|
||||
|
|
@ -76,6 +76,7 @@ class DefaultSelectUsersPresenter @Inject constructor() : SelectUsersPresenter {
|
|||
searchResults = searchResults.value,
|
||||
selectedUsers = selectedUsers.value,
|
||||
isSearchActive = isSearchActive,
|
||||
isMultiSelectionEnabled = isMultiSelectionEnabled,
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ import kotlinx.coroutines.test.runTest
|
|||
import org.junit.Test
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class DefaultSelectUsersPresenterTests {
|
||||
class DefaultSelectSingleUserPresenterTests {
|
||||
|
||||
@Test
|
||||
fun `present - initial state`() = runTest {
|
||||
val presenter = DefaultSelectUsersPresenter()
|
||||
val presenter = DefaultSelectSingleUserPresenter()
|
||||
moleculeFlow(RecompositionClock.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -43,7 +43,7 @@ class DefaultSelectUsersPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - update search query`() = runTest {
|
||||
val presenter = DefaultSelectUsersPresenter()
|
||||
val presenter = DefaultSelectSingleUserPresenter()
|
||||
moleculeFlow(RecompositionClock.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
Loading…
Add table
Add a link
Reference in a new issue