From df36d7d0fe571d906895b839f536944525aebbcb Mon Sep 17 00:00:00 2001 From: Namithesh <45740739+Namithesh@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:44:02 +0530 Subject: [PATCH 1/4] trying to reduce one extra click --- .../screens/playlist/LocalPlaylistScreen.kt | 84 +++++++++++++------ 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt index ab3bed418..77a481fd0 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt @@ -765,35 +765,67 @@ fun LocalPlaylistHeader( ) } - if (playlist.playlist.browseId != null) { - IconButton( - onClick = { - scope.launch(Dispatchers.IO) { - val playlistPage = YouTube.playlist(playlist.playlist.browseId).completed().getOrNull() ?: return@launch - database.transaction { - clearPlaylist(playlist.id) - playlistPage.songs - .map(SongItem::toMediaMetadata) - .onEach(::insert) - .mapIndexed { position, song -> - PlaylistSongMap( - songId = song.id, - playlistId = playlist.id, - position = position - ) - } - .forEach(::insert) + // State to control dialog visibility + var showDialog by remember { mutableStateOf(false) } + + // State for context + val context = LocalContext.current + + // Dialog for confirmation + if (showDialog) { + AlertDialog( + onDismissRequest = { showDialog = false }, + title = { Text("Confirm Sync") }, + text = { Text("Are you sure you want to sync this playlist?") }, + confirmButton = { + Button( + onClick = { + scope.launch(Dispatchers.IO) { + // Perform the sync operation + val playlistPage = YouTube.playlist(playlist.playlist.browseId).completed().getOrNull() ?: return@launch + database.transaction { + clearPlaylist(playlist.id) + playlistPage.songs + .map(SongItem::toMediaMetadata) + .onEach(::insert) + .mapIndexed { position, song -> + PlaylistSongMap( + songId = song.id, + playlistId = playlist.id, + position = position + ) } - snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) - } + .forEach(::insert) } - ) { - Icon( - painter = painterResource(R.drawable.sync), - contentDescription = null - ) + snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) } + showDialog = false // Close dialog after confirmation } + ) { + Text("Confirm") + } + }, + dismissButton = { + Button( + onClick = { showDialog = false } // Close dialog without syncing + ) { + Text("Cancel") + } + } + ) + } + // IconButton to trigger the dialog + if (playlist.playlist.browseId != null) { + IconButton( + onClick = { showDialog = true } // Show confirmation dialog + ) { + Icon( + painter = painterResource(R.drawable.sync), + contentDescription = null + ) + } + } +// } when (downloadState) { Download.STATE_COMPLETED -> { @@ -912,4 +944,4 @@ fun LocalPlaylistHeader( } } } -} \ No newline at end of file +// } From 4ad681d4aed50c2d6b157fcae2ae8864000281ed Mon Sep 17 00:00:00 2001 From: Namithesh <45740739+Namithesh@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:49:19 +0530 Subject: [PATCH 2/4] Update LocalPlaylistScreen.kt --- .../screens/playlist/LocalPlaylistScreen.kt | 83 ++++++------------- 1 file changed, 26 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt index 77a481fd0..75e2daa44 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt @@ -765,67 +765,36 @@ fun LocalPlaylistHeader( ) } - // State to control dialog visibility - var showDialog by remember { mutableStateOf(false) } - - // State for context - val context = LocalContext.current - - // Dialog for confirmation - if (showDialog) { - AlertDialog( - onDismissRequest = { showDialog = false }, - title = { Text("Confirm Sync") }, - text = { Text("Are you sure you want to sync this playlist?") }, - confirmButton = { - Button( - onClick = { - scope.launch(Dispatchers.IO) { - // Perform the sync operation - val playlistPage = YouTube.playlist(playlist.playlist.browseId).completed().getOrNull() ?: return@launch - database.transaction { - clearPlaylist(playlist.id) - playlistPage.songs - .map(SongItem::toMediaMetadata) - .onEach(::insert) - .mapIndexed { position, song -> - PlaylistSongMap( - songId = song.id, - playlistId = playlist.id, - position = position - ) + if (playlist.playlist.browseId != null) { + IconButton( + onClick = { + snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) + scope.launch(Dispatchers.IO) { + val playlistPage = YouTube.playlist(playlist.playlist.browseId).completed().getOrNull() ?: return@launch + database.transaction { + clearPlaylist(playlist.id) + playlistPage.songs + .map(SongItem::toMediaMetadata) + .onEach(::insert) + .mapIndexed { position, song -> + PlaylistSongMap( + songId = song.id, + playlistId = playlist.id, + position = position + ) + } + .forEach(::insert) } - .forEach(::insert) + snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) + } } - snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) + ) { + Icon( + painter = painterResource(R.drawable.sync), + contentDescription = null + ) } - showDialog = false // Close dialog after confirmation } - ) { - Text("Confirm") - } - }, - dismissButton = { - Button( - onClick = { showDialog = false } // Close dialog without syncing - ) { - Text("Cancel") - } - } - ) - } - // IconButton to trigger the dialog - if (playlist.playlist.browseId != null) { - IconButton( - onClick = { showDialog = true } // Show confirmation dialog - ) { - Icon( - painter = painterResource(R.drawable.sync), - contentDescription = null - ) - } - } -// } when (downloadState) { Download.STATE_COMPLETED -> { From addb4ec260729e988439ab1eb1549c19cb7b26cb Mon Sep 17 00:00:00 2001 From: Namithesh <45740739+Namithesh@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:03:30 +0530 Subject: [PATCH 3/4] Update strings.xml --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 187474d75..ca209dd8f 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -188,6 +188,7 @@ Playlist imported Removed \"%s\" from playlist + Trying to sync Playlist synced Undo From f4b996150bd190eb024819ce602eb5d9a8cead99 Mon Sep 17 00:00:00 2001 From: Namithesh <45740739+Namithesh@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:05:46 +0530 Subject: [PATCH 4/4] Update LocalPlaylistScreen.kt --- .../zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt index 75e2daa44..e8b92b7d3 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/playlist/LocalPlaylistScreen.kt @@ -768,7 +768,7 @@ fun LocalPlaylistHeader( if (playlist.playlist.browseId != null) { IconButton( onClick = { - snackbarHostState.showSnackbar(context.getString(R.string.playlist_synced)) + snackbarHostState.showSnackbar(context.getString(R.string.playlist_try)) scope.launch(Dispatchers.IO) { val playlistPage = YouTube.playlist(playlist.playlist.browseId).completed().getOrNull() ?: return@launch database.transaction {