Skip to content

Commit

Permalink
feat(player-ux): make source links copyable by long clicking server i…
Browse files Browse the repository at this point in the history
…tems
  • Loading branch information
rhenwinch committed Jul 5, 2024
1 parent cf4f7e8 commit 183f8a4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.flixclusive.feature.mobile.player.controls.common

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -20,17 +19,19 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.flixclusive.core.ui.common.util.fadingEdge
import com.flixclusive.core.ui.mobile.util.getFeedbackOnLongPress
import com.flixclusive.core.ui.player.PlayerProviderState
import com.flixclusive.core.util.exception.safeCall
import com.flixclusive.model.provider.SourceLink
import com.flixclusive.model.provider.Subtitle
import com.flixclusive.provider.ProviderApi

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun <Type> ListContentHolder(
modifier: Modifier = Modifier,
Expand All @@ -42,6 +43,9 @@ internal fun <Type> ListContentHolder(
itemState: PlayerProviderState = PlayerProviderState.SELECTED,
onItemClick: (Int) -> Unit,
) {
val clipboardManager = LocalClipboardManager.current
val hapticFeedback = getFeedbackOnLongPress()

val listState = rememberLazyListState()
val listBottomFade = Brush.verticalGradient(
0.15F to Color.Transparent,
Expand Down Expand Up @@ -79,7 +83,23 @@ internal fun <Type> ListContentHolder(
selectedIndex = selectedIndex,
itemState = itemState,
onClick = {
onItemClick(i)
if (i != selectedIndex) {
onItemClick(i)
}
},
onLongClick = {
if (item is SourceLink) {
hapticFeedback()
clipboardManager.setText(
AnnotatedString(
"""
Source name: ${item.name}
Source link: ${item.url}
Source headers: ${item.customHeaders}
""".trimIndent()
)
)
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.flixclusive.feature.mobile.player.controls.common

import androidx.compose.foundation.clickable
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -37,6 +38,7 @@ import com.flixclusive.core.ui.common.util.placeholderEffect
import com.flixclusive.core.ui.player.PlayerProviderState
import com.flixclusive.core.util.R as UtilR

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun ListItem(
modifier: Modifier = Modifier,
Expand All @@ -45,6 +47,7 @@ internal fun ListItem(
selectedIndex: Int,
itemState: PlayerProviderState = PlayerProviderState.SELECTED,
onClick: () -> Unit,
onLongClick: () -> Unit = {}
) {
val baseStyle = MaterialTheme.typography.labelLarge
val unselectedColor = LocalContentColor.current.onMediumEmphasis()
Expand All @@ -63,9 +66,10 @@ internal fun ListItem(

Box(
modifier = modifier
.clickable(enabled = index != selectedIndex) {
onClick()
}
.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
)
) {
Row(
horizontalArrangement = Arrangement.spacedBy(15.dp),
Expand Down Expand Up @@ -149,7 +153,8 @@ private fun SheetItemLoadingPreview() {
index = 0,
selectedIndex = if (it < 2) 0 else 1,
itemState = PlayerProviderState.entries[it % PlayerProviderState.entries.size],
onClick = {}
onClick = {},
onLongClick = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ internal fun PlayerSettingsPanel(
index = i,
selectedIndex = selected,
onClick = {
onClick?.invoke(i, item)
if (i != selected) {
onClick?.invoke(i, item)
}
}
)
}
Expand Down

0 comments on commit 183f8a4

Please sign in to comment.