Remove dependencies to other presenters from PreferencesRootPresenter.

Also do some renaming since DirectLogoutPresenter interface can be removed.
This commit is contained in:
Benoit Marty 2024-10-07 09:02:05 +02:00 committed by Benoit Marty
parent e9e4963373
commit a100676f4b
8 changed files with 44 additions and 54 deletions

View file

@ -0,0 +1,23 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/
package io.element.android.features.logout.impl.di
import com.squareup.anvil.annotations.ContributesTo
import dagger.Binds
import dagger.Module
import io.element.android.features.logout.api.direct.DirectLogoutState
import io.element.android.features.logout.impl.direct.DirectLogoutPresenter
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.di.SessionScope
@ContributesTo(SessionScope::class)
@Module
interface LogoutModule {
@Binds
fun bindDirectLogoutPresenter(presenter: DirectLogoutPresenter): Presenter<DirectLogoutState>
}

View file

@ -14,14 +14,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.logout.api.direct.DirectLogoutEvents
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
import io.element.android.features.logout.api.direct.DirectLogoutState
import io.element.android.features.logout.impl.tools.isBackingUp
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.architecture.runCatchingUpdatingState
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.encryption.BackupUploadState
import io.element.android.libraries.matrix.api.encryption.EncryptionService
@ -29,11 +27,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.inject.Inject
@ContributesBinding(SessionScope::class)
class DefaultDirectLogoutPresenter @Inject constructor(
class DirectLogoutPresenter @Inject constructor(
private val matrixClient: MatrixClient,
private val encryptionService: EncryptionService,
) : DirectLogoutPresenter {
) : Presenter<DirectLogoutState> {
@Composable
override fun present(): DirectLogoutState {
val localCoroutineScope = rememberCoroutineScope()

View file

@ -26,13 +26,13 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class DefaultDirectLogoutPresenterTest {
class DirectLogoutPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()
@Test
fun `present - initial state`() = runTest {
val presenter = createDefaultDirectLogoutPresenter()
val presenter = createDirectLogoutPresenter()
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
@ -44,7 +44,7 @@ class DefaultDirectLogoutPresenterTest {
@Test
fun `present - initial state - last session`() = runTest {
val presenter = createDefaultDirectLogoutPresenter(
val presenter = createDirectLogoutPresenter(
encryptionService = FakeEncryptionService().apply {
emitIsLastDevice(true)
}
@ -66,7 +66,7 @@ class DefaultDirectLogoutPresenterTest {
emit(BackupUploadState.Waiting)
}
)
val presenter = createDefaultDirectLogoutPresenter(
val presenter = createDirectLogoutPresenter(
encryptionService = encryptionService
)
moleculeFlow(RecompositionMode.Immediate) {
@ -81,7 +81,7 @@ class DefaultDirectLogoutPresenterTest {
@Test
fun `present - logout then cancel`() = runTest {
val presenter = createDefaultDirectLogoutPresenter()
val presenter = createDirectLogoutPresenter()
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
@ -97,7 +97,7 @@ class DefaultDirectLogoutPresenterTest {
@Test
fun `present - logout then confirm`() = runTest {
val presenter = createDefaultDirectLogoutPresenter()
val presenter = createDirectLogoutPresenter()
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
@ -120,7 +120,7 @@ class DefaultDirectLogoutPresenterTest {
throw A_THROWABLE
}
}
val presenter = createDefaultDirectLogoutPresenter(
val presenter = createDirectLogoutPresenter(
matrixClient,
)
moleculeFlow(RecompositionMode.Immediate) {
@ -152,7 +152,7 @@ class DefaultDirectLogoutPresenterTest {
}
}
}
val presenter = createDefaultDirectLogoutPresenter(
val presenter = createDirectLogoutPresenter(
matrixClient,
)
moleculeFlow(RecompositionMode.Immediate) {
@ -179,10 +179,10 @@ class DefaultDirectLogoutPresenterTest {
return awaitItem()
}
private fun createDefaultDirectLogoutPresenter(
private fun createDirectLogoutPresenter(
matrixClient: MatrixClient = FakeMatrixClient(),
encryptionService: EncryptionService = FakeEncryptionService(),
): DefaultDirectLogoutPresenter = DefaultDirectLogoutPresenter(
): DirectLogoutPresenter = DirectLogoutPresenter(
matrixClient = matrixClient,
encryptionService = encryptionService,
)