Skip to content

Commit effbe7a

Browse files
committed
Allow playing local playlists directly
1 parent d76976b commit effbe7a

2 files changed

Lines changed: 60 additions & 11 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.schabi.newpipe.player.playqueue
2+
3+
import android.util.Log
4+
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
5+
import io.reactivex.rxjava3.disposables.Disposable
6+
import io.reactivex.rxjava3.schedulers.Schedulers
7+
import org.schabi.newpipe.App
8+
import org.schabi.newpipe.NewPipeDatabase
9+
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry
10+
import org.schabi.newpipe.local.playlist.LocalPlaylistManager
11+
12+
class LocalPlaylistPlayQueue(info: PlaylistMetadataEntry) : PlayQueue(0, listOf()) {
13+
private val playlistId: Long = info.uid
14+
private var fetchDisposable: Disposable? = null
15+
override var isComplete: Boolean = false
16+
private set
17+
18+
override fun fetch() {
19+
if (isComplete) {
20+
return
21+
}
22+
isComplete = true
23+
24+
fetchDisposable = LocalPlaylistManager(NewPipeDatabase.getInstance(App.instance))
25+
.getPlaylistStreams(playlistId)
26+
.firstOrError()
27+
.subscribeOn(Schedulers.io())
28+
.observeOn(AndroidSchedulers.mainThread())
29+
.subscribe(
30+
{ streamEntries ->
31+
append(streamEntries.map { PlayQueueItem(it.toStreamInfoItem()) })
32+
},
33+
{ e ->
34+
Log.e(TAG, "Error fetching local playlist", e)
35+
notifyChange()
36+
}
37+
)
38+
}
39+
40+
override fun dispose() {
41+
super.dispose()
42+
fetchDisposable?.dispose()
43+
fetchDisposable = null
44+
}
45+
46+
companion object {
47+
private val TAG: String = LocalPlaylistPlayQueue::class.java.getSimpleName()
48+
}
49+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.compose.material.icons.filled.Share
2525
import androidx.compose.ui.graphics.vector.ImageVector
2626
import androidx.core.net.toUri
2727
import kotlinx.coroutines.Dispatchers
28+
import kotlinx.coroutines.reactive.awaitFirst
2829
import kotlinx.coroutines.rx3.await
2930
import kotlinx.coroutines.rx3.awaitSingle
3031
import kotlinx.coroutines.withContext
@@ -47,6 +48,7 @@ import org.schabi.newpipe.local.history.HistoryRecordManager
4748
import org.schabi.newpipe.local.playlist.LocalPlaylistManager
4849
import org.schabi.newpipe.player.helper.PlayerHolder
4950
import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue
51+
import org.schabi.newpipe.player.playqueue.LocalPlaylistPlayQueue
5052
import org.schabi.newpipe.player.playqueue.PlayQueue
5153
import org.schabi.newpipe.player.playqueue.PlayQueueItem
5254
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue
@@ -93,10 +95,7 @@ data class LongPressAction(
9395
UnsetPlaylistThumbnail(18, R.string.unset_playlist_thumbnail, Icons.Default.HideImage),
9496
Unsubscribe(19, R.string.unsubscribe, Icons.Default.Delete),
9597
ShowDetails(20, R.string.play_queue_stream_detail, Icons.Default.Info),
96-
Remove(21, R.string.play_queue_remove, Icons.Default.Delete)
97-
;
98-
99-
// TODO add actions that use the whole list the item belongs to (see wholeListQueue)
98+
Remove(21, R.string.play_queue_remove, Icons.Default.Delete);
10099

101100
fun buildAction(
102101
enabled: () -> Boolean = { true },
@@ -338,13 +337,14 @@ data class LongPressAction(
338337
onDelete: Runnable,
339338
unsetPlaylistThumbnail: Runnable?
340339
): List<LongPressAction> {
341-
return listOf(
342-
Type.Rename.buildAction { onRename.run() },
343-
Type.Delete.buildAction { onDelete.run() },
344-
Type.UnsetPlaylistThumbnail.buildAction(
345-
enabled = { unsetPlaylistThumbnail != null }
346-
) { unsetPlaylistThumbnail?.run() }
347-
)
340+
return buildPlayerActionList { LocalPlaylistPlayQueue(item) } +
341+
listOf(
342+
Type.Rename.buildAction { onRename.run() },
343+
Type.Delete.buildAction { onDelete.run() },
344+
Type.UnsetPlaylistThumbnail.buildAction(
345+
enabled = { unsetPlaylistThumbnail != null }
346+
) { unsetPlaylistThumbnail?.run() }
347+
)
348348
}
349349

350350
@JvmStatic

0 commit comments

Comments
 (0)