Browse Source

Ensure the application react correctly if analytics is disabled at compilation time.

pull/947/head
Benoit Marty 1 year ago
parent
commit
82258f12ba
  1. 1
      features/preferences/impl/build.gradle.kts
  2. 4
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt
  3. 1
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootState.kt
  4. 1
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootStateProvider.kt
  5. 2
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt
  6. 3
      features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenterTest.kt
  7. 2
      plugins/src/main/kotlin/extension/DependencyHandleScope.kt

1
features/preferences/impl/build.gradle.kts

@ -47,6 +47,7 @@ dependencies { @@ -47,6 +47,7 @@ dependencies {
implementation(projects.features.ftue.api)
implementation(projects.libraries.matrixui)
implementation(projects.features.logout.api)
implementation(projects.services.analytics.api)
implementation(projects.services.toolbox.api)
implementation(libs.datetime)
implementation(libs.accompanist.placeholder)

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

@ -35,6 +35,7 @@ import io.element.android.libraries.matrix.api.user.MatrixUser @@ -35,6 +35,7 @@ import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.matrix.api.user.getCurrentUser
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
import io.element.android.services.analytics.api.AnalyticsService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.inject.Inject
@ -43,6 +44,7 @@ class PreferencesRootPresenter @Inject constructor( @@ -43,6 +44,7 @@ class PreferencesRootPresenter @Inject constructor(
private val logoutPresenter: LogoutPreferencePresenter,
private val matrixClient: MatrixClient,
private val sessionVerificationService: SessionVerificationService,
private val analyticsService: AnalyticsService,
private val buildType: BuildType,
private val versionFormatter: VersionFormatter,
private val snackbarDispatcher: SnackbarDispatcher,
@ -58,6 +60,7 @@ class PreferencesRootPresenter @Inject constructor( @@ -58,6 +60,7 @@ class PreferencesRootPresenter @Inject constructor(
}
val snackbarMessage by snackbarDispatcher.collectSnackbarMessageAsState()
val hasAnalyticsProviders = remember { analyticsService.getAvailableAnalyticsProviders().isNotEmpty() }
// Session verification status (unknown, not verified, verified)
val sessionVerifiedStatus by sessionVerificationService.sessionVerifiedStatus.collectAsState()
@ -72,6 +75,7 @@ class PreferencesRootPresenter @Inject constructor( @@ -72,6 +75,7 @@ class PreferencesRootPresenter @Inject constructor(
myUser = matrixUser.value,
version = versionFormatter.get(),
showCompleteVerification = sessionIsNotVerified,
showAnalyticsSettings = hasAnalyticsProviders,
showDeveloperSettings = showDeveloperSettings,
snackbarMessage = snackbarMessage,
)

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

@ -25,6 +25,7 @@ data class PreferencesRootState( @@ -25,6 +25,7 @@ data class PreferencesRootState(
val myUser: MatrixUser?,
val version: String,
val showCompleteVerification: Boolean,
val showAnalyticsSettings: Boolean,
val showDeveloperSettings: Boolean,
val snackbarMessage: SnackbarMessage?,
)

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

@ -25,6 +25,7 @@ fun aPreferencesRootState() = PreferencesRootState( @@ -25,6 +25,7 @@ fun aPreferencesRootState() = PreferencesRootState(
myUser = null,
version = "Version 1.1 (1)",
showCompleteVerification = true,
showAnalyticsSettings = true,
showDeveloperSettings = true,
snackbarMessage = SnackbarMessage(CommonStrings.common_verification_complete),
)

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

@ -82,11 +82,13 @@ fun PreferencesRootView( @@ -82,11 +82,13 @@ fun PreferencesRootView(
)
Divider()
}
if (state.showAnalyticsSettings) {
PreferenceText(
title = stringResource(id = CommonStrings.common_analytics),
icon = Icons.Outlined.InsertChart,
onClick = onOpenAnalytics,
)
}
PreferenceText(
title = stringResource(id = CommonStrings.action_report_bug),
icon = Icons.Outlined.BugReport,

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

@ -20,6 +20,7 @@ import app.cash.molecule.RecompositionMode @@ -20,6 +20,7 @@ import app.cash.molecule.RecompositionMode
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.features.analytics.test.FakeAnalyticsService
import io.element.android.features.logout.impl.DefaultLogoutPreferencePresenter
import io.element.android.libraries.architecture.Async
import io.element.android.libraries.core.meta.BuildType
@ -41,6 +42,7 @@ class PreferencesRootPresenterTest { @@ -41,6 +42,7 @@ class PreferencesRootPresenterTest {
logoutPresenter,
matrixClient,
FakeSessionVerificationService(),
FakeAnalyticsService(),
BuildType.DEBUG,
FakeVersionFormatter(),
SnackbarDispatcher(),
@ -61,6 +63,7 @@ class PreferencesRootPresenterTest { @@ -61,6 +63,7 @@ class PreferencesRootPresenterTest {
)
)
assertThat(loadedState.showDeveloperSettings).isEqualTo(true)
assertThat(loadedState.showAnalyticsSettings).isEqualTo(false)
}
}
}

2
plugins/src/main/kotlin/extension/DependencyHandleScope.kt

@ -103,6 +103,8 @@ fun DependencyHandlerScope.allLibrariesImpl() { @@ -103,6 +103,8 @@ fun DependencyHandlerScope.allLibrariesImpl() {
}
fun DependencyHandlerScope.allServicesImpl() {
// For analytics configuration, either use noop, or use the impl, with at least one analyticsproviders implementation
// implementation(project(":services:analytics:noop"))
implementation(project(":services:analytics:impl"))
implementation(project(":services:analyticsproviders:posthog"))
implementation(project(":services:apperror:impl"))

Loading…
Cancel
Save