Skip to content

Commit 84687b8

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Convert newpipe/local/playlist/RemotePlaylistManager to kotlin
1 parent 8893a27 commit 84687b8

2 files changed

Lines changed: 62 additions & 69 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/playlist/RemotePlaylistManager.java

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2018-2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package org.schabi.newpipe.local.playlist
8+
9+
import io.reactivex.rxjava3.core.Completable
10+
import io.reactivex.rxjava3.core.Flowable
11+
import io.reactivex.rxjava3.core.Single
12+
import io.reactivex.rxjava3.schedulers.Schedulers
13+
import org.schabi.newpipe.database.AppDatabase
14+
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity
15+
import org.schabi.newpipe.extractor.playlist.PlaylistInfo
16+
17+
class RemotePlaylistManager(private val database: AppDatabase) {
18+
private val playlistRemoteTable = database.playlistRemoteDAO()
19+
20+
val playlists: Flowable<MutableList<PlaylistRemoteEntity>>
21+
get() = playlistRemoteTable.playlists.subscribeOn(Schedulers.io())
22+
23+
fun getPlaylist(playlistId: Long): Flowable<PlaylistRemoteEntity> {
24+
return playlistRemoteTable.getPlaylist(playlistId).subscribeOn(Schedulers.io())
25+
}
26+
27+
fun getPlaylist(info: PlaylistInfo): Flowable<MutableList<PlaylistRemoteEntity>> {
28+
return playlistRemoteTable.getPlaylist(info.serviceId.toLong(), info.url)
29+
.subscribeOn(Schedulers.io())
30+
}
31+
32+
fun deletePlaylist(playlistId: Long): Single<Int> {
33+
return Single.fromCallable { playlistRemoteTable.deletePlaylist(playlistId) }
34+
.subscribeOn(Schedulers.io())
35+
}
36+
37+
fun updatePlaylists(
38+
updateItems: List<PlaylistRemoteEntity>,
39+
deletedItems: List<Long>
40+
): Completable {
41+
return Completable.fromRunnable {
42+
database.runInTransaction {
43+
deletedItems.forEach { playlistRemoteTable.deletePlaylist(it) }
44+
updateItems.forEach { playlistRemoteTable.upsert(it) }
45+
}
46+
}.subscribeOn(Schedulers.io())
47+
}
48+
49+
fun onBookmark(playlistInfo: PlaylistInfo): Single<Long> {
50+
return Single.fromCallable {
51+
val playlist = PlaylistRemoteEntity(playlistInfo)
52+
playlistRemoteTable.upsert(playlist)
53+
}.subscribeOn(Schedulers.io())
54+
}
55+
56+
fun onUpdate(playlistId: Long, playlistInfo: PlaylistInfo): Single<Int> {
57+
return Single.fromCallable {
58+
val playlist = PlaylistRemoteEntity(playlistInfo).apply { uid = playlistId }
59+
playlistRemoteTable.update(playlist)
60+
}.subscribeOn(Schedulers.io())
61+
}
62+
}

0 commit comments

Comments
 (0)