diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt index c6680ed819..223107226e 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt @@ -89,6 +89,7 @@ fun NotificationSettingsView( onGroupChatsClicked = { onOpenEditDefault(false) }, onDirectChatsClicked = { onOpenEditDefault(true) }, onMentionNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetAtRoomNotificationsEnabled(it)) }, + // TODO We are removing the call notification toggle until support for call notifications has been added // onCallsNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetCallNotificationsEnabled(it)) }, ) } @@ -116,6 +117,7 @@ private fun NotificationSettingsContentView( onGroupChatsClicked: () -> Unit, onDirectChatsClicked: () -> Unit, onMentionNotificationsChanged: (Boolean) -> Unit, + // TODO We are removing the call notification toggle until support for call notifications has been added // onCallsNotificationsChanged: (Boolean) -> Unit, modifier: Modifier = Modifier, ) { @@ -166,7 +168,7 @@ private fun NotificationSettingsContentView( onCheckedChange = onMentionNotificationsChanged ) } - // We are removing the call notification toggle until call support has been added + // TODO We are removing the call notification toggle until support for call notifications has been added // PreferenceCategory(title = stringResource(id = CommonStrings.screen_notification_settings_additional_settings_section_title)) { // PreferenceSwitch( // modifier = Modifier, diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/edit/EditDefaultNotificationSettingStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/edit/EditDefaultNotificationSettingStateProvider.kt index 2b1236f4af..2ff02c008c 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/edit/EditDefaultNotificationSettingStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/edit/EditDefaultNotificationSettingStateProvider.kt @@ -27,11 +27,12 @@ open class EditDefaultNotificationSettingStateProvider: PreviewParameterProvider override val values: Sequence get() = sequenceOf( anEditDefaultNotificationSettingsState(), + anEditDefaultNotificationSettingsState(isOneToOne = true) ) } -fun anEditDefaultNotificationSettingsState() = EditDefaultNotificationSettingState( - isOneToOne = false, +fun anEditDefaultNotificationSettingsState(isOneToOne: Boolean = false) = EditDefaultNotificationSettingState( + isOneToOne = isOneToOne, mode = RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY, roomsWithUserDefinedMode = listOf(aRoomSummary()), changeNotificationSettingAction = Async.Uninitialized, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsNode.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsNode.kt index cb0168a42b..5972314ea4 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsNode.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsNode.kt @@ -35,7 +35,7 @@ import io.element.android.services.analytics.api.AnalyticsService class RoomNotificationSettingsNode @AssistedInject constructor( @Assisted buildContext: BuildContext, @Assisted plugins: List, - private val presenter: RoomNotificationSettingsPresenter, + presenterFactory: RoomNotificationSettingsPresenter.Factory, private val analyticsService: AnalyticsService, ) : Node(buildContext, plugins = plugins) { @@ -45,6 +45,7 @@ class RoomNotificationSettingsNode @AssistedInject constructor( private val inputs = inputs() + private val presenter = presenterFactory.create(inputs.showUserDefinedSettingStyle) init { lifecycle.subscribe( onResume = { @@ -56,18 +57,10 @@ class RoomNotificationSettingsNode @AssistedInject constructor( @Composable override fun View(modifier: Modifier) { val state = presenter.present() - if(inputs.showUserDefinedSettingStyle) { - UserDefinedRoomNotificationSettingsView( - state = state, - modifier = modifier, - onBackPressed = this::navigateUp, - ) - } else { RoomNotificationSettingsView( state = state, modifier = modifier, onBackPressed = this::navigateUp, ) - } } } diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt index 3086d878c4..a75ea94e39 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt @@ -23,6 +23,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject import io.element.android.libraries.architecture.Async import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.runCatchingUpdatingState @@ -36,13 +39,19 @@ import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import javax.inject.Inject import kotlin.time.Duration.Companion.seconds -class RoomNotificationSettingsPresenter @Inject constructor( +class RoomNotificationSettingsPresenter @AssistedInject constructor( private val room: MatrixRoom, private val notificationSettingsService: NotificationSettingsService, + @Assisted private val showUserDefinedSettingStyle: Boolean, ) : Presenter { + + @AssistedFactory + interface Factory { + fun create(showUserDefinedSettingStyle: Boolean): RoomNotificationSettingsPresenter + } + @Composable override fun present(): RoomNotificationSettingsState { val defaultRoomNotificationMode: MutableState = rememberSaveable { @@ -107,6 +116,7 @@ class RoomNotificationSettingsPresenter @Inject constructor( } return RoomNotificationSettingsState( + showUserDefinedSettingStyle = showUserDefinedSettingStyle, roomName = room.displayName, roomNotificationSettings = roomNotificationSettings.value, pendingRoomNotificationMode = pendingRoomNotificationMode.value, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsState.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsState.kt index 1f8c7e4ce8..ea51636eb3 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsState.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsState.kt @@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode import io.element.android.libraries.matrix.api.room.RoomNotificationSettings data class RoomNotificationSettingsState( + val showUserDefinedSettingStyle: Boolean, val roomName: String, val roomNotificationSettings: Async, val pendingRoomNotificationMode: RoomNotificationMode?, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsStateProvider.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsStateProvider.kt index 961909f933..a7faa52210 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsStateProvider.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsStateProvider.kt @@ -25,6 +25,7 @@ internal class RoomNotificationSettingsStateProvider : PreviewParameterProvider< override val values: Sequence get() = sequenceOf( RoomNotificationSettingsState( + showUserDefinedSettingStyle = false, roomName = "Room 1", Async.Success(RoomNotificationSettings( mode = RoomNotificationMode.MUTE, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt index 3d95e4ec20..43e736137e 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt @@ -45,11 +45,33 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode import io.element.android.libraries.theme.ElementTheme import io.element.android.libraries.ui.strings.CommonStrings + @Composable fun RoomNotificationSettingsView( state: RoomNotificationSettingsState, modifier: Modifier = Modifier, onBackPressed: () -> Unit = {}, +) { + if(state.showUserDefinedSettingStyle) { + UserDefinedRoomNotificationSettingsView( + state = state, + modifier = modifier, + onBackPressed = onBackPressed, + ) + } else { + RoomSpecificNotificationSettingsView( + state = state, + modifier = modifier, + onBackPressed = onBackPressed, + ) + } +} + +@Composable +private fun RoomSpecificNotificationSettingsView( + state: RoomNotificationSettingsState, + modifier: Modifier = Modifier, + onBackPressed: () -> Unit = {}, ) { Scaffold( modifier = modifier, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/UserDefinedRoomNotificationSettingsStateProvider.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/UserDefinedRoomNotificationSettingsStateProvider.kt index 76714a82d0..59181f4d9c 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/UserDefinedRoomNotificationSettingsStateProvider.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/UserDefinedRoomNotificationSettingsStateProvider.kt @@ -25,6 +25,7 @@ internal class UserDefinedRoomNotificationSettingsStateProvider : PreviewParamet override val values: Sequence get() = sequenceOf( RoomNotificationSettingsState( + showUserDefinedSettingStyle = false, roomName = "Room 1", Async.Success( RoomNotificationSettings( diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/notificationsettings/RoomNotificationSettingsPresenterTests.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/notificationsettings/RoomNotificationSettingsPresenterTests.kt index 7f4ea57cf1..31d7973109 100644 --- a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/notificationsettings/RoomNotificationSettingsPresenterTests.kt +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/notificationsettings/RoomNotificationSettingsPresenterTests.kt @@ -136,7 +136,8 @@ class RoomNotificationSettingsPresenterTests { val room = aMatrixRoom(notificationSettingsService = notificationSettingsService) return RoomNotificationSettingsPresenter( room = room, - notificationSettingsService = notificationSettingsService + notificationSettingsService = notificationSettingsService, + showUserDefinedSettingStyle = false, ) } }