Skip to content

Commit a100676

Browse files
committed
Remove dependencies to other presenters from PreferencesRootPresenter.
Also do some renaming since DirectLogoutPresenter interface can be removed.
1 parent e9e4963 commit a100676

File tree

8 files changed

+44
-54
lines changed

8 files changed

+44
-54
lines changed

features/logout/api/src/main/kotlin/io/element/android/features/logout/api/direct/DirectLogoutPresenter.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2024 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only
5+
* Please see LICENSE in the repository root for full details.
6+
*/
7+
8+
package io.element.android.features.logout.impl.di
9+
10+
import com.squareup.anvil.annotations.ContributesTo
11+
import dagger.Binds
12+
import dagger.Module
13+
import io.element.android.features.logout.api.direct.DirectLogoutState
14+
import io.element.android.features.logout.impl.direct.DirectLogoutPresenter
15+
import io.element.android.libraries.architecture.Presenter
16+
import io.element.android.libraries.di.SessionScope
17+
18+
@ContributesTo(SessionScope::class)
19+
@Module
20+
interface LogoutModule {
21+
@Binds
22+
fun bindDirectLogoutPresenter(presenter: DirectLogoutPresenter): Presenter<DirectLogoutState>
23+
}

features/logout/impl/src/main/kotlin/io/element/android/features/logout/impl/direct/DefaultDirectLogoutPresenter.kt renamed to features/logout/impl/src/main/kotlin/io/element/android/features/logout/impl/direct/DirectLogoutPresenter.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,23 @@ import androidx.compose.runtime.getValue
1414
import androidx.compose.runtime.mutableStateOf
1515
import androidx.compose.runtime.remember
1616
import androidx.compose.runtime.rememberCoroutineScope
17-
import com.squareup.anvil.annotations.ContributesBinding
1817
import io.element.android.features.logout.api.direct.DirectLogoutEvents
19-
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
2018
import io.element.android.features.logout.api.direct.DirectLogoutState
2119
import io.element.android.features.logout.impl.tools.isBackingUp
2220
import io.element.android.libraries.architecture.AsyncAction
21+
import io.element.android.libraries.architecture.Presenter
2322
import io.element.android.libraries.architecture.runCatchingUpdatingState
24-
import io.element.android.libraries.di.SessionScope
2523
import io.element.android.libraries.matrix.api.MatrixClient
2624
import io.element.android.libraries.matrix.api.encryption.BackupUploadState
2725
import io.element.android.libraries.matrix.api.encryption.EncryptionService
2826
import kotlinx.coroutines.CoroutineScope
2927
import kotlinx.coroutines.launch
3028
import javax.inject.Inject
3129

