diff --git a/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt b/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt index 4b2d476cc..e89a30777 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/ComposeNotificationHost.kt @@ -6,12 +6,14 @@ package org.schabi.newpipe.settings import android.content.Context +import android.content.Intent import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map import kotlinx.coroutines.reactive.asFlow import net.newpipe.app.model.ChannelNotificationCount import net.newpipe.app.platform.NotificationHost +import org.schabi.newpipe.App import org.schabi.newpipe.database.subscription.NotificationMode import org.schabi.newpipe.error.ErrorInfo import org.schabi.newpipe.error.ErrorUtil @@ -20,6 +22,7 @@ import org.schabi.newpipe.local.feed.notifications.NotificationHelper import org.schabi.newpipe.local.feed.notifications.NotificationWorker import org.schabi.newpipe.local.feed.notifications.ScheduleOptions import org.schabi.newpipe.local.subscription.SubscriptionManager +import org.schabi.newpipe.player.notification.NotificationConstants class ComposeNotificationHost(private val context: Context) : NotificationHost { @@ -33,6 +36,10 @@ class ComposeNotificationHost(private val context: Context) : NotificationHost { } } + override fun recreatePlayerNotification() = context.sendBroadcast( + Intent(NotificationConstants.ACTION_RECREATE_NOTIFICATION).setPackage(App.PACKAGE_NAME) + ) + override fun applyNewStreamsCheckSchedule() = NotificationWorker.schedule(context, ScheduleOptions.from(context), force = true) override fun channelNotificationCounts(): Flow = SubscriptionManager(context) diff --git a/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidNotificationActions.kt b/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidNotificationActions.kt index a43996802..559bd4577 100644 --- a/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidNotificationActions.kt +++ b/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidNotificationActions.kt @@ -25,6 +25,13 @@ class AndroidNotificationActions(private val context: Context) : NotificationAct override val isPlayerNotificationExempt: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU + override val hasSystemMediaControls: Boolean + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU + + override fun recreatePlayerNotification() { + host?.recreatePlayerNotification() + } + override fun areNotificationsEnabledOnDevice(): Boolean = host?.areNotificationsEnabledOnDevice() ?: true override fun openSystemNotificationSettings() { diff --git a/shared/src/androidMain/kotlin/net/newpipe/app/platform/NotificationHost.kt b/shared/src/androidMain/kotlin/net/newpipe/app/platform/NotificationHost.kt index af7a23794..64334629f 100644 --- a/shared/src/androidMain/kotlin/net/newpipe/app/platform/NotificationHost.kt +++ b/shared/src/androidMain/kotlin/net/newpipe/app/platform/NotificationHost.kt @@ -20,4 +20,6 @@ interface NotificationHost { fun applyNewStreamsCheckSchedule() fun channelNotificationCounts(): Flow + + fun recreatePlayerNotification() } diff --git a/shared/src/commonMain/composeResources/drawable/ic_close.xml b/shared/src/commonMain/composeResources/drawable/ic_close.xml new file mode 100644 index 000000000..bc1111289 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_close.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_fast_forward.xml b/shared/src/commonMain/composeResources/drawable/ic_fast_forward.xml new file mode 100644 index 000000000..909055ad3 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_fast_forward.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_fast_rewind.xml b/shared/src/commonMain/composeResources/drawable/ic_fast_rewind.xml new file mode 100644 index 000000000..57f1d9f20 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_fast_rewind.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_hourglass_top.xml b/shared/src/commonMain/composeResources/drawable/ic_hourglass_top.xml new file mode 100644 index 000000000..dfc8fa27f --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_hourglass_top.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_next.xml b/shared/src/commonMain/composeResources/drawable/ic_next.xml new file mode 100644 index 000000000..b4c240381 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_next.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_pause.xml b/shared/src/commonMain/composeResources/drawable/ic_pause.xml new file mode 100644 index 000000000..5df38e1e4 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_pause.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_previous.xml b/shared/src/commonMain/composeResources/drawable/ic_previous.xml new file mode 100644 index 000000000..f3231893a --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_previous.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_repeat.xml b/shared/src/commonMain/composeResources/drawable/ic_repeat.xml new file mode 100644 index 000000000..6cd046184 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_repeat.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/drawable/ic_shuffle.xml b/shared/src/commonMain/composeResources/drawable/ic_shuffle.xml new file mode 100644 index 000000000..1b5745136 --- /dev/null +++ b/shared/src/commonMain/composeResources/drawable/ic_shuffle.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/shared/src/commonMain/composeResources/values/strings.xml b/shared/src/commonMain/composeResources/values/strings.xml index 78624058b..85bc268b4 100644 --- a/shared/src/commonMain/composeResources/values/strings.xml +++ b/shared/src/commonMain/composeResources/values/strings.xml @@ -327,6 +327,33 @@ Channels Notifications are disabled + + Crop thumbnail to 1:1 aspect ratio + Crop the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio + Colorize notification + Have Android customize the notification's color according to the main color in the thumbnail (note that this is not available on all devices) + Show thumbnail + Use thumbnail for both lock screen background and notifications + First action button + Second action button + Third action button + Fourth action button + Fifth action button + Edit each notification action below by tapping on it. Select up to three of them to be shown in the compact notification by using the checkboxes on the right. + Edit each notification action below by tapping on it. The first three actions (play/pause, previous and next) are set by the system and cannot be customized. + You can select at most three actions to show in the compact notification! + Nothing + Previous + Next + Rewind + Fast forward + Play + Pause + Buffering + Repeat + Shuffle + Close + Updates Show a notification to prompt app update when a new version is available diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/composable/NotificationActionSlot.kt b/shared/src/commonMain/kotlin/net/newpipe/app/composable/NotificationActionSlot.kt new file mode 100644 index 000000000..00ec7393e --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/composable/NotificationActionSlot.kt @@ -0,0 +1,172 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.composable + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.selection.selectable +import androidx.compose.foundation.selection.selectableGroup +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Checkbox +import androidx.compose.material3.Icon +import androidx.compose.material3.ListItem +import androidx.compose.material3.RadioButton +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.isTraversalGroup +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.tooling.preview.PreviewLightDark +import androidx.compose.ui.tooling.preview.PreviewWrapper +import androidx.compose.ui.unit.dp +import net.newpipe.app.model.NotificationAction +import net.newpipe.app.preview.ThemePreviewProvider +import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.cancel +import newpipe.shared.generated.resources.notification_action_0_title +import newpipe.shared.generated.resources.notification_action_3_title +import org.jetbrains.compose.resources.painterResource +import org.jetbrains.compose.resources.stringResource + +private const val LABEL_SEPARATOR = " • " + +@Composable +fun NotificationActionSlot( + title: String, + action: NotificationAction, + onActionChange: (NotificationAction) -> Unit, + modifier: Modifier = Modifier, + compact: Boolean? = null, + onCompactToggle: () -> Unit = {} +) { + var showDialog by remember { mutableStateOf(false) } + + Row( + modifier = modifier + .fillMaxWidth() + .semantics { isTraversalGroup = true }, + verticalAlignment = Alignment.CenterVertically + ) { + ListItem( + modifier = Modifier + .weight(1f) + .clickable { showDialog = true }, + headlineContent = { Text(text = title) }, + supportingContent = { Text(text = action.title()) }, + leadingContent = { + Box(modifier = Modifier.size(24.dp)) { + action.icon?.let { icon -> Icon(painter = painterResource(icon), contentDescription = null) } + } + } + ) + compact?.let { checked -> + Checkbox( + checked = checked, + onCheckedChange = { onCompactToggle() }, + modifier = Modifier.padding(end = 8.dp) + ) + } + } + + if (showDialog) { + NotificationActionDialog( + title = title, + selectedAction = action, + onActionSelected = { selected -> + onActionChange(selected) + showDialog = false + }, + onDismiss = { showDialog = false } + ) + } +} + +@Composable +private fun NotificationActionDialog( + title: String, + selectedAction: NotificationAction, + onActionSelected: (NotificationAction) -> Unit, + onDismiss: () -> Unit +) { + AlertDialog( + onDismissRequest = onDismiss, + title = { Text(text = title) }, + text = { + Column(modifier = Modifier.selectableGroup().verticalScroll(rememberScrollState())) { + NotificationAction.entries.forEach { action -> + Row( + modifier = Modifier + .fillMaxWidth() + .selectable( + selected = action == selectedAction, + role = Role.RadioButton, + onClick = { onActionSelected(action) } + ) + .padding(vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically + ) { + RadioButton(selected = action == selectedAction, onClick = null) + Text( + text = action.title(), + modifier = Modifier + .weight(1f) + .padding(horizontal = 16.dp) + ) + action.icon?.let { icon -> Icon(painter = painterResource(icon), contentDescription = null) } + } + } + } + }, + confirmButton = { + TextButton(onClick = onDismiss) { + Text(text = stringResource(Res.string.cancel)) + } + } + ) +} + +@Composable +private fun NotificationAction.title(): String = labels + .map { label -> stringResource(label) } + .joinToString(separator = LABEL_SEPARATOR) + +@PreviewWrapper(ThemePreviewProvider::class) +@PreviewLightDark +@Composable +private fun NotificationActionSlotPreviewWithMultipleLabels() { + NotificationActionSlot( + title = stringResource(Res.string.notification_action_0_title), + action = NotificationAction.SMART_REWIND_PREVIOUS, + onActionChange = {}, + compact = true + ) +} + +@PreviewWrapper(ThemePreviewProvider::class) +@PreviewLightDark +@Composable +private fun NotificationActionSlotPreviewWithSingleLabel() { + NotificationActionSlot( + title = stringResource(Res.string.notification_action_3_title), + action = NotificationAction.REPEAT, + onActionChange = {}, + compact = false + ) +} diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/model/NotificationAction.kt b/shared/src/commonMain/kotlin/net/newpipe/app/model/NotificationAction.kt new file mode 100644 index 000000000..88714af77 --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/model/NotificationAction.kt @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.model + +/** + * Actions that can be placed in a slot of the player notification + */ + +import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.close +import newpipe.shared.generated.resources.ic_close +import newpipe.shared.generated.resources.ic_fast_forward +import newpipe.shared.generated.resources.ic_fast_rewind +import newpipe.shared.generated.resources.ic_hourglass_top +import newpipe.shared.generated.resources.ic_next +import newpipe.shared.generated.resources.ic_pause +import newpipe.shared.generated.resources.ic_previous +import newpipe.shared.generated.resources.ic_repeat +import newpipe.shared.generated.resources.ic_shuffle +import newpipe.shared.generated.resources.notification_action_buffering +import newpipe.shared.generated.resources.notification_action_fast_forward +import newpipe.shared.generated.resources.notification_action_next +import newpipe.shared.generated.resources.notification_action_nothing +import newpipe.shared.generated.resources.notification_action_pause +import newpipe.shared.generated.resources.notification_action_play +import newpipe.shared.generated.resources.notification_action_previous +import newpipe.shared.generated.resources.notification_action_repeat +import newpipe.shared.generated.resources.notification_action_rewind +import newpipe.shared.generated.resources.notification_action_shuffle +import org.jetbrains.compose.resources.DrawableResource +import org.jetbrains.compose.resources.StringResource + +/** + * Actions that can be placed in a slot of the player notification + * @param id Value stored in the preferences, shared with the current Android app + * @param labels Names of the actions combined in this slot, shown joined together + * @param icon Icon shown next to the action, if any + */ +enum class NotificationAction( + val id: Int, + val labels: List, + val icon: DrawableResource? +) { + NOTHING( + id = 0, + labels = listOf(Res.string.notification_action_nothing), + icon = null + ), + PREVIOUS( + id = 1, + labels = listOf(Res.string.notification_action_previous), + icon = Res.drawable.ic_previous + ), + NEXT( + id = 2, + labels = listOf(Res.string.notification_action_next), + icon = Res.drawable.ic_next + ), + REWIND( + id = 3, + labels = listOf(Res.string.notification_action_rewind), + icon = Res.drawable.ic_fast_rewind + ), + FORWARD( + id = 4, + labels = listOf(Res.string.notification_action_fast_forward), + icon = Res.drawable.ic_fast_forward + ), + SMART_REWIND_PREVIOUS( + id = 5, + labels = listOf(Res.string.notification_action_rewind, Res.string.notification_action_previous), + icon = Res.drawable.ic_previous + ), + SMART_FORWARD_NEXT( + id = 6, + labels = listOf(Res.string.notification_action_fast_forward, Res.string.notification_action_next), + icon = Res.drawable.ic_next + ), + PLAY_PAUSE( + id = 7, + labels = listOf(Res.string.notification_action_play, Res.string.notification_action_pause), + icon = Res.drawable.ic_pause + ), + PLAY_PAUSE_BUFFERING( + id = 8, + labels = listOf( + Res.string.notification_action_play, + Res.string.notification_action_pause, + Res.string.notification_action_buffering + ), + icon = Res.drawable.ic_hourglass_top + ), + REPEAT( + id = 9, + labels = listOf(Res.string.notification_action_repeat), + icon = Res.drawable.ic_repeat + ), + SHUFFLE( + id = 10, + labels = listOf(Res.string.notification_action_shuffle), + icon = Res.drawable.ic_shuffle + ), + CLOSE( + id = 11, + labels = listOf(Res.string.close), + icon = Res.drawable.ic_close + ); + + companion object { + fun fromId(id: Int): NotificationAction = entries.firstOrNull { action -> + action.id == id + } ?: NOTHING + } +} diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/navigation/Destination.kt b/shared/src/commonMain/kotlin/net/newpipe/app/navigation/Destination.kt index 715be227c..6f0dbdb78 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/navigation/Destination.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/navigation/Destination.kt @@ -17,6 +17,9 @@ sealed interface Destination : NavKey { @Serializable data object BackupRestoreSettings : Destination + @Serializable + data object PlayerNotificationSettings : Destination + @Serializable data object UpdateSettings : Destination diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/navigation/NavModule.kt b/shared/src/commonMain/kotlin/net/newpipe/app/navigation/NavModule.kt index 948e2c3b8..615be474e 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/navigation/NavModule.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/navigation/NavModule.kt @@ -15,6 +15,7 @@ import net.newpipe.app.screen.settings.DebugSettingsScreen import net.newpipe.app.screen.settings.DownloadSettingsScreen import net.newpipe.app.screen.settings.HistorySettingsScreen import net.newpipe.app.screen.settings.NotificationSettingsScreen +import net.newpipe.app.screen.settings.PlayerNotificationSettingsScreen import net.newpipe.app.screen.settings.PlayerSettingsScreen import net.newpipe.app.screen.settings.SettingsHomeScreen import net.newpipe.app.screen.settings.UpdateSettingsScreen @@ -82,6 +83,10 @@ fun navModule() = module { navigation { BackupRestoreSettingsScreen() } + + navigation { + PlayerNotificationSettingsScreen() + } } /** diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/platform/NotificationActions.kt b/shared/src/commonMain/kotlin/net/newpipe/app/platform/NotificationActions.kt index 8763beaef..15b4d5086 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/platform/NotificationActions.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/platform/NotificationActions.kt @@ -17,6 +17,8 @@ interface NotificationActions { val isPlayerNotificationExempt: Boolean + val hasSystemMediaControls: Boolean + fun areNotificationsEnabledOnDevice(): Boolean fun openSystemNotificationSettings() @@ -26,12 +28,16 @@ interface NotificationActions { fun applyNewStreamsCheckSchedule() fun channelNotificationCounts(): Flow + + fun recreatePlayerNotification() } internal object NoOpNotificationActions : NotificationActions { override val isPlayerNotificationExempt = false + override val hasSystemMediaControls = false + override fun areNotificationsEnabledOnDevice() = true override fun openSystemNotificationSettings() = logUnsupported("openSystemNotificationSettings") @@ -42,5 +48,7 @@ internal object NoOpNotificationActions : NotificationActions { override fun channelNotificationCounts(): Flow = emptyFlow() + override fun recreatePlayerNotification() = logUnsupported("recreatePlayerNotification") + private fun logUnsupported(action: String) = Logger.w(messageString = "Notification action '$action' is unsupported on this platform") } diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/preferences/PlayerNotificationPreferences.kt b/shared/src/commonMain/kotlin/net/newpipe/app/preferences/PlayerNotificationPreferences.kt new file mode 100644 index 000000000..29d79ac5b --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/preferences/PlayerNotificationPreferences.kt @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.preferences + +import net.newpipe.app.model.NotificationAction + +object PlayerNotificationPreferences { + const val SLOT_COUNT = 5 + const val MAX_COMPACT_SLOTS = 3 + + const val NO_COMPACT_SLOT = -1 + + const val KEY_SCALE_TO_SQUARE_IMAGE = "scale_to_square_image_in_notifications" + const val KEY_COLORIZE = "notification_colorize_key" + const val KEY_SHOW_THUMBNAIL = "show_thumbnail_key" + val KEYS_SLOT = List(SLOT_COUNT) { slot -> "notification_slot_${slot}_key" } + val KEYS_COMPACT_SLOT = List(MAX_COMPACT_SLOTS) { index -> + "notification_slot_compact_${index}_key" + } + + const val DEFAULT_SCALE_TO_SQUARE_IMAGE = false + const val DEFAULT_COLORIZE = true + const val DEFAULT_SHOW_THUMBNAIL = true + val DEFAULT_SLOT_ACTIONS = listOf( + NotificationAction.SMART_REWIND_PREVIOUS, + NotificationAction.PLAY_PAUSE_BUFFERING, + NotificationAction.SMART_FORWARD_NEXT, + NotificationAction.REPEAT, + NotificationAction.CLOSE + ) + val DEFAULT_COMPACT_SLOTS = setOf(0, 1, 2) +} diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/NotificationSettingsScreen.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/NotificationSettingsScreen.kt index 733c1ef54..2c92ec6ac 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/NotificationSettingsScreen.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/NotificationSettingsScreen.kt @@ -37,6 +37,7 @@ import net.newpipe.app.composable.SwitchPreference import net.newpipe.app.composable.TopAppBar import net.newpipe.app.composable.localizedDuration import net.newpipe.app.model.ChannelNotificationCount +import net.newpipe.app.navigation.Destination import net.newpipe.app.navigation.Navigator import net.newpipe.app.platform.NotificationActions import net.newpipe.app.preferences.NotificationPreferences.DEFAULT_ENABLE_STREAMS_NOTIFICATIONS @@ -91,6 +92,7 @@ fun NotificationSettingsScreen( deviceNotificationsEnabled = deviceNotificationsEnabled, isPlayerNotificationExempt = notificationActions.isPlayerNotificationExempt, channelNotificationCount = channelNotificationCount, + onOpenPlayerNotificationSettings = { navigator.navigateTo(Destination.PlayerNotificationSettings) }, onNewStreamsNotificationsEnabledChange = viewModel::setNewStreamsNotificationsEnabled, onCheckIntervalChange = viewModel::setCheckInterval, onRequiredNetworkChange = viewModel::setRequiredNetwork, @@ -107,6 +109,7 @@ fun NotificationSettingsScreenContent( deviceNotificationsEnabled: Boolean = true, isPlayerNotificationExempt: Boolean = false, channelNotificationCount: ChannelNotificationCount? = null, + onOpenPlayerNotificationSettings: () -> Unit = {}, onNewStreamsNotificationsEnabledChange: (Boolean) -> Unit = {}, onCheckIntervalChange: (String) -> Unit = {}, onRequiredNetworkChange: (String) -> Unit = {}, @@ -162,11 +165,11 @@ fun NotificationSettingsScreenContent( .verticalScroll(rememberScrollState()) .padding(WindowInsets.navigationBars.asPaddingValues()) ) { - // TODO: open the player notification screen once it is migrated PreferenceRow( title = stringResource(Res.string.settings_category_player_notification_title), summary = stringResource(Res.string.settings_category_player_notification_summary), - enabled = playerNotificationEnabled + enabled = playerNotificationEnabled, + onClick = onOpenPlayerNotificationSettings ) SwitchPreference( title = stringResource(Res.string.enable_streams_notifications_title), diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreen.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreen.kt new file mode 100644 index 000000000..56a0c3591 --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreen.kt @@ -0,0 +1,198 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.screen.settings + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.navigationBars +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.PreviewLightDark +import androidx.compose.ui.tooling.preview.PreviewWrapper +import androidx.compose.ui.unit.dp +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import kotlinx.coroutines.launch +import net.newpipe.app.composable.NotificationActionSlot +import net.newpipe.app.composable.SwitchPreference +import net.newpipe.app.composable.TopAppBar +import net.newpipe.app.model.NotificationAction +import net.newpipe.app.navigation.Navigator +import net.newpipe.app.platform.NotificationActions +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_COLORIZE +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_COMPACT_SLOTS +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SCALE_TO_SQUARE_IMAGE +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SHOW_THUMBNAIL +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SLOT_ACTIONS +import net.newpipe.app.preferences.PlayerNotificationPreferences.MAX_COMPACT_SLOTS +import net.newpipe.app.preferences.PlayerNotificationPreferences.SLOT_COUNT +import net.newpipe.app.preview.ThemePreviewProvider +import net.newpipe.app.viewmodel.settings.PlayerNotificationSettingsViewModel +import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.notification_action_0_title +import newpipe.shared.generated.resources.notification_action_1_title +import newpipe.shared.generated.resources.notification_action_2_title +import newpipe.shared.generated.resources.notification_action_3_title +import newpipe.shared.generated.resources.notification_action_4_title +import newpipe.shared.generated.resources.notification_actions_at_most_three +import newpipe.shared.generated.resources.notification_actions_summary +import newpipe.shared.generated.resources.notification_actions_summary_android13 +import newpipe.shared.generated.resources.notification_colorize_summary +import newpipe.shared.generated.resources.notification_colorize_title +import newpipe.shared.generated.resources.notification_scale_to_square_image_summary +import newpipe.shared.generated.resources.notification_scale_to_square_image_title +import newpipe.shared.generated.resources.settings_category_player_notification_title +import newpipe.shared.generated.resources.show_thumbnail_summary +import newpipe.shared.generated.resources.show_thumbnail_title +import org.jetbrains.compose.resources.stringResource +import org.koin.compose.koinInject +import org.koin.compose.viewmodel.koinViewModel + +private val SLOT_TITLES = listOf( + Res.string.notification_action_0_title, + Res.string.notification_action_1_title, + Res.string.notification_action_2_title, + Res.string.notification_action_3_title, + Res.string.notification_action_4_title +) + +// Play/pause, previous and next, which the system places in the first slots itself +private const val SYSTEM_MEDIA_CONTROL_SLOTS = 3 + +@Composable +fun PlayerNotificationSettingsScreen( + navigator: Navigator = koinInject(), + viewModel: PlayerNotificationSettingsViewModel = koinViewModel(), + notificationActions: NotificationActions = koinInject() +) { + val scaleToSquareImage by viewModel.scaleToSquareImage.collectAsStateWithLifecycle() + val colorize by viewModel.colorize.collectAsStateWithLifecycle() + val showThumbnail by viewModel.showThumbnail.collectAsStateWithLifecycle() + val slotActions by viewModel.slotActions.collectAsStateWithLifecycle() + val compactSlots by viewModel.compactSlots.collectAsStateWithLifecycle() + + PlayerNotificationSettingsScreenContent( + scaleToSquareImage = scaleToSquareImage, + colorize = colorize, + showThumbnail = showThumbnail, + slotActions = slotActions, + compactSlots = compactSlots, + hasSystemMediaControls = notificationActions.hasSystemMediaControls, + onScaleToSquareImageChange = viewModel::setScaleToSquareImage, + onColorizeChange = viewModel::setColorize, + onShowThumbnailChange = viewModel::setShowThumbnail, + onSlotActionChange = viewModel::setSlotAction, + onCompactSlotToggle = viewModel::toggleCompactSlot, + onNavigateUp = { navigator.navigateUp() } + ) +} + +@Composable +fun PlayerNotificationSettingsScreenContent( + scaleToSquareImage: Boolean = DEFAULT_SCALE_TO_SQUARE_IMAGE, + colorize: Boolean = DEFAULT_COLORIZE, + showThumbnail: Boolean = DEFAULT_SHOW_THUMBNAIL, + slotActions: List = DEFAULT_SLOT_ACTIONS, + compactSlots: Set = DEFAULT_COMPACT_SLOTS, + hasSystemMediaControls: Boolean = false, + onScaleToSquareImageChange: (Boolean) -> Unit = {}, + onColorizeChange: (Boolean) -> Unit = {}, + onShowThumbnailChange: (Boolean) -> Unit = {}, + onSlotActionChange: (slot: Int, action: NotificationAction) -> Unit = { _, _ -> }, + onCompactSlotToggle: (slot: Int) -> Unit = {}, + onNavigateUp: () -> Unit = {} +) { + val snackbarHostState = remember { SnackbarHostState() } + val scope = rememberCoroutineScope() + val atMostThreeText = stringResource(Res.string.notification_actions_at_most_three) + val firstEditableSlot = if (hasSystemMediaControls) SYSTEM_MEDIA_CONTROL_SLOTS else 0 + val actionsSummary = if (hasSystemMediaControls) { + Res.string.notification_actions_summary_android13 + } else { + Res.string.notification_actions_summary + } + + Scaffold( + topBar = { + TopAppBar( + title = stringResource(Res.string.settings_category_player_notification_title), + onNavigateUp = onNavigateUp + ) + }, + snackbarHost = { SnackbarHost(snackbarHostState) } + ) { paddingValues -> + Column( + modifier = Modifier + .fillMaxSize() + .padding(top = paddingValues.calculateTopPadding()) + .verticalScroll(rememberScrollState()) + .padding(WindowInsets.navigationBars.asPaddingValues()) + ) { + SwitchPreference( + title = stringResource(Res.string.notification_scale_to_square_image_title), + summary = stringResource(Res.string.notification_scale_to_square_image_summary), + checked = scaleToSquareImage, + onCheckedChange = onScaleToSquareImageChange + ) + SwitchPreference( + title = stringResource(Res.string.notification_colorize_title), + summary = stringResource(Res.string.notification_colorize_summary), + checked = colorize, + onCheckedChange = onColorizeChange + ) + SwitchPreference( + title = stringResource(Res.string.show_thumbnail_title), + summary = stringResource(Res.string.show_thumbnail_summary), + checked = showThumbnail, + onCheckedChange = onShowThumbnailChange + ) + HorizontalDivider(modifier = Modifier.padding(top = 8.dp)) + Text( + text = stringResource(actionsSummary), + modifier = Modifier.padding(16.dp), + color = MaterialTheme.colorScheme.onSurfaceVariant, + style = MaterialTheme.typography.bodyMedium + ) + for (slot in firstEditableSlot until SLOT_COUNT) { + NotificationActionSlot( + title = stringResource(SLOT_TITLES[slot]), + action = slotActions[slot], + onActionChange = { action -> onSlotActionChange(slot, action) }, + compact = (slot in compactSlots).takeUnless { hasSystemMediaControls }, + onCompactToggle = { + if (slot !in compactSlots && compactSlots.size >= MAX_COMPACT_SLOTS) { + scope.launch { snackbarHostState.showSnackbar(atMostThreeText) } + } else { + onCompactSlotToggle(slot) + } + } + ) + } + } + } +} + +@PreviewWrapper(ThemePreviewProvider::class) +@PreviewLightDark +@Composable +private fun PlayerNotificationSettingsScreenPreview() { + PlayerNotificationSettingsScreenContent() +} diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/SettingsHomeScreen.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/SettingsHomeScreen.kt index a5ed9c221..f13ee02e8 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/SettingsHomeScreen.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/SettingsHomeScreen.kt @@ -23,7 +23,6 @@ import androidx.compose.ui.tooling.preview.PreviewWrapper import androidx.lifecycle.compose.collectAsStateWithLifecycle import net.newpipe.app.composable.PreferenceRow import net.newpipe.app.composable.TopAppBar -import net.newpipe.app.navigation.Destination import net.newpipe.app.navigation.Navigator import net.newpipe.app.preview.ThemePreviewProvider import net.newpipe.app.screen.settings.model.SettingsCategory @@ -50,47 +49,7 @@ fun SettingsHomeScreen( SettingsCategory( title = type.title, icon = type.icon, - onClick = { - when (type) { - SettingsCategoryType.APPEARANCE -> navigator.navigateTo( - Destination.AppearanceSettings - ) - - SettingsCategoryType.VIDEO_AUDIO -> navigator.navigateTo( - Destination.VideoAudioSettings - ) - - SettingsCategoryType.DEBUG -> navigator.navigateTo( - Destination.DebugSettings - ) - - SettingsCategoryType.DOWNLOADS -> navigator.navigateTo( - Destination.DownloadSettings - ) - - SettingsCategoryType.HISTORY -> navigator.navigateTo( - Destination.HistorySettings - ) - - SettingsCategoryType.CONTENT -> navigator.navigateTo( - Destination.ContentSettings - ) - - SettingsCategoryType.NOTIFICATIONS -> navigator.navigateTo( - Destination.NotificationSettings - ) - - SettingsCategoryType.UPDATES -> navigator.navigateTo( - Destination.UpdateSettings - ) - - SettingsCategoryType.BACKUP_RESTORE -> navigator.navigateTo( - Destination.BackupRestoreSettings - ) - - else -> Unit - } - } + onClick = { navigator.navigateTo(type.destination) } ) }, onNavigateUp = { navigator.navigateUp() } diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategory.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategory.kt index b4bcf8718..593ab38e2 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategory.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategory.kt @@ -11,6 +11,5 @@ import org.jetbrains.compose.resources.StringResource data class SettingsCategory( val title: StringResource, val icon: DrawableResource, - // TODO: Replace with a Destination once sub-screens are migrated val onClick: () -> Unit = {} ) diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategoryType.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategoryType.kt index 93ae3bc6e..c70861888 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategoryType.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/model/SettingsCategoryType.kt @@ -1,5 +1,6 @@ package net.newpipe.app.screen.settings.model +import net.newpipe.app.navigation.Destination import newpipe.shared.generated.resources.Res import newpipe.shared.generated.resources.content import newpipe.shared.generated.resources.ic_bug_report @@ -27,15 +28,52 @@ import org.jetbrains.compose.resources.StringResource */ enum class SettingsCategoryType( val title: StringResource, - val icon: DrawableResource + val icon: DrawableResource, + val destination: Destination ) { - VIDEO_AUDIO(Res.string.settings_category_video_audio_title, Res.drawable.ic_headset), - DOWNLOADS(Res.string.settings_category_downloads_title, Res.drawable.ic_file_download), - APPEARANCE(Res.string.settings_category_appearance_title, Res.drawable.ic_palette), - HISTORY(Res.string.settings_category_history_title, Res.drawable.ic_history), - CONTENT(Res.string.content, Res.drawable.ic_language), - NOTIFICATIONS(Res.string.notifications, Res.drawable.ic_notifications), - UPDATES(Res.string.settings_category_updates_title, Res.drawable.ic_cloud_download), - BACKUP_RESTORE(Res.string.settings_category_backup_restore_title, Res.drawable.ic_settings_backup_restore), - DEBUG(Res.string.settings_category_debug_title, Res.drawable.ic_bug_report) + VIDEO_AUDIO( + title = Res.string.settings_category_video_audio_title, + icon = Res.drawable.ic_headset, + destination = Destination.VideoAudioSettings + ), + DOWNLOADS( + title = Res.string.settings_category_downloads_title, + icon = Res.drawable.ic_file_download, + destination = Destination.DownloadSettings + ), + APPEARANCE( + title = Res.string.settings_category_appearance_title, + icon = Res.drawable.ic_palette, + destination = Destination.AppearanceSettings + ), + HISTORY( + title = Res.string.settings_category_history_title, + icon = Res.drawable.ic_history, + destination = Destination.HistorySettings + ), + CONTENT( + title = Res.string.content, + icon = Res.drawable.ic_language, + destination = Destination.ContentSettings + ), + NOTIFICATIONS( + title = Res.string.notifications, + icon = Res.drawable.ic_notifications, + destination = Destination.NotificationSettings + ), + UPDATES( + title = Res.string.settings_category_updates_title, + icon = Res.drawable.ic_cloud_download, + destination = Destination.UpdateSettings + ), + BACKUP_RESTORE( + title = Res.string.settings_category_backup_restore_title, + icon = Res.drawable.ic_settings_backup_restore, + destination = Destination.BackupRestoreSettings + ), + DEBUG( + title = Res.string.settings_category_debug_title, + icon = Res.drawable.ic_bug_report, + destination = Destination.DebugSettings + ) } diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/PlayerNotificationSettingsViewModel.kt b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/PlayerNotificationSettingsViewModel.kt new file mode 100644 index 000000000..46c0543e9 --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/PlayerNotificationSettingsViewModel.kt @@ -0,0 +1,96 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.viewmodel.settings + +import androidx.lifecycle.ViewModel +import com.russhwolf.settings.Settings +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.update +import net.newpipe.app.model.NotificationAction +import net.newpipe.app.platform.NotificationActions +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_COLORIZE +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_COMPACT_SLOTS +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SCALE_TO_SQUARE_IMAGE +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SHOW_THUMBNAIL +import net.newpipe.app.preferences.PlayerNotificationPreferences.DEFAULT_SLOT_ACTIONS +import net.newpipe.app.preferences.PlayerNotificationPreferences.KEYS_COMPACT_SLOT +import net.newpipe.app.preferences.PlayerNotificationPreferences.KEYS_SLOT +import net.newpipe.app.preferences.PlayerNotificationPreferences.KEY_COLORIZE +import net.newpipe.app.preferences.PlayerNotificationPreferences.KEY_SCALE_TO_SQUARE_IMAGE +import net.newpipe.app.preferences.PlayerNotificationPreferences.KEY_SHOW_THUMBNAIL +import net.newpipe.app.preferences.PlayerNotificationPreferences.MAX_COMPACT_SLOTS +import net.newpipe.app.preferences.PlayerNotificationPreferences.NO_COMPACT_SLOT +import org.koin.core.annotation.KoinViewModel + +@KoinViewModel +class PlayerNotificationSettingsViewModel( + private val settings: Settings, + private val notificationActions: NotificationActions +) : ViewModel() { + + val scaleToSquareImage: StateFlow + field = booleanFlow(KEY_SCALE_TO_SQUARE_IMAGE, DEFAULT_SCALE_TO_SQUARE_IMAGE) + + val colorize: StateFlow + field = booleanFlow(KEY_COLORIZE, DEFAULT_COLORIZE) + + val showThumbnail: StateFlow + field = booleanFlow(KEY_SHOW_THUMBNAIL, DEFAULT_SHOW_THUMBNAIL) + + val slotActions: StateFlow> + field = MutableStateFlow( + KEYS_SLOT.mapIndexed { slot, key -> + NotificationAction.fromId(settings.getInt(key, DEFAULT_SLOT_ACTIONS[slot].id)) + } + ) + + val compactSlots: StateFlow> + field = MutableStateFlow(storedCompactSlots()) + + fun setScaleToSquareImage(value: Boolean) = scaleToSquareImage.persist(KEY_SCALE_TO_SQUARE_IMAGE, value) + + fun setColorize(value: Boolean) = colorize.persist(KEY_COLORIZE, value) + + fun setShowThumbnail(value: Boolean) = showThumbnail.persist(KEY_SHOW_THUMBNAIL, value) + + fun setSlotAction(slot: Int, action: NotificationAction) { + settings.putInt(KEYS_SLOT[slot], action.id) + slotActions.update { actions -> actions.toMutableList().apply { set(slot, action) } } + notificationActions.recreatePlayerNotification() + } + + fun toggleCompactSlot(slot: Int) { + val current = compactSlots.value + val updated = when { + slot in current -> current - slot + current.size < MAX_COMPACT_SLOTS -> current + slot + else -> return + } + val sorted = updated.sorted() + KEYS_COMPACT_SLOT.forEachIndexed { index, key -> + settings.putInt(key, sorted.getOrElse(index) { NO_COMPACT_SLOT }) + } + compactSlots.value = updated + notificationActions.recreatePlayerNotification() + } + + // The keys only exist once the slots were saved, until then the defaults apply + private fun storedCompactSlots(): Set = KEYS_COMPACT_SLOT + .map { key -> settings.getIntOrNull(key) ?: return DEFAULT_COMPACT_SLOTS } + .filter { slot -> slot >= 0 } + .toSet() + + private fun booleanFlow(key: String, defaultValue: Boolean) = MutableStateFlow( + settings.getBoolean(key, defaultValue) + ) + + private fun MutableStateFlow.persist(key: String, newValue: Boolean) { + settings.putBoolean(key, newValue) + value = newValue + notificationActions.recreatePlayerNotification() + } +} diff --git a/shared/src/commonTest/kotlin/net/newpipe/app/extensions/SemanticsNodeInteractionsProvider.kt b/shared/src/commonTest/kotlin/net/newpipe/app/extensions/SemanticsNodeInteractionsProvider.kt new file mode 100644 index 000000000..652a38ab9 --- /dev/null +++ b/shared/src/commonTest/kotlin/net/newpipe/app/extensions/SemanticsNodeInteractionsProvider.kt @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.extensions + +import androidx.compose.ui.test.SemanticsNodeInteraction +import androidx.compose.ui.test.SemanticsNodeInteractionsProvider +import androidx.compose.ui.test.hasAnySibling +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.isToggleable + +/** + * Finds the toggleable node, like a checkbox or switch, placed next to the node with the given text + * + * Useful for rows where the label and the toggle are separate tap targets + * @param text Text of the node next to the toggleable node + */ +fun SemanticsNodeInteractionsProvider.onToggleableNodeNextTo(text: String): SemanticsNodeInteraction = onNode(isToggleable() and hasAnySibling(hasText(text))) diff --git a/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreenTest.kt b/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreenTest.kt new file mode 100644 index 000000000..b1315acc4 --- /dev/null +++ b/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/PlayerNotificationSettingsScreenTest.kt @@ -0,0 +1,90 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.screen.settings + +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.isToggleable +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollTo +import androidx.compose.ui.test.v2.runComposeUiTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import net.newpipe.app.extensions.onToggleableNodeNextTo +import net.newpipe.app.extensions.settingsModule +import net.newpipe.app.extensions.withKoin +import net.newpipe.app.model.NotificationAction +import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.notification_action_0_title +import newpipe.shared.generated.resources.notification_action_3_title +import newpipe.shared.generated.resources.notification_action_4_title +import newpipe.shared.generated.resources.notification_action_shuffle +import newpipe.shared.generated.resources.notification_actions_at_most_three +import org.jetbrains.compose.resources.getString + +@OptIn(ExperimentalTestApi::class) +class PlayerNotificationSettingsScreenTest { + + @Test + fun aFourthCompactSlotIsRejectedWithAWarning() = runComposeUiTest { + var toggledSlot: Int? = null + withKoin( + modules = listOf(settingsModule()), + content = { PlayerNotificationSettingsScreenContent(onCompactSlotToggle = { slot -> toggledSlot = slot }) }, + onContent = { + onToggleableNodeNextTo(getString(Res.string.notification_action_3_title)).performScrollTo().performClick() + waitForIdle() + onNodeWithText(getString(Res.string.notification_actions_at_most_three)).assertIsDisplayed() + assertNull(toggledSlot) + } + ) + } + + @Test + fun uncheckingACompactSlotIsReported() = runComposeUiTest { + var toggledSlot: Int? = null + withKoin( + modules = listOf(settingsModule()), + content = { PlayerNotificationSettingsScreenContent(onCompactSlotToggle = { slot -> toggledSlot = slot }) }, + onContent = { + onToggleableNodeNextTo(getString(Res.string.notification_action_0_title)).performScrollTo().performClick() + assertEquals(0, toggledSlot) + } + ) + } + + @Test + fun systemMediaControlsHideTheFixedSlotsAndCheckboxes() = runComposeUiTest { + withKoin( + modules = listOf(settingsModule()), + content = { PlayerNotificationSettingsScreenContent(hasSystemMediaControls = true) }, + onContent = { + onNodeWithText(getString(Res.string.notification_action_0_title)).assertDoesNotExist() + onNodeWithText(getString(Res.string.notification_action_3_title)).assertExists() + onAllNodes(isToggleable()).assertCountEquals(3) + } + ) + } + + @Test + fun choosingAnActionReportsItsSlot() = runComposeUiTest { + var change: Pair? = null + withKoin( + modules = listOf(settingsModule()), + content = { + PlayerNotificationSettingsScreenContent(onSlotActionChange = { slot, action -> change = slot to action }) + }, + onContent = { + onNodeWithText(getString(Res.string.notification_action_4_title)).performScrollTo().performClick() + onNodeWithText(getString(Res.string.notification_action_shuffle)).performClick() + assertEquals(4 to NotificationAction.SHUFFLE, change) + } + ) + } +}