From a86ec1a8fa20f8c69bd7fe4a8c551f7a99f09acb Mon Sep 17 00:00:00 2001 From: yostyle Date: Thu, 24 Aug 2023 15:43:10 +0200 Subject: [PATCH] Rebase on develop and refactoring --- .../api/preferences/AnalyticsPreferencesState.kt | 1 + .../preferences/impl/PreferencesFlowNode.kt | 12 ++++++------ ...ttingsNode.kt => NotificationSettingsNode.kt} | 16 +++++++++++++--- ...enter.kt => NotificationSettingsPresenter.kt} | 6 +++--- ...ingsState.kt => NotificationSettingsState.kt} | 2 +- ...r.kt => NotificationSettingsStateProvider.kt} | 8 ++++---- ...ttingsView.kt => NotificationSettingsView.kt} | 12 ++++++------ .../preferences/impl/root/PreferencesRootNode.kt | 2 +- .../preferences/impl/root/PreferencesRootView.kt | 2 +- .../impl/tasks/ComputeCacheSizeUseCase.kt | 2 +- 10 files changed, 37 insertions(+), 26 deletions(-) rename features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/{NotificationsSettingsNode.kt => NotificationSettingsNode.kt} (71%) rename features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/{NotificationsSettingsPresenter.kt => NotificationSettingsPresenter.kt} (82%) rename features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/{NotificationsSettingsState.kt => NotificationSettingsState.kt} (95%) rename features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/{NotificationsSettingsStateProvider.kt => NotificationSettingsStateProvider.kt} (76%) rename features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/{NotificationsSettingsView.kt => NotificationSettingsView.kt} (93%) diff --git a/features/analytics/api/src/main/kotlin/io/element/android/features/analytics/api/preferences/AnalyticsPreferencesState.kt b/features/analytics/api/src/main/kotlin/io/element/android/features/analytics/api/preferences/AnalyticsPreferencesState.kt index 11622ea20d..7cf0f51dfd 100644 --- a/features/analytics/api/src/main/kotlin/io/element/android/features/analytics/api/preferences/AnalyticsPreferencesState.kt +++ b/features/analytics/api/src/main/kotlin/io/element/android/features/analytics/api/preferences/AnalyticsPreferencesState.kt @@ -21,4 +21,5 @@ import io.element.android.features.analytics.api.AnalyticsOptInEvents data class AnalyticsPreferencesState( val applicationName: String, val isEnabled: Boolean, + val eventSink: (AnalyticsOptInEvents) -> Unit, ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt index f6e4a88f87..00684dde13 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt @@ -33,7 +33,7 @@ import io.element.android.features.preferences.api.PreferencesEntryPoint import io.element.android.features.preferences.impl.about.AboutNode import io.element.android.features.preferences.impl.analytics.AnalyticsSettingsNode import io.element.android.features.preferences.impl.developer.DeveloperSettingsNode -import io.element.android.features.preferences.impl.notifications.NotificationsSettingsNode +import io.element.android.features.preferences.impl.notifications.NotificationSettingsNode import io.element.android.features.preferences.impl.root.PreferencesRootNode import io.element.android.libraries.architecture.BackstackNode import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler @@ -68,7 +68,7 @@ class PreferencesFlowNode @AssistedInject constructor( object About : NavTarget @Parcelize - object NotificationsSettings : NavTarget + object NotificationSettings : NavTarget } override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node { @@ -95,8 +95,8 @@ class PreferencesFlowNode @AssistedInject constructor( backstack.push(NavTarget.DeveloperSettings) } - override fun onOpenNotificationsSettings() { - backstack.push(NavTarget.NotificationsSettings) + override fun onOpenNotificationSettings() { + backstack.push(NavTarget.NotificationSettings) } } createNode(buildContext, plugins = listOf(callback)) @@ -110,8 +110,8 @@ class PreferencesFlowNode @AssistedInject constructor( NavTarget.AnalyticsSettings -> { createNode(buildContext) } - NavTarget.NotificationsSettings -> { - createNode(buildContext) + NavTarget.NotificationSettings -> { + createNode(buildContext) } } } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsNode.kt similarity index 71% rename from features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsNode.kt rename to features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsNode.kt index 409b2e4af3..d0db81ea7a 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsNode.kt @@ -16,6 +16,8 @@ package io.element.android.features.preferences.impl.notifications +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import com.bumble.appyx.core.modality.BuildContext import com.bumble.appyx.core.node.Node import com.bumble.appyx.core.plugin.Plugin @@ -25,10 +27,18 @@ import io.element.android.anvilannotations.ContributesNode import io.element.android.libraries.di.SessionScope @ContributesNode(SessionScope::class) -class NotificationsSettingsNode @AssistedInject constructor( +class NotificationSettingsNode @AssistedInject constructor( @Assisted buildContext: BuildContext, @Assisted plugins: List, - private val presenter: NotificationsSettingsPresenter, + private val presenter: NotificationSettingsPresenter, ) : Node(buildContext, plugins = plugins) { - + @Composable + override fun View(modifier: Modifier) { + val state = presenter.present() + NotificationSettingsView( + state = state, + onBackPressed = ::navigateUp, + modifier = modifier + ) + } } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt similarity index 82% rename from features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsPresenter.kt rename to features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt index e9ed425e40..255284f003 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt @@ -20,11 +20,11 @@ import androidx.compose.runtime.Composable import io.element.android.libraries.architecture.Presenter import javax.inject.Inject -class NotificationsSettingsPresenter @Inject constructor() : Presenter { +class NotificationSettingsPresenter @Inject constructor() : Presenter { @Composable - override fun present(): NotificationsSettingsState { - return NotificationsSettingsState( + override fun present(): NotificationSettingsState { + return NotificationSettingsState( isEnabled = true, hasSystemPermission = true, notifyMeOnRoom = true, diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsState.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt similarity index 95% rename from features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsState.kt rename to features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt index 33c9cfc2f0..ca65fcf5d0 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsState.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt @@ -16,7 +16,7 @@ package io.element.android.features.preferences.impl.notifications -data class NotificationsSettingsState( +data class NotificationSettingsState( val hasSystemPermission: Boolean, val isEnabled: Boolean, val notifyMeOnRoom: Boolean, diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt similarity index 76% rename from features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsStateProvider.kt rename to features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt index 5d74a519e9..c6c72f3acc 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt @@ -18,14 +18,14 @@ package io.element.android.features.preferences.impl.notifications import androidx.compose.ui.tooling.preview.PreviewParameterProvider -open class NotificationsSettingsStateProvider : PreviewParameterProvider { - override val values: Sequence +open class NotificationSettingsStateProvider : PreviewParameterProvider { + override val values: Sequence get() = sequenceOf( - aNotificationsSettingsState(), + aNotificationSettingsState(), ) } -fun aNotificationsSettingsState() = NotificationsSettingsState( +fun aNotificationSettingsState() = NotificationSettingsState( isEnabled = true, hasSystemPermission = false, notifyMeOnRoom = true, diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt similarity index 93% rename from features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsView.kt rename to features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt index 7b0fb6aa46..8789e70cc5 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationsSettingsView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt @@ -33,8 +33,8 @@ import io.element.android.libraries.designsystem.preview.ElementPreviewLight import io.element.android.libraries.ui.strings.CommonStrings @Composable -fun NotificationsSettingsView( - state: NotificationsSettingsState, +fun NotificationSettingsView( + state: NotificationSettingsState, onBackPressed: () -> Unit, modifier: Modifier = Modifier, ) { @@ -100,17 +100,17 @@ fun NotificationsSettingsView( @Preview @Composable -internal fun AboutViewLightPreview(@PreviewParameter(NotificationsSettingsStateProvider::class) state: NotificationsSettingsState) = +internal fun AboutViewLightPreview(@PreviewParameter(NotificationSettingsStateProvider::class) state: NotificationSettingsState) = ElementPreviewLight { ContentToPreview(state) } @Preview @Composable -internal fun AboutViewDarkPreview(@PreviewParameter(NotificationsSettingsStateProvider::class) state: NotificationsSettingsState) = +internal fun AboutViewDarkPreview(@PreviewParameter(NotificationSettingsStateProvider::class) state: NotificationSettingsState) = ElementPreviewDark { ContentToPreview(state) } @Composable -private fun ContentToPreview(state: NotificationsSettingsState) { - NotificationsSettingsView( +private fun ContentToPreview(state: NotificationSettingsState) { + NotificationSettingsView( state = state, onBackPressed = {}, ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootNode.kt index 09b488294e..0f297d14dd 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootNode.kt @@ -44,7 +44,7 @@ class PreferencesRootNode @AssistedInject constructor( fun onOpenAnalytics() fun onOpenAbout() fun onOpenDeveloperSettings() - fun onOpenNotificationsSettings() + fun onOpenNotificationSettings() } private fun onOpenBugReport() { diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt index 7c2e80ef52..d4783cde1f 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt @@ -97,7 +97,7 @@ fun PreferencesRootView( PreferenceText( title = stringResource(id = CommonStrings.screen_notification_settings_title), icon = Icons.Outlined.Notifications, - onClick = onOpenNotificationsSettings, + onClick = onOpenNotificationSettings, ) PreferenceText( title = stringResource(id = CommonStrings.action_report_bug), diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/tasks/ComputeCacheSizeUseCase.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/tasks/ComputeCacheSizeUseCase.kt index 661f6493ec..0eb6e5b613 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/tasks/ComputeCacheSizeUseCase.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/tasks/ComputeCacheSizeUseCase.kt @@ -18,8 +18,8 @@ package io.element.android.features.preferences.impl.tasks import android.content.Context import com.squareup.anvil.annotations.ContributesBinding -import io.element.android.libraries.androidutils.filesize.FileSizeFormatter import io.element.android.libraries.androidutils.file.getSizeOfFiles +import io.element.android.libraries.androidutils.filesize.FileSizeFormatter import io.element.android.libraries.core.coroutine.CoroutineDispatchers import io.element.android.libraries.di.ApplicationContext import io.element.android.libraries.di.SessionScope