Skip to content

Commit

Permalink
Continue desktop player, add narrow desktop player
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed Nov 27, 2023
1 parent 9957c55 commit 9571658
Show file tree
Hide file tree
Showing 32 changed files with 812 additions and 341 deletions.
2 changes: 1 addition & 1 deletion ComposeKit
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data object DesktopSettings: SettingsCategory("desktop") {
SERVER_IP_ADDRESS,
SERVER_PORT,
SERVER_LOCAL_COMMAND,
SERVER_LOCAL_START_AUTOMATICALLY,
SERVER_KILL_CHILD_ON_EXIT;

override val category: SettingsCategory get() = DesktopSettings
Expand All @@ -35,6 +36,7 @@ data object DesktopSettings: SettingsCategory("desktop") {
SERVER_IP_ADDRESS -> "127.0.0.1"
SERVER_PORT -> 3973
SERVER_LOCAL_COMMAND -> "spms"
SERVER_LOCAL_START_AUTOMATICALLY -> false
SERVER_KILL_CHILD_ON_EXIT -> true
} as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import app.cash.sqldelight.Query
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
import com.toasterofbread.composekit.platform.Platform
import com.toasterofbread.composekit.platform.PlatformPreferences
import com.toasterofbread.composekit.platform.PlatformPreferencesListener
import com.toasterofbread.spmp.ProjectBuildConfig
Expand Down Expand Up @@ -204,7 +205,7 @@ abstract class PlayerServicePlayer(private val service: PlatformPlayerService) {
}

init {
if (ProjectBuildConfig.MUTE_PLAYER == true) {
if (ProjectBuildConfig.MUTE_PLAYER == true && !Platform.DESKTOP.isCurrent()) {
service.volume = 0f
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material.icons.outlined.ThumbUp
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -25,6 +26,7 @@ import com.toasterofbread.spmp.model.mediaitem.loader.SongLikedLoader
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.model.mediaitem.song.SongLikedStatus
import com.toasterofbread.spmp.model.mediaitem.song.updateLiked
import com.toasterofbread.spmp.ui.theme.appHover
import com.toasterofbread.spmp.youtubeapi.YoutubeApi
import com.toasterofbread.spmp.youtubeapi.endpoint.SetSongLikedEndpoint
import com.toasterofbread.spmp.youtubeapi.endpoint.SongLikedEndpoint
Expand Down Expand Up @@ -79,7 +81,8 @@ fun LikeDislikeButton(
)
}
},
modifier.bounceOnClick(),
modifier.bounceOnClick().appHover(true),
enabled = getEnabled?.invoke() != false,
apply_minimum_size = false
) {
Crossfade(liked_status) { status ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.toasterofbread.composekit.utils.common.getContrasted
import com.toasterofbread.composekit.utils.common.thenIf
import com.toasterofbread.composekit.utils.composable.NoRipple
import com.toasterofbread.spmp.platform.AppContext
import kotlin.math.sign

class PillMenu(
private val action_count: Int = 0,
Expand Down Expand Up @@ -406,12 +407,31 @@ fun RowOrColumn(
row: Boolean,
modifier: Modifier = Modifier,
arrangement: Arrangement.HorizontalOrVertical = Arrangement.SpaceEvenly,
alignment: Int = 0,
content: @Composable (getWeightModifier: (Float) -> Modifier) -> Unit,
) {
if (row) {
Row(modifier, horizontalArrangement = arrangement, verticalAlignment = Alignment.CenterVertically) { content { Modifier.weight(it) } }
Row(
modifier,
horizontalArrangement = arrangement,
verticalAlignment =
when (alignment.sign) {
-1 -> Alignment.Top
0 -> Alignment.CenterVertically
else -> Alignment.Bottom
}
) { content { Modifier.weight(it) } }
}
else {
Column(modifier, verticalArrangement = arrangement, horizontalAlignment = Alignment.CenterHorizontally) { content { Modifier.weight(it) } }
Column(
modifier,
verticalArrangement = arrangement,
horizontalAlignment =
when (alignment.sign) {
-1 -> Alignment.Start
0 -> Alignment.CenterHorizontally
else -> Alignment.End
}
) { content { Modifier.weight(it) } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal fun DesktopLongPressMenu(
.width(MENU_WIDTH_DP.dp)
.focusRequester(focus_requester)
.onFocusChanged {
if (focused && !it.hasFocus) {
if (focused && !it.hasFocus && show_background) {
close()
}
focused = it.hasFocus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Radio
import androidx.compose.material.icons.filled.Remove
import androidx.compose.material.icons.filled.SubdirectoryArrowRight
import androidx.compose.material.ripple.rememberRipple
Expand All @@ -27,10 +28,12 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.toasterofbread.composekit.platform.vibrateShort
import com.toasterofbread.composekit.utils.common.thenIf
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.platform.playerservice.PlatformPlayerService
import com.toasterofbread.spmp.ui.component.mediaitempreview.MediaItemPreviewLong
import com.toasterofbread.spmp.ui.layout.apppage.mainpage.PlayerState
import com.toasterofbread.spmp.ui.theme.appHover

class LongPressMenuActionProvider(
val getContentColour: () -> Color,
Expand Down Expand Up @@ -148,7 +151,7 @@ class LongPressMenuActionProvider(
onAction: () -> Unit,
fill_width: Boolean = true
) {
val player = LocalPlayerState.current
val player: PlayerState = LocalPlayerState.current

Row(
modifier
Expand All @@ -167,7 +170,10 @@ class LongPressMenuActionProvider(
}
}
)
.let { if (fill_width) it.fillMaxWidth() else it },
.appHover(true)
.thenIf(fill_width) {
fillMaxWidth()
},
horizontalArrangement = Arrangement.spacedBy(20.dp),
verticalAlignment = Alignment.CenterVertically
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.toasterofbread.spmp.ui.component.longpressmenu

import LocalPlayerState
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.offset
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.Modifier
import androidx.compose.ui.geometry.Offset
Expand All @@ -13,6 +19,7 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.toasterofbread.composekit.utils.common.getContrasted
import com.toasterofbread.spmp.model.mediaitem.MediaItem
import com.toasterofbread.spmp.model.mediaitem.MediaItemPreviewInteractionPressStage
Expand All @@ -25,6 +32,7 @@ import com.toasterofbread.spmp.ui.component.longpressmenu.playlist.PlaylistLongP
import com.toasterofbread.spmp.ui.component.longpressmenu.song.SongLongPressMenuActions
import com.toasterofbread.spmp.ui.component.multiselect.MediaItemMultiSelectContext
import com.toasterofbread.spmp.ui.layout.artistpage.ArtistSubscribeButton
import com.toasterofbread.spmp.ui.theme.appHover
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -107,8 +115,12 @@ data class LongPressMenuData(
}
}

fun Modifier.longPressItem(long_press_menu_data: LongPressMenuData): Modifier =
onGloballyPositioned {
long_press_menu_data.layout_size = it.size
long_press_menu_data.layout_offset = it.positionInRoot()
}
@Composable
fun Modifier.longPressItem(long_press_menu_data: LongPressMenuData): Modifier {
return this
.onGloballyPositioned {
long_press_menu_data.layout_size = it.size
long_press_menu_data.layout_offset = it.positionInRoot()
}
.appHover()
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,14 @@ fun MediaItemPreviewLong(
Column(
Modifier
.padding(horizontal = 10.dp)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(3.dp)
.fillMaxWidth()
) {
val item_title: String? by loaded_item.observeActiveTitle()
Text(
item_title ?: "",
color = contentColour?.invoke() ?: Color.Unspecified,
fontSize = font_size,
lineHeight = font_size,
// lineHeight = font_size,
maxLines = title_lines,
overflow = TextOverflow.Clip
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.toasterofbread.composekit.utils.common.bitmapResource
import com.toasterofbread.composekit.utils.common.blockGestures
import com.toasterofbread.composekit.utils.common.thenIf
import com.toasterofbread.composekit.utils.common.toFloat
import com.toasterofbread.spmp.platform.splash.SplashExtraLoadingContent
import com.toasterofbread.spmp.resources.getString
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -125,10 +129,17 @@ fun LoadingSplashView(splash_mode: SplashMode?, loading_message: String?, modifi
Text(loading_message, Modifier.padding(horizontal = 20.dp), color = player.theme.on_background)
}
LinearProgressIndicator(Modifier.fillMaxWidth(), color = player.theme.accent)

SplashExtraLoadingContent(Modifier)
}
}

val extra_content_alpha: Float by animateFloatAsState(show_message.toFloat())
SplashExtraLoadingContent(
Modifier
.thenIf(!show_message) {
blockGestures()
}
.graphicsLayer { alpha = extra_content_alpha }
)
}
}
SplashMode.WARNING -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PlayerStateImpl(override val context: AppContext, private val coroutine_sc
np_swipe_state.value.animateTo(
page,
when (NowPlayingMainTabPage.Mode.getCurrent(this@PlayerStateImpl)) {
NowPlayingMainTabPage.Mode.LARGE -> spring(Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow)
// NowPlayingMainTabPage.Mode.LARGE -> spring(Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow)
else -> spring()
}
)
Expand Down Expand Up @@ -321,6 +321,9 @@ class PlayerStateImpl(override val context: AppContext, private val coroutine_sc
}

override fun showLongPressMenu(data: LongPressMenuData) {
// Check lateinit
data.layout_size

long_press_menu_data = data

if (long_press_menu_showing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import com.toasterofbread.spmp.model.settings.category.DesktopSettings
import com.toasterofbread.spmp.resources.getString

internal fun getDesktopCategoryItems(): List<SettingsItem> {
// (I will never learn regex)
// https://stackoverflow.com/a/36760050
val ip_regex: Regex = "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}\$".toRegex()
// https://stackoverflow.com/a/12968117
val port_regex: Regex = "^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])\$".toRegex()

check(ip_regex.matches("127.0.0.1"))
check(port_regex.matches("1111"))

return listOf(
GroupSettingsItem(
getString("s_group_desktop_system")
Expand All @@ -29,6 +20,23 @@ internal fun getDesktopCategoryItems(): List<SettingsItem> {
getString("s_key_startup_command"), getString("s_sub_startup_command")
),

GroupSettingsItem(
getString("s_group_server")
)
) + getServerGroupItems()
}

fun getServerGroupItems(): List<SettingsItem> {
// (I will never learn regex)
// https://stackoverflow.com/a/36760050
val ip_regex: Regex = "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}\$".toRegex()
// https://stackoverflow.com/a/12968117
val port_regex: Regex = "^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])\$".toRegex()

check(ip_regex.matches("127.0.0.1"))
check(port_regex.matches("1111"))

return listOf(
InfoTextSettingsItem(
getString("s_info_server")
),
Expand Down Expand Up @@ -65,7 +73,12 @@ internal fun getDesktopCategoryItems(): List<SettingsItem> {

TextFieldSettingsItem(
SettingsValueState(DesktopSettings.Key.SERVER_LOCAL_COMMAND.getName()),
getString("s_key_server_command"), getString("s_sub_server_command")
getString("s_key_local_server_command"), getString("s_sub_local_server_command")
),

ToggleSettingsItem(
SettingsValueState(DesktopSettings.Key.SERVER_LOCAL_START_AUTOMATICALLY.getName()),
getString("s_key_server_local_start_automatically"), getString("s_sub_server_local_start_automatically")
),

ToggleSettingsItem(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalMaterialApi::class)

package com.toasterofbread.spmp.ui.layout.nowplaying

import LocalNowPlayingExpansion
Expand Down Expand Up @@ -27,6 +29,7 @@ import com.toasterofbread.composekit.platform.composable.composeScope
import com.toasterofbread.composekit.platform.vibrateShort
import com.toasterofbread.composekit.utils.*
import com.toasterofbread.composekit.utils.common.amplifyPercent
import com.toasterofbread.composekit.utils.common.getContrasted
import com.toasterofbread.composekit.utils.composable.RecomposeOnInterval
import com.toasterofbread.composekit.utils.composable.getTop
import com.toasterofbread.composekit.utils.modifier.brushBackground
Expand Down Expand Up @@ -55,14 +58,28 @@ private const val GRADIENT_TOP_START_RATIO = 0.7f
private const val OVERSCROLL_CLEAR_DISTANCE_THRESHOLD_DP = 5f

internal fun PlayerState.getNPBackground(theme_mode: ThemeMode = np_theme_mode): Color {
val pages: List<NowPlayingPage> = NowPlayingPage.ALL.filter { it.shouldShow(this) }

val override: Color? = pages[expansion.swipe_state.currentValue.coerceAtMost(pages.size - 1)].getPlayerBackgroundColourOverride(this)
if (override != null) {
return override
}

return when (theme_mode) {
ThemeMode.BACKGROUND -> theme.accent
ThemeMode.ELEMENTS -> theme.background
ThemeMode.NONE -> theme.background
ThemeMode.ELEMENTS -> theme.card
ThemeMode.NONE -> theme.card
}
}

internal fun PlayerState.getNPOnBackground(): Color {
val pages: List<NowPlayingPage> = NowPlayingPage.ALL.filter { it.shouldShow(this) }

val override: Color? = pages[expansion.swipe_state.currentValue.coerceAtMost(pages.size - 1)].getPlayerBackgroundColourOverride(this)
if (override != null) {
return override.getContrasted()
}

return when (np_theme_mode) {
ThemeMode.BACKGROUND -> theme.on_accent
ThemeMode.ELEMENTS -> theme.accent
Expand Down Expand Up @@ -189,7 +206,6 @@ fun NowPlaying(swipe_state: SwipeableState<Int>, swipe_anchors: Map<Float, Int>,
val song_gradient_depth: Float? =
player.status.m_song?.PlayerGradientDepth?.observe(player.database)?.value

val pages: List<NowPlayingPage> = NowPlayingPage.ALL.filter { it.shouldShow(player) }
val large_page_showing: Boolean = !player.isPortrait() && player.isLargeFormFactor()

val swipe_modifier: Modifier = remember(swipe_anchors, large_page_showing) {
Expand Down Expand Up @@ -232,11 +248,6 @@ fun NowPlaying(swipe_state: SwipeableState<Int>, swipe_anchors: Map<Float, Int>,
}
.brushBackground {
with(density) {
val override_colour: Color? = pages[swipe_state.currentValue.coerceAtMost(pages.size - 1)].getPlayerBackgroundColourOverride(player)
if (override_colour != null) {
return@brushBackground Brush.verticalGradient(listOf(override_colour, override_colour))
}

val screen_height_px = page_height.toPx()
val v_offset = (expansion.get() - 1f).coerceAtLeast(0f) * screen_height_px

Expand Down
Loading

0 comments on commit 9571658

Please sign in to comment.