Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fun ClickablePreferenceItem(
icon: ImageVector? = null,
onClick: () -> Unit = {},
onLongClick: (() -> Unit)? = null,
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
) {
PreferenceItem(
title = title,
Expand All @@ -29,8 +29,8 @@ fun ClickablePreferenceItem(
enabled = enabled,
onClick = onClick,
onLongClick = onLongClick,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.anilbeesetti.nextplayer.core.ui.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CornerBasedShape
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
Expand All @@ -11,6 +12,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SegmentedListItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -22,11 +24,11 @@ fun NextSegmentedListItem(
modifier: Modifier = Modifier,
selected: Boolean = false,
enabled: Boolean = true,
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
contentPadding: PaddingValues = PaddingValues(16.dp),
colors: ListItemColors = ListItemDefaults.segmentedColors(),
shapes: ListItemShapes = ListItemDefaults.segmentedShapes(index, count),
shapes: ListItemShapes = ListItemDefaults.shapes(),
leadingContent: @Composable (() -> Unit)? = null,
trailingContent: @Composable (() -> Unit)? = null,
overlineContent: @Composable (() -> Unit)? = null,
Expand All @@ -36,14 +38,29 @@ fun NextSegmentedListItem(
onLongClick: (() -> Unit)? = null,
interactionSource: MutableInteractionSource? = null,
) {
val overrideShape = MaterialTheme.shapes.large
SegmentedListItem(
modifier = modifier,
selected = selected,
onClick = onClick,
onLongClick = onLongClick,
enabled = enabled,
verticalAlignment = Alignment.CenterVertically,
shapes = shapes,
shapes = remember(isFirstItem, isLastItem, shapes) {
val defaultBaseShape = shapes.shape
if (defaultBaseShape is CornerBasedShape) {
shapes.copy(
shape = defaultBaseShape.copy(
topStart = overrideShape.topStart.takeIf { isFirstItem } ?: defaultBaseShape.topStart,
topEnd = overrideShape.topEnd.takeIf { isFirstItem } ?: defaultBaseShape.topEnd,
bottomStart = overrideShape.bottomStart.takeIf { isLastItem } ?: defaultBaseShape.bottomStart,
bottomEnd = overrideShape.bottomEnd.takeIf { isLastItem } ?: defaultBaseShape.bottomEnd,
),
)
} else {
shapes
}
},
colors = colors,
contentPadding = contentPadding,
leadingContent = leadingContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ fun PreferenceItem(
enabled: Boolean,
onClick: () -> Unit = {},
onLongClick: (() -> Unit)? = null,
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
trailingContent: @Composable () -> Unit = {},
) {
NextSegmentedListItem(
modifier = modifier,
onClick = onClick,
onLongClick = onLongClick,
enabled = enabled,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
leadingContent = icon?.let {
{
Icon(
Expand Down Expand Up @@ -70,15 +70,15 @@ fun SelectablePreference(
selected: Boolean = false,
onClick: () -> Unit = {},
onLongClick: () -> Unit = {},
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
) {
NextSegmentedListItem(
modifier = modifier,
onClick = onClick,
onLongClick = onLongClick,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
content = {
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fun PreferenceSlider(
description: String? = null,
icon: ImageVector? = null,
enabled: Boolean = true,
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
value: Float,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
onValueChange: (Float) -> Unit,
Expand All @@ -32,8 +32,8 @@ fun PreferenceSlider(
onClick = {},
onLongClick = null,
enabled = enabled,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
leadingContent = icon?.let {
{
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ fun PreferenceSwitch(
enabled: Boolean = true,
isChecked: Boolean = true,
onClick: (() -> Unit) = {},
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
) {
PreferenceItem(
title = title,
description = description,
icon = icon,
enabled = enabled,
onClick = onClick,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
trailingContent = {
NextSwitch(
checked = isChecked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ fun PreferenceSwitchWithDivider(
isChecked: Boolean = true,
onClick: (() -> Unit) = {},
onChecked: () -> Unit = {},
index: Int = 0,
count: Int = 1,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
) {
PreferenceItem(
title = title,
description = description,
icon = icon,
onClick = onClick,
enabled = enabled,
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
trailingContent = {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ fun BoxScope.PlaylistView(
val isCurrentItem = index == playlistState.currentMediaItemIndex
PlaylistItemView(
mediaItem = mediaItem,
index = index,
count = playlistState.playlist.size,
isFirstItem = index == 0,
isLastItem = index == playlistState.playlist.lastIndex,
isCurrentItem = isCurrentItem,
canDelete = playlistState.playlist.size > 1,
onClick = { playlistState.seekToItem(index) },
Expand All @@ -128,8 +128,8 @@ fun BoxScope.PlaylistView(
@Composable
private fun ReorderableCollectionItemScope.PlaylistItemView(
mediaItem: MediaItem,
index: Int,
count: Int,
isFirstItem: Boolean = false,
isLastItem: Boolean = false,
isCurrentItem: Boolean,
canDelete: Boolean,
onClick: () -> Unit,
Expand Down Expand Up @@ -161,8 +161,8 @@ private fun ReorderableCollectionItemScope.PlaylistItemView(
},
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f),
),
index = index,
count = count,
isFirstItem = isFirstItem,
isLastItem = isLastItem,
onClick = onClick,
leadingContent = {
Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fun SettingsScreen(
description = stringResource(id = row.descriptionResId),
icon = row.icon,
onClick = { onItemClick(row.setting) },
index = index,
count = settingRows.size,
isFirstItem = index == 0,
isLastItem = index == settingRows.lastIndex,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ fun AboutPreferencesScreen(
Column(
verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap),
) {
val totalRows = 3
ClickablePreferenceItem(
title = stringResource(R.string.kofi),
description = stringResource(R.string.support_the_developer_on, stringResource(R.string.kofi)),
Expand All @@ -128,8 +127,7 @@ fun AboutPreferencesScreen(
context = context,
)
},
index = 0,
count = totalRows,
isFirstItem = true
)
ClickablePreferenceItem(
title = stringResource(R.string.paypal),
Expand All @@ -141,8 +139,6 @@ fun AboutPreferencesScreen(
context = context,
)
},
index = 1,
count = totalRows,
)
ClickablePreferenceItem(
title = stringResource(R.string.upi),
Expand All @@ -154,8 +150,7 @@ fun AboutPreferencesScreen(
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show()
}
},
index = 2,
count = totalRows,
isLastItem = true,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ fun LibrariesScreen(
}
}
},
index = index,
count = libs.libraries.size,
isFirstItem = index == 0,
isLastItem = index == libs.libraries.lastIndex,
onClick = {
library.website?.takeIf { it.isNotBlank() }?.let {
uriHandler.openUriOrShowToast(uri = it, context = context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,22 @@ private fun AppearancePreferencesContent(
Column(
verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap),
) {
val totalRows = if (supportsDynamicTheming()) 3 else 2
PreferenceSwitchWithDivider(
title = stringResource(id = R.string.dark_theme),
description = uiState.preferences.themeConfig.name(),
isChecked = uiState.preferences.themeConfig == ThemeConfig.ON,
onChecked = { onEvent(AppearancePreferencesEvent.ToggleDarkTheme) },
icon = NextIcons.DarkMode,
onClick = { onEvent(AppearancePreferencesEvent.ShowDialog(AppearancePreferenceDialog.Theme)) },
index = 0,
count = totalRows,
isFirstItem = true
)
PreferenceSwitch(
title = stringResource(R.string.high_contrast_dark_theme),
description = stringResource(R.string.high_contrast_dark_theme_desc),
icon = NextIcons.Contrast,
isChecked = uiState.preferences.useHighContrastDarkTheme,
onClick = { onEvent(AppearancePreferencesEvent.ToggleUseHighContrastDarkTheme) },
index = 1,
count = totalRows,
isLastItem = !supportsDynamicTheming()
)
if (supportsDynamicTheming()) {
PreferenceSwitch(
Expand All @@ -110,8 +107,7 @@ private fun AppearancePreferencesContent(
icon = NextIcons.Appearance,
isChecked = uiState.preferences.useDynamicColors,
onClick = { onEvent(AppearancePreferencesEvent.ToggleUseDynamicColors) },
index = 2,
count = totalRows,
isLastItem = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,51 +84,42 @@ private fun AudioPreferencesContent(
Column(
verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap),
) {
val totalRows = 5
ClickablePreferenceItem(
title = stringResource(id = R.string.preferred_audio_lang),
description = LocalesHelper.getLocaleDisplayLanguage(uiState.preferences.preferredAudioLanguage)
.takeIf { it.isNotBlank() } ?: stringResource(R.string.preferred_audio_lang_description),
icon = NextIcons.Language,
onClick = { onEvent(AudioPreferencesUiEvent.ShowDialog(AudioPreferenceDialog.AudioLanguageDialog)) },
index = 0,
count = totalRows,
isFirstItem = true,
)
PreferenceSwitch(
title = stringResource(R.string.require_audio_focus),
description = stringResource(R.string.require_audio_focus_desc),
icon = NextIcons.Focus,
isChecked = uiState.preferences.requireAudioFocus,
onClick = { onEvent(AudioPreferencesUiEvent.ToggleRequireAudioFocus) },
index = 1,
count = totalRows,
)
PreferenceSwitch(
title = stringResource(id = R.string.pause_on_headset_disconnect),
description = stringResource(id = R.string.pause_on_headset_disconnect_desc),
icon = NextIcons.HeadsetOff,
isChecked = uiState.preferences.pauseOnHeadsetDisconnect,
onClick = { onEvent(AudioPreferencesUiEvent.TogglePauseOnHeadsetDisconnect) },
index = 2,
count = totalRows,
)
PreferenceSwitch(
title = stringResource(id = R.string.system_volume_panel),
description = stringResource(id = R.string.system_volume_panel_desc),
icon = NextIcons.Headset,
isChecked = uiState.preferences.showSystemVolumePanel,
onClick = { onEvent(AudioPreferencesUiEvent.ToggleShowSystemVolumePanel) },
index = 3,
count = totalRows,
)
PreferenceSwitch(
title = stringResource(id = R.string.volume_boost),
description = stringResource(id = R.string.volume_boost_desc),
icon = NextIcons.VolumeUp,
isChecked = uiState.preferences.enableVolumeBoost,
onClick = { onEvent(AudioPreferencesUiEvent.ToggleVolumeBoost) },
index = 4,
count = totalRows,
isLastItem = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private fun DecoderPreferencesContent(
description = preferences.decoderPriority.name(),
icon = NextIcons.Priority,
onClick = { onEvent(DecoderPreferencesUiEvent.ShowDialog(DecoderPreferenceDialog.DecoderPriorityDialog)) },
isFirstItem = true,
isLastItem = true,
)
}
}
Expand Down
Loading