Merge pull request #14031 from TeamNewPipe/missing-settings

Missing player notifcations settings to compose multiplatform
This commit is contained in:
Ida authored and GitHub committed 2026-11-15 13:38:23 -08:00
commit 1e61c9adac
27 files changed
+976 -55

No files matched your search

@@ -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<ChannelNotificationCount> = SubscriptionManager(context)
@@ -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() {
@@ -20,4 +20,6 @@ interface NotificationHost {
fun applyNewStreamsCheckSchedule()
fun channelNotificationCounts(): Flow<ChannelNotificationCount>
fun recreatePlayerNotification()
}
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M11,18V6l-8.5,6 8.5,6zM11.5,12l8.5,6V6l-8.5,6z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M6,2l0.01,6L10,12l-3.99,4.01L6,22h12v-6l-4,-4l4,-3.99V2H6zM16,16.5V20H8v-3.5l4,-4L16,16.5z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M6,6h2v12L6,18zM9.5,12l8.5,6L18,6z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z" />
</vector>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: Material Design Authors / Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5L20,4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20L20,20v-5.5l-2.04,2.04 -3.13,-3.13z" />
</vector>
@@ -327,6 +327,33 @@
<string name="channels">Channels</string>
<string name="notifications_disabled">Notifications are disabled</string>
<!-- Player notification -->
<string name="notification_scale_to_square_image_title">Crop thumbnail to 1:1 aspect ratio</string>
<string name="notification_scale_to_square_image_summary">Crop the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio</string>
<string name="notification_colorize_title">Colorize notification</string>
<string name="notification_colorize_summary">Have Android customize the notification's color according to the main color in the thumbnail (note that this is not available on all devices)</string>
<string name="show_thumbnail_title">Show thumbnail</string>
<string name="show_thumbnail_summary">Use thumbnail for both lock screen background and notifications</string>
<string name="notification_action_0_title">First action button</string>
<string name="notification_action_1_title">Second action button</string>
<string name="notification_action_2_title">Third action button</string>
<string name="notification_action_3_title">Fourth action button</string>
<string name="notification_action_4_title">Fifth action button</string>
<string name="notification_actions_summary">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.</string>
<string name="notification_actions_summary_android13">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.</string>
<string name="notification_actions_at_most_three">You can select at most three actions to show in the compact notification!</string>
<string name="notification_action_nothing">Nothing</string>
<string name="notification_action_previous">Previous</string>
<string name="notification_action_next">Next</string>
<string name="notification_action_rewind">Rewind</string>
<string name="notification_action_fast_forward">Fast forward</string>
<string name="notification_action_play">Play</string>
<string name="notification_action_pause">Pause</string>
<string name="notification_action_buffering">Buffering</string>
<string name="notification_action_repeat">Repeat</string>
<string name="notification_action_shuffle">Shuffle</string>
<string name="close">Close</string>
<!-- Update Settings -->
<string name="updates_setting_title">Updates</string>
<string name="updates_setting_description">Show a notification to prompt app update when a new version is available</string>
@@ -0,0 +1,172 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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
)
}
@@ -0,0 +1,117 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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<StringResource>,
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
}
}
@@ -17,6 +17,9 @@ sealed interface Destination : NavKey {
@Serializable
data object BackupRestoreSettings : Destination
@Serializable
data object PlayerNotificationSettings : Destination
@Serializable
data object UpdateSettings : Destination
@@ -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<Destination.BackupRestoreSettings> {
BackupRestoreSettingsScreen()
}
navigation<Destination.PlayerNotificationSettings> {
PlayerNotificationSettingsScreen()
}
}
/**
@@ -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<ChannelNotificationCount>
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<ChannelNotificationCount> = emptyFlow()
override fun recreatePlayerNotification() = logUnsupported("recreatePlayerNotification")
private fun logUnsupported(action: String) = Logger.w(messageString = "Notification action '$action' is unsupported on this platform")
}
@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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)
}
@@ -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),
@@ -0,0 +1,198 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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<NotificationAction> = DEFAULT_SLOT_ACTIONS,
compactSlots: Set<Int> = 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()
}
@@ -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() }
@@ -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 = {}
)
@@ -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
)
}
@@ -0,0 +1,96 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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<Boolean>
field = booleanFlow(KEY_SCALE_TO_SQUARE_IMAGE, DEFAULT_SCALE_TO_SQUARE_IMAGE)
val colorize: StateFlow<Boolean>
field = booleanFlow(KEY_COLORIZE, DEFAULT_COLORIZE)
val showThumbnail: StateFlow<Boolean>
field = booleanFlow(KEY_SHOW_THUMBNAIL, DEFAULT_SHOW_THUMBNAIL)
val slotActions: StateFlow<List<NotificationAction>>
field = MutableStateFlow(
KEYS_SLOT.mapIndexed { slot, key ->
NotificationAction.fromId(settings.getInt(key, DEFAULT_SLOT_ACTIONS[slot].id))
}
)
val compactSlots: StateFlow<Set<Int>>
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<Int> = 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<Boolean>.persist(key: String, newValue: Boolean) {
settings.putBoolean(key, newValue)
value = newValue
notificationActions.recreatePlayerNotification()
}
}
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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)))
@@ -0,0 +1,90 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* 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<Int, NotificationAction>? = 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)
}
)
}
}