Address comments

- Add additional states to preview.
- Add TODO description for commented code
- Move showUserDefinedSettingStyle from the node to the view for testability.
This commit is contained in:
David Langley
2023-10-24 16:27:26 +01:00
parent 463ceba52c
commit 39af4d5e1b
9 changed files with 47 additions and 15 deletions

View File

@@ -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,

View File

@@ -27,11 +27,12 @@ open class EditDefaultNotificationSettingStateProvider: PreviewParameterProvider
override val values: Sequence<EditDefaultNotificationSettingState>
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,

View File

@@ -35,7 +35,7 @@ import io.element.android.services.analytics.api.AnalyticsService
class RoomNotificationSettingsNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
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<RoomNotificationSettingInput>()
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,
)
}
}
}

View File

@@ -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<RoomNotificationSettingsState> {
@AssistedFactory
interface Factory {
fun create(showUserDefinedSettingStyle: Boolean): RoomNotificationSettingsPresenter
}
@Composable
override fun present(): RoomNotificationSettingsState {
val defaultRoomNotificationMode: MutableState<RoomNotificationMode?> = rememberSaveable {
@@ -107,6 +116,7 @@ class RoomNotificationSettingsPresenter @Inject constructor(
}
return RoomNotificationSettingsState(
showUserDefinedSettingStyle = showUserDefinedSettingStyle,
roomName = room.displayName,
roomNotificationSettings = roomNotificationSettings.value,
pendingRoomNotificationMode = pendingRoomNotificationMode.value,

View File

@@ -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<RoomNotificationSettings>,
val pendingRoomNotificationMode: RoomNotificationMode?,

View File

@@ -25,6 +25,7 @@ internal class RoomNotificationSettingsStateProvider : PreviewParameterProvider<
override val values: Sequence<RoomNotificationSettingsState>
get() = sequenceOf(
RoomNotificationSettingsState(
showUserDefinedSettingStyle = false,
roomName = "Room 1",
Async.Success(RoomNotificationSettings(
mode = RoomNotificationMode.MUTE,

View File

@@ -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,

View File

@@ -25,6 +25,7 @@ internal class UserDefinedRoomNotificationSettingsStateProvider : PreviewParamet
override val values: Sequence<RoomNotificationSettingsState>
get() = sequenceOf(
RoomNotificationSettingsState(
showUserDefinedSettingStyle = false,
roomName = "Room 1",
Async.Success(
RoomNotificationSettings(

View File

@@ -136,7 +136,8 @@ class RoomNotificationSettingsPresenterTests {
val room = aMatrixRoom(notificationSettingsService = notificationSettingsService)
return RoomNotificationSettingsPresenter(
room = room,
notificationSettingsService = notificationSettingsService
notificationSettingsService = notificationSettingsService,
showUserDefinedSettingStyle = false,
)
}
}