Skip to content

Commit 4a748ca

Browse files
committed
Click on long press menu subtitle opens channel details
1 parent 18abe2c commit 4a748ca

3 files changed

Lines changed: 114 additions & 20 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
package org.schabi.newpipe.ui.components.menu
44

5+
import android.content.Context
56
import android.content.res.Configuration
67
import androidx.compose.foundation.basicMarquee
8+
import androidx.compose.foundation.clickable
79
import androidx.compose.foundation.layout.Arrangement
810
import androidx.compose.foundation.layout.Box
911
import androidx.compose.foundation.layout.BoxWithConstraints
@@ -57,9 +59,12 @@ import androidx.compose.ui.graphics.vector.ImageVector
5759
import androidx.compose.ui.platform.LocalContext
5860
import androidx.compose.ui.res.painterResource
5961
import androidx.compose.ui.res.stringResource
60-
import androidx.compose.ui.semantics.contentDescription
61-
import androidx.compose.ui.semantics.semantics
62+
import androidx.compose.ui.text.SpanStyle
63+
import androidx.compose.ui.text.buildAnnotatedString
64+
import androidx.compose.ui.text.font.FontWeight
6265
import androidx.compose.ui.text.style.TextAlign
66+
import androidx.compose.ui.text.style.TextDecoration
67+
import androidx.compose.ui.text.withStyle
6368
import androidx.compose.ui.tooling.preview.Preview
6469
import androidx.compose.ui.tooling.preview.PreviewParameter
6570
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
@@ -72,6 +77,7 @@ import org.schabi.newpipe.R
7277
import org.schabi.newpipe.player.playqueue.PlayQueue
7378
import org.schabi.newpipe.player.playqueue.SinglePlayQueue
7479
import org.schabi.newpipe.ui.theme.AppTheme
80+
import org.schabi.newpipe.ui.theme.customColors
7581
import org.schabi.newpipe.util.Either
7682
import org.schabi.newpipe.util.Localization
7783
import java.time.OffsetDateTime
@@ -346,27 +352,78 @@ fun LongPressMenuHeader(
346352
modifier = Modifier.basicMarquee(iterations = Int.MAX_VALUE),
347353
)
348354

349-
val subtitle = Localization.concatenateStrings(
350-
item.uploader,
351-
item.uploadDate?.match<String>(
352-
{ it },
353-
{ Localization.relativeTime(it) }
354-
),
355-
item.viewCount?.let { Localization.localizeViewCount(ctx, it) }
355+
val subtitle = getSubtitleAnnotatedString(
356+
item = item,
357+
linkColor = MaterialTheme.customColors.onSurfaceVariantLink,
358+
ctx = ctx,
356359
)
357360
if (subtitle.isNotBlank()) {
358361
Spacer(Modifier.height(1.dp))
362+
359363
Text(
360364
text = subtitle,
361365
style = MaterialTheme.typography.bodyMedium,
362-
modifier = Modifier.basicMarquee(iterations = Int.MAX_VALUE),
366+
modifier = if (item.uploaderUrl.isNullOrBlank()) {
367+
Modifier
368+
} else {
369+
Modifier.clickable {
370+
// TODO handle click on uploader URL
371+
}
372+
}.basicMarquee(iterations = Int.MAX_VALUE)
363373
)
364374
}
365375
}
366376
}
367377
}
368378
}
369379

380+
fun getSubtitleAnnotatedString(
381+
item: LongPressable,
382+
linkColor: Color,
383+
ctx: Context,
384+
) = buildAnnotatedString {
385+
var shouldAddSeparator = false
386+
if (!item.uploaderUrl.isNullOrBlank()) {
387+
withStyle(
388+
SpanStyle(
389+
fontWeight = FontWeight.Bold,
390+
color = linkColor,
391+
textDecoration = TextDecoration.Underline
392+
)
393+
) {
394+
if (item.uploader.isNullOrBlank()) {
395+
append(ctx.getString(R.string.show_channel_details))
396+
} else {
397+
append(item.uploader)
398+
}
399+
}
400+
shouldAddSeparator = true
401+
} else if (!item.uploader.isNullOrBlank()) {
402+
append(item.uploader)
403+
shouldAddSeparator = true
404+
}
405+
406+
val uploadDate = item.uploadDate?.match<String>(
407+
{ it },
408+
{ Localization.relativeTime(it) }
409+
)
410+
if (!uploadDate.isNullOrBlank()) {
411+
if (shouldAddSeparator) {
412+
append(Localization.DOT_SEPARATOR)
413+
}
414+
shouldAddSeparator = true
415+
append(uploadDate)
416+
}
417+
418+
val viewCount = item.viewCount?.let { Localization.localizeViewCount(ctx, it) }
419+
if (!viewCount.isNullOrBlank()) {
420+
if (shouldAddSeparator) {
421+
append(Localization.DOT_SEPARATOR)
422+
}
423+
append(viewCount)
424+
}
425+
}
426+
370427
@Composable
371428
fun LongPressMenuButton(
372429
icon: ImageVector,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.schabi.newpipe.ui.theme
2+
3+
import androidx.compose.material3.MaterialTheme
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.Immutable
6+
import androidx.compose.runtime.ReadOnlyComposable
7+
import androidx.compose.runtime.staticCompositionLocalOf
8+
import androidx.compose.ui.graphics.Color
9+
10+
@Immutable
11+
data class CustomColors(
12+
val onSurfaceVariantLink: Color = Color.Unspecified,
13+
)
14+
15+
val onSurfaceVariantLinkLight = Color(0xFF5060B0)
16+
17+
val onSurfaceVariantLinkDark = Color(0xFFC0D0FF)
18+
19+
val lightCustomColors = CustomColors(
20+
onSurfaceVariantLink = onSurfaceVariantLinkLight
21+
)
22+
23+
val darkCustomColors = CustomColors(
24+
onSurfaceVariantLink = onSurfaceVariantLinkDark
25+
)
26+
27+
val LocalCustomColors = staticCompositionLocalOf { CustomColors() }
28+
29+
val MaterialTheme.customColors: CustomColors
30+
@Composable
31+
@ReadOnlyComposable
32+
get() = LocalCustomColors.current

app/src/main/java/org/schabi/newpipe/ui/theme/Theme.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.material3.MaterialTheme
55
import androidx.compose.material3.darkColorScheme
66
import androidx.compose.material3.lightColorScheme
77
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.CompositionLocalProvider
89
import androidx.compose.ui.graphics.Color
910
import androidx.compose.ui.platform.LocalContext
1011
import androidx.preference.PreferenceManager
@@ -93,14 +94,18 @@ fun AppTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable
9394
val theme = sharedPreferences.getString("theme", "auto_device_theme")
9495
val nightTheme = sharedPreferences.getString("night_theme", "dark_theme")
9596

96-
MaterialTheme(
97-
colorScheme = if (!useDarkTheme) {
98-
lightScheme
99-
} else if (theme == "black_theme" || nightTheme == "black_theme") {
100-
blackScheme
101-
} else {
102-
darkScheme
103-
},
104-
content = content
105-
)
97+
CompositionLocalProvider(
98+
LocalCustomColors provides if (!useDarkTheme) lightCustomColors else darkCustomColors
99+
) {
100+
MaterialTheme(
101+
colorScheme = if (!useDarkTheme) {
102+
lightScheme
103+
} else if (theme == "black_theme" || nightTheme == "black_theme") {
104+
blackScheme
105+
} else {
106+
darkScheme
107+
},
108+
content = content
109+
)
110+
}
106111
}

0 commit comments

Comments
 (0)