diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 10c90a6c4..269d85c7a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -49,6 +49,8 @@ import org.schabi.newpipe.local.dialog.PlaylistDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; +import org.schabi.newpipe.ui.components.menu.LongPressAction; +import org.schabi.newpipe.ui.components.menu.LongPressable; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; @@ -152,7 +154,11 @@ public class PlaylistFragment extends BaseListInfoFragment, ): ComposeView { return ComposeView(context).apply { setContent { - LongPressMenu( - longPressable = LongPressable( - title = item.name, - url = item.url?.takeIf { it.isNotBlank() }, - thumbnailUrl = ImageStrategy.choosePreferredImage(item.thumbnails), - uploader = item.uploaderName?.takeIf { it.isNotBlank() }, - uploaderUrl = item.uploaderUrl?.takeIf { it.isNotBlank() }, - viewCount = item.viewCount.takeIf { it >= 0 }, - uploadDate = item.uploadDate?.let { Either.right(it.offsetDateTime()) } - ?: item.textualUploadDate?.let { Either.left(it) }, - decoration = item.duration.takeIf { it >= 0 }?.let { - LongPressable.Decoration.Duration(it) - }, - ), - onDismissRequest = { (this.parent as ViewGroup).removeView(this) }, - longPressActions = LongPressAction.buildActionList(item, false), - onEditActions = {}, - ) + AppTheme { + LongPressMenu( + longPressable = longPressable, + onDismissRequest = { (this.parent as ViewGroup).removeView(this) }, + longPressActions = longPressActions, + onEditActions = {}, + ) + } } } } @@ -157,7 +146,6 @@ fun LongPressMenu( .weight((buttonsPerRow - rowIndex).toFloat()), ) break - } else if (actionIndex >= 0) { val action = actions[actionIndex] LongPressMenuButton( @@ -174,7 +162,6 @@ fun LongPressMenu( .weight(1F), ) rowIndex += 1 - } else if (headerWidthInButtons >= buttonsPerRow) { // this branch is taken if the header is going to fit on one line // (i.e. on phones in portrait) @@ -189,7 +176,6 @@ fun LongPressMenu( .weight(headerWidthInButtons.toFloat()), ) rowIndex += headerWidthInButtons - } else { // this branch is taken if the header will have some buttons to its // right (i.e. on tablets or on phones in landscape) @@ -203,7 +189,6 @@ fun LongPressMenu( .weight(headerWidthInButtons.toFloat()), ) rowIndex += headerWidthInButtons - } actionIndex += 1 } diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressable.kt b/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressable.kt index b4b9cae1a..ada15e6cd 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressable.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressable.kt @@ -1,7 +1,10 @@ package org.schabi.newpipe.ui.components.menu import androidx.compose.runtime.Stable +import org.schabi.newpipe.extractor.stream.StreamInfoItem +import org.schabi.newpipe.extractor.stream.StreamType import org.schabi.newpipe.util.Either +import org.schabi.newpipe.util.image.ImageStrategy import java.time.OffsetDateTime @Stable @@ -20,4 +23,27 @@ data class LongPressable( data object Live : Decoration data class Playlist(val itemCount: Long) : Decoration } + + companion object { + @JvmStatic + fun from(item: StreamInfoItem) = LongPressable( + title = item.name, + url = item.url?.takeIf { it.isNotBlank() }, + thumbnailUrl = ImageStrategy.choosePreferredImage(item.thumbnails), + uploader = item.uploaderName?.takeIf { it.isNotBlank() }, + uploaderUrl = item.uploaderUrl?.takeIf { it.isNotBlank() }, + viewCount = item.viewCount.takeIf { it >= 0 }, + uploadDate = item.uploadDate?.let { Either.right(it.offsetDateTime()) } + ?: item.textualUploadDate?.let { Either.left(it) }, + decoration = if (item.streamType == StreamType.LIVE_STREAM || + item.streamType == StreamType.AUDIO_LIVE_STREAM + ) { + LongPressable.Decoration.Live + } else { + item.duration.takeIf { it >= 0 }?.let { + LongPressable.Decoration.Duration(it) + } + }, + ) + } }