Skip to content

Commit

Permalink
This rewert afda980
Browse files Browse the repository at this point in the history
  • Loading branch information
MaloyBegonia committed Feb 15, 2025
1 parent afda980 commit e88fb8e
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 25 deletions.
63 changes: 57 additions & 6 deletions app/schemas/com.maloy.muzza.db.InternalDatabase/13.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 13,
"identityHash": "cf1917f48fb44c8b82e3aa4a03223b2d",
"identityHash": "3eab7e4a1f6aceefcce0dc809aa2ec17",
"entities": [
{
"tableName": "song",
Expand Down Expand Up @@ -90,7 +90,7 @@
},
{
"tableName": "artist",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnailUrl` TEXT, `lastUpdateTime` INTEGER NOT NULL, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnailUrl` TEXT, `channelId` TEXT, `lastUpdateTime` INTEGER NOT NULL, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand All @@ -110,6 +110,12 @@
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "channelId",
"columnName": "channelId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "lastUpdateTime",
"columnName": "lastUpdateTime",
Expand All @@ -134,14 +140,20 @@
},
{
"tableName": "album",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT NOT NULL, `year` INTEGER, `thumbnailUrl` TEXT, `themeColor` INTEGER, `songCount` INTEGER NOT NULL, `duration` INTEGER NOT NULL, `lastUpdateTime` INTEGER NOT NULL, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `playlistId` TEXT, `title` TEXT NOT NULL, `year` INTEGER, `thumbnailUrl` TEXT, `themeColor` INTEGER, `songCount` INTEGER NOT NULL, `duration` INTEGER NOT NULL, `lastUpdateTime` INTEGER NOT NULL, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "playlistId",
"columnName": "playlistId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "title",
"columnName": "title",
Expand Down Expand Up @@ -202,7 +214,7 @@
},
{
"tableName": "playlist",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `browseId` TEXT, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `browseId` TEXT, `isEditable` INTEGER NOT NULL DEFAULT true, `bookmarkedAt` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand All @@ -222,6 +234,13 @@
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isEditable",
"columnName": "isEditable",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "true"
},
{
"fieldPath": "bookmarkedAt",
"columnName": "bookmarkedAt",
Expand Down Expand Up @@ -465,7 +484,7 @@
},
{
"tableName": "playlist_song_map",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `playlistId` TEXT NOT NULL, `songId` TEXT NOT NULL, `position` INTEGER NOT NULL, FOREIGN KEY(`playlistId`) REFERENCES `playlist`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`songId`) REFERENCES `song`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `playlistId` TEXT NOT NULL, `songId` TEXT NOT NULL, `position` INTEGER NOT NULL, `setVideoId` TEXT, FOREIGN KEY(`playlistId`) REFERENCES `playlist`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`songId`) REFERENCES `song`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
Expand All @@ -490,6 +509,12 @@
"columnName": "position",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "setVideoId",
"columnName": "setVideoId",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
Expand Down Expand Up @@ -800,6 +825,32 @@
]
}
]
},
{
"tableName": "set_video_id",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`videoId` TEXT NOT NULL, `setVideoId` TEXT, PRIMARY KEY(`videoId`))",
"fields": [
{
"fieldPath": "videoId",
"columnName": "videoId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "setVideoId",
"columnName": "setVideoId",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"videoId"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [
Expand All @@ -818,7 +869,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'cf1917f48fb44c8b82e3aa4a03223b2d')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3eab7e4a1f6aceefcce0dc809aa2ec17')"
]
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/maloy/muzza/db/MusicDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class MusicDatabase(
FormatEntity::class,
LyricsEntity::class,
Event::class,
RelatedSongMap::class
RelatedSongMap::class,
SetVideoIdEntity::class
],
views = [
SortedSongArtistMap::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.Immutable
import androidx.room.Entity
import androidx.room.PrimaryKey
import org.apache.commons.lang3.RandomStringUtils
import java.time.LocalDateTime

@Suppress("DEPRECATION")
@Immutable
Expand All @@ -13,7 +12,6 @@ data class PlaylistEntity(
@PrimaryKey val id: String = generatePlaylistId(),
val name: String,
val browseId: String? = null,
val bookmarkedAt: LocalDateTime? = null,
) {
companion object {
const val LIKED_PLAYLIST_ID = "LP_LIKED"
Expand Down
23 changes: 9 additions & 14 deletions app/src/main/java/com/maloy/muzza/ui/menu/AddToPlaylistDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -43,11 +44,10 @@ fun AddToPlaylistDialog(
) {
val database = LocalDatabase.current
val coroutineScope = rememberCoroutineScope()

var playlists by remember {
val playlists by remember {
mutableStateOf(emptyList<Playlist>())
}
var showCreatePlaylistDialog by rememberSaveable {
var showAddPlaylistDialog by rememberSaveable {
mutableStateOf(false)
}

Expand All @@ -64,12 +64,6 @@ fun AddToPlaylistDialog(
mutableStateOf(emptyList<String>())
}

LaunchedEffect(Unit) {
database.playlistsByCreateDateAsc().collect {
playlists = it.asReversed()
}
}

if (isVisible) {
ListDialog(
onDismiss = onDismiss
Expand All @@ -79,14 +73,14 @@ fun AddToPlaylistDialog(
title = stringResource(R.string.create_playlist),
thumbnailContent = {
Image(
painter = painterResource(R.drawable.add),
imageVector = Icons.Rounded.Add,
contentDescription = null,
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
modifier = Modifier.size(ListThumbnailSize)
)
},
modifier = Modifier.clickable {
showCreatePlaylistDialog = true
showAddPlaylistDialog = true
}
)
}
Expand Down Expand Up @@ -114,11 +108,11 @@ fun AddToPlaylistDialog(
}
}

if (showCreatePlaylistDialog) {
if (showAddPlaylistDialog) {
TextFieldDialog(
icon = { Icon(painter = painterResource(R.drawable.add), contentDescription = null) },
title = { Text(text = stringResource(R.string.create_playlist)) },
onDismiss = { showCreatePlaylistDialog = false },
onDismiss = { showAddPlaylistDialog = false },
onDone = { playlistName ->
database.query {
insert(
Expand All @@ -131,6 +125,7 @@ fun AddToPlaylistDialog(
)
}

// duplicate songs warning
if (showDuplicateDialog) {
DefaultDialog(
title = { Text(stringResource(R.string.duplicates)) },
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/maloy/muzza/ui/menu/AlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ fun AlbumMenu(
mutableStateOf(emptyList<Song>())
}

val coroutineScope = rememberCoroutineScope()

LaunchedEffect(Unit) {
database.albumSongs(album.id).collect {
songs = it
Expand Down Expand Up @@ -138,7 +140,16 @@ fun AlbumMenu(

AddToPlaylistDialog(
isVisible = showChoosePlaylistDialog,
onGetSong = { songs.map { it.id } },
onGetSong = { playlist ->
coroutineScope.launch(Dispatchers.IO) {
playlist.playlist.browseId?.let { playlistId ->
album.album.playlistId?.let { addPlaylistId ->
YouTube.addPlaylistToPlaylist(playlistId, addPlaylistId)
}
}
}
songs.map { it.id }
},
onDismiss = {
showChoosePlaylistDialog = false
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/maloy/muzza/ui/menu/YouTubeAlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -56,6 +57,8 @@ import com.maloy.muzza.ui.component.GridMenuItem
import com.maloy.muzza.ui.component.ListDialog
import com.maloy.muzza.ui.component.YouTubeListItem
import com.maloy.muzza.utils.reportException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Composable
fun YouTubeAlbumMenu(
Expand All @@ -68,6 +71,7 @@ fun YouTubeAlbumMenu(
val downloadUtil = LocalDownloadUtil.current
val playerConnection = LocalPlayerConnection.current ?: return
val album by database.albumWithSongs(albumItem.id).collectAsState(initial = null)
val coroutineScope = rememberCoroutineScope()

LaunchedEffect(Unit) {
database.album(albumItem.id).collect { album ->
Expand Down Expand Up @@ -110,7 +114,14 @@ fun YouTubeAlbumMenu(

AddToPlaylistDialog(
isVisible = showChoosePlaylistDialog,
onGetSong = {
onGetSong = { playlist ->
coroutineScope.launch(Dispatchers.IO) {
playlist.playlist.browseId?.let { playlistId ->
album?.album?.playlistId?.let { addPlaylistId ->
YouTube.addPlaylistToPlaylist(playlistId, addPlaylistId)
}
}
}
album?.songs?.map { it.id }.orEmpty()
},
onDismiss = { showChoosePlaylistDialog = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.maloy.muzza.db.MusicDatabase
import com.maloy.muzza.extensions.reversed
import com.maloy.muzza.extensions.toEnum
import com.maloy.muzza.playback.DownloadUtil
import com.maloy.muzza.utils.SyncUtils
import com.maloy.muzza.utils.dataStore
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
Expand All @@ -24,6 +25,7 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -33,6 +35,7 @@ class AutoPlaylistViewModel @Inject constructor(
database: MusicDatabase,
downloadUtil: DownloadUtil,
savedStateHandle: SavedStateHandle,
private val syncUtils: SyncUtils,
) : ViewModel() {
val playlist = savedStateHandle.get<String>("playlist")!!

Expand Down Expand Up @@ -74,4 +77,8 @@ class AutoPlaylistViewModel @Inject constructor(
else -> MutableStateFlow(emptyList())
}
}.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())

fun syncLikedSongs() {
viewModelScope.launch(Dispatchers.IO) { syncUtils.syncLikedSongs() }
}
}

0 comments on commit e88fb8e

Please sign in to comment.