mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-11-23 15:47:20 +00:00
address pr review feedback
This commit is contained in:
1 parent
fe4f2ce902
commit
33954fa1f7
9 files changed
+168
-127
No files matched your search
@@ -40,28 +40,7 @@ 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.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
|
||||
import newpipe.shared.generated.resources.notification_action_0_title
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -167,66 +146,12 @@ private fun NotificationAction.title(): String = labels
|
||||
.map { label -> stringResource(label) }
|
||||
.joinToString(separator = LABEL_SEPARATOR)
|
||||
|
||||
private val NotificationAction.labels: List<StringResource>
|
||||
get() = when (this) {
|
||||
NotificationAction.NOTHING -> listOf(Res.string.notification_action_nothing)
|
||||
|
||||
NotificationAction.PREVIOUS -> listOf(Res.string.notification_action_previous)
|
||||
|
||||
NotificationAction.NEXT -> listOf(Res.string.notification_action_next)
|
||||
|
||||
NotificationAction.REWIND -> listOf(Res.string.notification_action_rewind)
|
||||
|
||||
NotificationAction.FORWARD -> listOf(Res.string.notification_action_fast_forward)
|
||||
|
||||
NotificationAction.SMART_REWIND_PREVIOUS -> listOf(
|
||||
Res.string.notification_action_rewind,
|
||||
Res.string.notification_action_previous
|
||||
)
|
||||
|
||||
NotificationAction.SMART_FORWARD_NEXT -> listOf(
|
||||
Res.string.notification_action_fast_forward,
|
||||
Res.string.notification_action_next
|
||||
)
|
||||
|
||||
NotificationAction.PLAY_PAUSE -> listOf(
|
||||
Res.string.notification_action_play,
|
||||
Res.string.notification_action_pause
|
||||
)
|
||||
|
||||
NotificationAction.PLAY_PAUSE_BUFFERING -> listOf(
|
||||
Res.string.notification_action_play,
|
||||
Res.string.notification_action_pause,
|
||||
Res.string.notification_action_buffering
|
||||
)
|
||||
|
||||
NotificationAction.REPEAT -> listOf(Res.string.notification_action_repeat)
|
||||
|
||||
NotificationAction.SHUFFLE -> listOf(Res.string.notification_action_shuffle)
|
||||
|
||||
NotificationAction.CLOSE -> listOf(Res.string.close)
|
||||
}
|
||||
|
||||
private val NotificationAction.icon: DrawableResource?
|
||||
get() = when (this) {
|
||||
NotificationAction.NOTHING -> null
|
||||
NotificationAction.PREVIOUS, NotificationAction.SMART_REWIND_PREVIOUS -> Res.drawable.ic_previous
|
||||
NotificationAction.NEXT, NotificationAction.SMART_FORWARD_NEXT -> Res.drawable.ic_next
|
||||
NotificationAction.REWIND -> Res.drawable.ic_fast_rewind
|
||||
NotificationAction.FORWARD -> Res.drawable.ic_fast_forward
|
||||
NotificationAction.PLAY_PAUSE -> Res.drawable.ic_pause
|
||||
NotificationAction.PLAY_PAUSE_BUFFERING -> Res.drawable.ic_hourglass_top
|
||||
NotificationAction.REPEAT -> Res.drawable.ic_repeat
|
||||
NotificationAction.SHUFFLE -> Res.drawable.ic_shuffle
|
||||
NotificationAction.CLOSE -> Res.drawable.ic_close
|
||||
}
|
||||
|
||||
@PreviewWrapper(ThemePreviewProvider::class)
|
||||
@PreviewLightDark
|
||||
@Composable
|
||||
private fun NotificationActionSlotPreview() {
|
||||
NotificationActionSlot(
|
||||
title = "First action button",
|
||||
title = stringResource(Res.string.notification_action_0_title),
|
||||
action = NotificationAction.SMART_REWIND_PREVIOUS,
|
||||
onActionChange = {},
|
||||
compact = true
|
||||
|
||||
@@ -7,21 +7,107 @@ package net.newpipe.app.model
|
||||
|
||||
/**
|
||||
* Actions that can be placed in a slot of the player notification
|
||||
*
|
||||
*/
|
||||
enum class NotificationAction(val id: Int) {
|
||||
NOTHING(0),
|
||||
PREVIOUS(1),
|
||||
NEXT(2),
|
||||
REWIND(3),
|
||||
FORWARD(4),
|
||||
SMART_REWIND_PREVIOUS(5),
|
||||
SMART_FORWARD_NEXT(6),
|
||||
PLAY_PAUSE(7),
|
||||
PLAY_PAUSE_BUFFERING(8),
|
||||
REPEAT(9),
|
||||
SHUFFLE(10),
|
||||
CLOSE(11);
|
||||
|
||||
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 ->
|
||||
|
||||
@@ -14,6 +14,12 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
sealed interface Destination : NavKey {
|
||||
|
||||
@Serializable
|
||||
data object BackupRestoreSettings : Destination
|
||||
|
||||
@Serializable
|
||||
data object PlayerNotificationSettings : Destination
|
||||
|
||||
@Serializable
|
||||
data object UpdateSettings : Destination
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ fun navModule() = module {
|
||||
|
||||
navigation<Destination.BackupRestoreSettings> {
|
||||
BackupRestoreSettingsScreen()
|
||||
}
|
||||
|
||||
navigation<Destination.PlayerNotificationSettings> {
|
||||
PlayerNotificationSettingsScreen()
|
||||
|
||||
+1
-4
@@ -167,11 +167,8 @@ fun PlayerNotificationSettingsScreenContent(
|
||||
HorizontalDivider(modifier = Modifier.padding(top = 8.dp))
|
||||
Text(
|
||||
text = stringResource(actionsSummary),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
for (slot in firstEditableSlot until SLOT_COUNT) {
|
||||
|
||||
@@ -50,7 +50,6 @@ fun SettingsHomeScreen(
|
||||
title = type.title,
|
||||
icon = type.icon,
|
||||
onClick = { navigator.navigateTo(type.destination) }
|
||||
|
||||
)
|
||||
},
|
||||
onNavigateUp = { navigator.navigateUp() }
|
||||
|
||||
+35
-24
@@ -32,37 +32,48 @@ enum class SettingsCategoryType(
|
||||
val destination: Destination
|
||||
) {
|
||||
VIDEO_AUDIO(
|
||||
Res.string.settings_category_video_audio_title,
|
||||
Res.drawable.ic_headset,
|
||||
Destination.VideoAudioSettings
|
||||
title = Res.string.settings_category_video_audio_title,
|
||||
icon = Res.drawable.ic_headset,
|
||||
destination = Destination.VideoAudioSettings
|
||||
),
|
||||
DOWNLOADS(
|
||||
Res.string.settings_category_downloads_title,
|
||||
Res.drawable.ic_file_download,
|
||||
Destination.DownloadSettings
|
||||
title = Res.string.settings_category_downloads_title,
|
||||
icon = Res.drawable.ic_file_download,
|
||||
destination = Destination.DownloadSettings
|
||||
),
|
||||
APPEARANCE(
|
||||
Res.string.settings_category_appearance_title,
|
||||
Res.drawable.ic_palette,
|
||||
Destination.AppearanceSettings
|
||||
title = Res.string.settings_category_appearance_title,
|
||||
icon = Res.drawable.ic_palette,
|
||||
destination = Destination.AppearanceSettings
|
||||
),
|
||||
HISTORY(
|
||||
Res.string.settings_category_history_title,
|
||||
Res.drawable.ic_history,
|
||||
Destination.HistorySettings
|
||||
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
|
||||
),
|
||||
CONTENT(Res.string.content, Res.drawable.ic_language, Destination.ContentSettings),
|
||||
NOTIFICATIONS(Res.string.notifications, Res.drawable.ic_notifications, Destination.NotificationSettings),
|
||||
UPDATES(
|
||||
Res.string.settings_category_updates_title,
|
||||
Res.drawable.ic_cloud_download,
|
||||
Destination.UpdateSettings
|
||||
title = Res.string.settings_category_updates_title,
|
||||
icon = Res.drawable.ic_cloud_download,
|
||||
destination = Destination.UpdateSettings
|
||||
),
|
||||
|
||||
// BACKUP_RESTORE(
|
||||
// Res.string.settings_category_backup_restore_title,
|
||||
// Res.drawable.ic_settings_backup_restore,
|
||||
// Destination.BackupRestoreSettings
|
||||
// ),
|
||||
DEBUG(Res.string.settings_category_debug_title, Res.drawable.ic_bug_report, Destination.DebugSettings)
|
||||
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
|
||||
)
|
||||
}
|
||||
+20
@@ -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)))
|
||||
+3
-7
@@ -6,11 +6,8 @@
|
||||
package net.newpipe.app.screen.settings
|
||||
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
|
||||
import androidx.compose.ui.test.assertCountEquals
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.hasAnySibling
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.isToggleable
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
@@ -19,6 +16,7 @@ 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
|
||||
@@ -40,7 +38,7 @@ class PlayerNotificationSettingsScreenTest {
|
||||
modules = listOf(settingsModule()),
|
||||
content = { PlayerNotificationSettingsScreenContent(onCompactSlotToggle = { slot -> toggledSlot = slot }) },
|
||||
onContent = {
|
||||
compactCheckbox(getString(Res.string.notification_action_3_title)).performScrollTo().performClick()
|
||||
onToggleableNodeNextTo(getString(Res.string.notification_action_3_title)).performScrollTo().performClick()
|
||||
waitForIdle()
|
||||
onNodeWithText(getString(Res.string.notification_actions_at_most_three)).assertIsDisplayed()
|
||||
assertNull(toggledSlot)
|
||||
@@ -55,7 +53,7 @@ class PlayerNotificationSettingsScreenTest {
|
||||
modules = listOf(settingsModule()),
|
||||
content = { PlayerNotificationSettingsScreenContent(onCompactSlotToggle = { slot -> toggledSlot = slot }) },
|
||||
onContent = {
|
||||
compactCheckbox(getString(Res.string.notification_action_0_title)).performScrollTo().performClick()
|
||||
onToggleableNodeNextTo(getString(Res.string.notification_action_0_title)).performScrollTo().performClick()
|
||||
assertEquals(0, toggledSlot)
|
||||
}
|
||||
)
|
||||
@@ -89,6 +87,4 @@ class PlayerNotificationSettingsScreenTest {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun SemanticsNodeInteractionsProvider.compactCheckbox(slotTitle: String) = onNode(isToggleable() and hasAnySibling(hasText(slotTitle)))
|
||||
}
|
||||
Reference in new issue
Block a user