From 183f8a483504997d0c85978965545697adcf61d5 Mon Sep 17 00:00:00 2001 From: rhenwinch Date: Fri, 5 Jul 2024 16:03:13 +0800 Subject: [PATCH] feat(player-ux): make source links copyable by long clicking server items --- .../controls/common/ListContentHolder.kt | 26 ++++++++++++++++--- .../mobile/player/controls/common/ListItem.kt | 15 +++++++---- .../dialogs/settings/PlayerSettingsPanel.kt | 4 ++- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListContentHolder.kt b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListContentHolder.kt index dbb40780d..9c59b026e 100644 --- a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListContentHolder.kt +++ b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListContentHolder.kt @@ -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 @@ -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 ListContentHolder( modifier: Modifier = Modifier, @@ -42,6 +43,9 @@ internal fun 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, @@ -79,7 +83,23 @@ internal fun 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() + ) + ) + } } ) } diff --git a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListItem.kt b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListItem.kt index 516a19b2f..4ae55ec1f 100644 --- a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListItem.kt +++ b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/common/ListItem.kt @@ -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 @@ -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, @@ -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() @@ -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), @@ -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 = {} ) } } diff --git a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/settings/PlayerSettingsPanel.kt b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/settings/PlayerSettingsPanel.kt index ae12ab7ed..a3663e9fa 100644 --- a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/settings/PlayerSettingsPanel.kt +++ b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/settings/PlayerSettingsPanel.kt @@ -36,7 +36,9 @@ internal fun PlayerSettingsPanel( index = i, selectedIndex = selected, onClick = { - onClick?.invoke(i, item) + if (i != selected) { + onClick?.invoke(i, item) + } } ) }