32-
@ContributesBinding(SessionScope::class)
33-
class DefaultDirectLogoutPresenter @Inject constructor(
30+
class DirectLogoutPresenter @Inject constructor(
3431
private val matrixClient: MatrixClient,
3532
private val encryptionService: EncryptionService,
36-
) : DirectLogoutPresenter {
33+
) : Presenter<DirectLogoutState> {
3734
@Composable
3835
override fun present(): DirectLogoutState {
3936
val localCoroutineScope = rememberCoroutineScope()

features/logout/impl/src/test/kotlin/io/element/android/features/logout/impl/direct/DefaultDirectLogoutPresenterTest.kt renamed to features/logout/impl/src/test/kotlin/io/element/android/features/logout/impl/direct/DirectLogoutPresenterTest.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import kotlinx.coroutines.test.runTest
2626
import org.junit.Rule
2727
import org.junit.Test
2828

29-
class DefaultDirectLogoutPresenterTest {
29+
class DirectLogoutPresenterTest {
3030
@get:Rule
3131
val warmUpRule = WarmUpRule()
3232

3333
@Test
3434
fun `present - initial state`() = runTest {
35-
val presenter = createDefaultDirectLogoutPresenter()
35+
val presenter = createDirectLogoutPresenter()
3636
moleculeFlow(RecompositionMode.Immediate) {
3737
presenter.present()
3838
}.test {
@@ -44,7 +44,7 @@ class DefaultDirectLogoutPresenterTest {
4444

4545
@Test
4646
fun `present - initial state - last session`() = runTest {
47-
val presenter = createDefaultDirectLogoutPresenter(
47+
val presenter = createDirectLogoutPresenter(
4848
encryptionService = FakeEncryptionService().apply {
4949
emitIsLastDevice(true)
5050
}
@@ -66,7 +66,7 @@ class DefaultDirectLogoutPresenterTest {
6666
emit(BackupUploadState.Waiting)
6767
}
6868
)
69-
val presenter = createDefaultDirectLogoutPresenter(
69+
val presenter = createDirectLogoutPresenter(
7070
encryptionService = encryptionService
7171
)
7272
moleculeFlow(RecompositionMode.Immediate) {
@@ -81,7 +81,7 @@ class DefaultDirectLogoutPresenterTest {
8181

8282
@Test
8383
fun `present - logout then cancel`() = runTest {
84-
val presenter = createDefaultDirectLogoutPresenter()
84+
val presenter = createDirectLogoutPresenter()
8585
moleculeFlow(RecompositionMode.Immediate) {
8686
presenter.present()
8787
}.test {
@@ -97,7 +97,7 @@ class DefaultDirectLogoutPresenterTest {
9797

9898
@Test
9999
fun `present - logout then confirm`() = runTest {
100-
val presenter = createDefaultDirectLogoutPresenter()
100+
val presenter = createDirectLogoutPresenter()
101101
moleculeFlow(RecompositionMode.Immediate) {
102102
presenter.present()
103103
}.test {
@@ -120,7 +120,7 @@ class DefaultDirectLogoutPresenterTest {
120120
throw A_THROWABLE
121121
}
122122
}
123-
val presenter = createDefaultDirectLogoutPresenter(
123+
val presenter = createDirectLogoutPresenter(
124124
matrixClient,
125125
)
126126
moleculeFlow(RecompositionMode.Immediate) {
@@ -152,7 +152,7 @@ class DefaultDirectLogoutPresenterTest {
152152
}
153153
}
154154
}
155-
val presenter = createDefaultDirectLogoutPresenter(
155+
val presenter = createDirectLogoutPresenter(
156156
matrixClient,
157157
)
158158
moleculeFlow(RecompositionMode.Immediate) {
@@ -179,10 +179,10 @@ class DefaultDirectLogoutPresenterTest {
179179
return awaitItem()
180180
}
181181

182-
private fun createDefaultDirectLogoutPresenter(
182+
private fun createDirectLogoutPresenter(
183183
matrixClient: MatrixClient = FakeMatrixClient(),
184184
encryptionService: EncryptionService = FakeEncryptionService(),
185-
): DefaultDirectLogoutPresenter = DefaultDirectLogoutPresenter(
185+
): DirectLogoutPresenter = DirectLogoutPresenter(
186186
matrixClient = matrixClient,
187187
encryptionService = encryptionService,
188188
)

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import androidx.compose.runtime.mutableStateOf
1616
import androidx.compose.runtime.produceState
1717
import androidx.compose.runtime.remember
1818
import androidx.compose.runtime.setValue
19-
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
19+
import io.element.android.features.logout.api.direct.DirectLogoutState
2020
import io.element.android.features.preferences.impl.utils.ShowDeveloperSettingsProvider
2121
import io.element.android.libraries.architecture.Presenter
2222
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher
@@ -42,7 +42,7 @@ class PreferencesRootPresenter @Inject constructor(
4242
private val snackbarDispatcher: SnackbarDispatcher,
4343
private val featureFlagService: FeatureFlagService,
4444
private val indicatorService: IndicatorService,
45-
private val directLogoutPresenter: DirectLogoutPresenter,
45+
private val directLogoutPresenter: Presenter<DirectLogoutState>,
4646
private val showDeveloperSettingsProvider: ShowDeveloperSettingsProvider,
4747
) : Presenter<PreferencesRootState> {
4848
@Composable

features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77

88
package io.element.android.features.preferences.impl.root
99

10-
import androidx.compose.runtime.Composable
1110
import app.cash.molecule.RecompositionMode
1211
import app.cash.molecule.moleculeFlow
1312
import app.cash.turbine.ReceiveTurbine
1413
import app.cash.turbine.test
1514
import com.google.common.truth.Truth.assertThat
16-
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
17-
import io.element.android.features.logout.api.direct.DirectLogoutState
15+
import io.element.android.features.logout.api.direct.aDirectLogoutState
1816
import io.element.android.features.preferences.impl.utils.ShowDeveloperSettingsProvider
19-
import io.element.android.libraries.architecture.AsyncAction
2017
import io.element.android.libraries.core.meta.BuildType
2118
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher
2219
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
@@ -38,12 +35,6 @@ class PreferencesRootPresenterTest {
3835
@get:Rule
3936
val warmUpRule = WarmUpRule()
4037

41-
private val aDirectLogoutState = DirectLogoutState(
42-
canDoDirectSignOut = true,
43-
logoutAction = AsyncAction.Uninitialized,
44-
eventSink = {},
45-
)
46-
4738
@Test
4839
fun `present - initial state`() = runTest {
4940
val matrixClient = FakeMatrixClient(canDeactivateAccountResult = { true })
@@ -78,7 +69,7 @@ class PreferencesRootPresenterTest {
7869
assertThat(loadedState.showLockScreenSettings).isTrue()
7970
assertThat(loadedState.showNotificationSettings).isTrue()
8071
assertThat(loadedState.canDeactivateAccount).isTrue()
81-
assertThat(loadedState.directLogoutState).isEqualTo(aDirectLogoutState)
72+
assertThat(loadedState.directLogoutState).isEqualTo(aDirectLogoutState())
8273
assertThat(loadedState.snackbarMessage).isNull()
8374
}
8475
}
@@ -148,10 +139,7 @@ class PreferencesRootPresenterTest {
148139
sessionVerificationService = sessionVerificationService,
149140
encryptionService = FakeEncryptionService(),
150141
),
151-
directLogoutPresenter = object : DirectLogoutPresenter {
152-
@Composable
153-
override fun present() = aDirectLogoutState
154-
},
142+
directLogoutPresenter = { aDirectLogoutState() },
155143
showDeveloperSettingsProvider = showDeveloperSettingsProvider,
156144
)
157145
}

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import io.element.android.features.invite.api.response.AcceptDeclineInviteState
2929
import io.element.android.features.invite.api.response.InviteData
3030
import io.element.android.features.leaveroom.api.LeaveRoomEvent
3131
import io.element.android.features.leaveroom.api.LeaveRoomPresenter
32-
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
32+
import io.element.android.features.logout.api.direct.DirectLogoutState
3333
import io.element.android.features.networkmonitor.api.NetworkMonitor
3434
import io.element.android.features.networkmonitor.api.NetworkStatus
3535
import io.element.android.features.roomlist.impl.datasource.RoomListDataSource
@@ -91,7 +91,7 @@ class RoomListPresenter @Inject constructor(
9191
private val acceptDeclineInvitePresenter: Presenter<AcceptDeclineInviteState>,
9292
private val fullScreenIntentPermissionsPresenter: FullScreenIntentPermissionsPresenter,
9393
private val notificationCleaner: NotificationCleaner,
94-
private val logoutPresenter: DirectLogoutPresenter,
94+
private val logoutPresenter: Presenter<DirectLogoutState>,
9595
) : Presenter<RoomListState> {
9696
private val encryptionService: EncryptionService = client.encryptionService()
9797
private val syncService: SyncService = client.syncService()

features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTest.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package io.element.android.features.roomlist.impl
99

10-
import androidx.compose.runtime.Composable
1110
import app.cash.molecule.RecompositionMode
1211
import app.cash.molecule.moleculeFlow
1312
import app.cash.turbine.test
@@ -19,7 +18,6 @@ import io.element.android.features.invite.api.response.anAcceptDeclineInviteStat
1918
import io.element.android.features.leaveroom.api.LeaveRoomEvent
2019
import io.element.android.features.leaveroom.api.LeaveRoomPresenter
2120
import io.element.android.features.leaveroom.fake.FakeLeaveRoomPresenter
22-
import io.element.android.features.logout.api.direct.DirectLogoutPresenter
2321
import io.element.android.features.logout.api.direct.aDirectLogoutState
2422
import io.element.android.features.networkmonitor.api.NetworkMonitor
2523
import io.element.android.features.networkmonitor.test.FakeNetworkMonitor
@@ -686,10 +684,6 @@ class RoomListPresenterTest {
686684
searchPresenter: Presenter<RoomListSearchState> = Presenter { aRoomListSearchState() },
687685
acceptDeclineInvitePresenter: Presenter<AcceptDeclineInviteState> = Presenter { anAcceptDeclineInviteState() },
688686
notificationCleaner: NotificationCleaner = FakeNotificationCleaner(),
689-
logoutPresenter: DirectLogoutPresenter = object : DirectLogoutPresenter {
690-
@Composable
691-
override fun present() = aDirectLogoutState()
692-
},
693687
) = RoomListPresenter(
694688
client = client,
695689
networkMonitor = networkMonitor,
@@ -717,6 +711,6 @@ class RoomListPresenterTest {
717711
acceptDeclineInvitePresenter = acceptDeclineInvitePresenter,
718712
fullScreenIntentPermissionsPresenter = FakeFullScreenIntentPermissionsPresenter(),
719713
notificationCleaner = notificationCleaner,
720-
logoutPresenter = logoutPresenter,
714+
logoutPresenter = { aDirectLogoutState() },
721715
)
722716
}

0 commit comments

Comments
 (0)