Make imported playlist synchronizable (#196)
This commit is contained in:
@@ -206,6 +206,9 @@ interface Database {
|
||||
@Query("UPDATE SongPlaylistMap SET position = position + 1 WHERE playlistId = :playlistId AND position >= :fromPosition AND position <= :toPosition")
|
||||
fun incrementSongPositions(playlistId: Long, fromPosition: Int, toPosition: Int)
|
||||
|
||||
@Query("DELETE FROM SongPlaylistMap WHERE playlistId = :id")
|
||||
fun clearPlaylist(id: Long)
|
||||
|
||||
@Query("SELECT loudnessDb FROM Format WHERE songId = :songId")
|
||||
fun loudnessDb(songId: String): Flow<Float?>
|
||||
|
||||
@@ -349,7 +352,7 @@ interface Database {
|
||||
views = [
|
||||
SortedSongPlaylistMap::class
|
||||
],
|
||||
version = 16,
|
||||
version = 17,
|
||||
exportSchema = true,
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 1, to = 2),
|
||||
@@ -364,6 +367,7 @@ interface Database {
|
||||
AutoMigration(from = 12, to = 13),
|
||||
AutoMigration(from = 13, to = 14),
|
||||
AutoMigration(from = 15, to = 16),
|
||||
AutoMigration(from = 16, to = 17),
|
||||
],
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
|
||||
@@ -9,11 +9,5 @@ import androidx.room.PrimaryKey
|
||||
data class Playlist(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
val name: String,
|
||||
) {
|
||||
companion object {
|
||||
val Empty = Playlist(
|
||||
id = 0,
|
||||
name = ""
|
||||
)
|
||||
}
|
||||
}
|
||||
val browseId: String? = null
|
||||
)
|
||||
|
||||
@@ -61,8 +61,12 @@ import it.vfsfitvnm.vimusic.utils.forcePlayAtIndex
|
||||
import it.vfsfitvnm.vimusic.utils.forcePlayFromBeginning
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import it.vfsfitvnm.vimusic.utils.toMediaItem
|
||||
import it.vfsfitvnm.youtubemusic.YouTube
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@ExperimentalFoundationApi
|
||||
@ExperimentalAnimationApi
|
||||
@@ -245,6 +249,43 @@ fun LocalPlaylistScreen(playlistId: Long) {
|
||||
}
|
||||
)
|
||||
|
||||
playlistWithSongs.playlist.browseId?.let { browseId ->
|
||||
MenuEntry(
|
||||
icon = R.drawable.sync,
|
||||
text = "Sync",
|
||||
onClick = {
|
||||
menuState.hide()
|
||||
transaction {
|
||||
runBlocking(Dispatchers.IO) {
|
||||
withContext(Dispatchers.IO) {
|
||||
YouTube.playlist(browseId)?.map {
|
||||
it.next()
|
||||
}?.map { playlist ->
|
||||
playlist.copy(items = playlist.items?.filter { it.info.endpoint != null })
|
||||
}
|
||||
}
|
||||
}?.getOrNull()?.let { remotePlaylist ->
|
||||
Database.clearPlaylist(playlistWithSongs.playlist.id)
|
||||
|
||||
remotePlaylist.items?.forEachIndexed { index, song ->
|
||||
song.toMediaItem(browseId, remotePlaylist)?.let { mediaItem ->
|
||||
Database.insert(mediaItem)
|
||||
|
||||
Database.insert(
|
||||
SongPlaylistMap(
|
||||
songId = mediaItem.mediaId,
|
||||
playlistId = playlistId,
|
||||
position = index
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
MenuEntry(
|
||||
icon = R.drawable.trash,
|
||||
text = "Delete",
|
||||
|
||||
@@ -252,7 +252,8 @@ fun PlaylistScreen(browseId: String) {
|
||||
Database.insert(
|
||||
Playlist(
|
||||
name = playlist.title
|
||||
?: "Unknown"
|
||||
?: "Unknown",
|
||||
browseId = browseId
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
27
app/src/main/res/drawable/sync.xml
Normal file
27
app/src/main/res/drawable/sync.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="512"
|
||||
android:viewportHeight="512">
|
||||
<path
|
||||
android:pathData="M434.67,285.59v-29.8C434.67,157.06 354.43,77 255.47,77a179,179 0,0 0,-140.14 67.36m-38.53,82v29.8C76.8,355 157,435 256,435a180.45,180.45 0,0 0,140 -66.92"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="32"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#000"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M32,256l44,-44l46,44"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="32"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#000"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M480,256l-44,44l-46,-44"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="32"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#000"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
Reference in New Issue
Block a user