Skip to content

Commit

Permalink
feat: added back the add to library buttons closes #189
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Jul 10, 2024
1 parent 70e0ea7 commit 87ab4eb
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/malopieds/innertune/ui/menu/AlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -75,6 +75,7 @@ fun AlbumMenu(
originalAlbum: Album,
navController: NavController,
onDismiss: () -> Unit,
selectAction: () -> Unit = {},
) {
val context = LocalContext.current
val database = LocalDatabase.current
Expand Down Expand Up @@ -259,7 +260,7 @@ fun AlbumMenu(
},
)

Divider()
HorizontalDivider()

GridMenu(
contentPadding =
Expand Down Expand Up @@ -343,5 +344,14 @@ fun AlbumMenu(
}
context.startActivity(Intent.createChooser(intent, null))
}
if (selectAction != {}) {
GridMenuItem(
icon = R.drawable.select_all,
title = R.string.select,
) {
onDismiss()
selectAction()
}
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/malopieds/innertune/ui/menu/PlayerMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fun PlayerMenu(
val playerConnection = LocalPlayerConnection.current ?: return
val playerVolume = playerConnection.service.playerVolume.collectAsState()
val activityResultLauncher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { }
val librarySong by database.song(mediaMetadata.id).collectAsState(initial = null)

val download by LocalDownloadUtil.current.getDownload(mediaMetadata.id).collectAsState(initial = null)

Expand Down Expand Up @@ -301,6 +302,26 @@ fun PlayerMenu(
)
},
)
if (librarySong?.song?.inLibrary != null) {
GridMenuItem(
icon = R.drawable.library_add_check,
title = R.string.remove_from_library,
) {
database.query {
inLibrary(mediaMetadata.id, null)
}
}
} else {
GridMenuItem(
icon = R.drawable.library_add,
title = R.string.add_to_library,
) {
database.transaction {
insert(mediaMetadata)
inLibrary(mediaMetadata.id, LocalDateTime.now())
}
}
}
GridMenuItem(
icon = R.drawable.artist,
title = R.string.view_artist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.malopieds.innertune.db.entities.PlaylistSongMap
import com.malopieds.innertune.db.entities.Song
import com.malopieds.innertune.extensions.toMediaItem
import com.malopieds.innertune.models.MediaMetadata
import com.malopieds.innertune.models.toMediaMetadata
import com.malopieds.innertune.playback.ExoDownloadService
import com.malopieds.innertune.playback.queues.ListQueue
import com.malopieds.innertune.ui.component.DefaultDialog
Expand All @@ -74,6 +75,14 @@ fun SelectionSongMenu(
val downloadUtil = LocalDownloadUtil.current
val playerConnection = LocalPlayerConnection.current ?: return

val allInLibrary by remember {
mutableStateOf(
songSelection.all {
it.song.inLibrary != null
},
)
}

var downloadState by remember {
mutableIntStateOf(Download.STATE_STOPPED)
}
Expand Down Expand Up @@ -244,6 +253,31 @@ fun SelectionSongMenu(
clearAction()
}

if (allInLibrary) {
GridMenuItem(
icon = R.drawable.library_add_check,
title = R.string.remove_from_library,
) {
database.query {
songSelection.forEach { song ->
inLibrary(song.id, null)
}
}
}
} else {
GridMenuItem(
icon = R.drawable.library_add,
title = R.string.add_to_library,
) {
database.transaction {
songSelection.forEach { song ->
insert(song.toMediaMetadata())
inLibrary(song.id, LocalDateTime.now())
}
}
}
}

GridMenuItem(
icon = R.drawable.queue_music,
title = R.string.add_to_queue,
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/malopieds/innertune/ui/menu/SongMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,25 @@ fun SongMenu(
}
context.startActivity(Intent.createChooser(intent, null))
}
if (song.song.inLibrary == null) {
GridMenuItem(
icon = R.drawable.library_add,
title = R.string.add_to_library,
) {
database.query {
update(song.song.toggleLibrary())
}
}
} else {
GridMenuItem(
icon = R.drawable.library_add_check,
title = R.string.remove_from_library,
) {
database.query {
update(song.song.toggleLibrary())
}
}
}
if (event != null) {
GridMenuItem(
icon = R.drawable.delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ fun YouTubeSongMenu(
playerConnection.addToQueue((song.toMediaItem()))
onDismiss()
}
if (librarySong?.song?.inLibrary != null) {
GridMenuItem(
icon = R.drawable.library_add_check,
title = R.string.remove_from_library,
) {
database.query {
inLibrary(song.id, null)
}
}
} else {
GridMenuItem(
icon = R.drawable.library_add,
title = R.string.add_to_library,
) {
database.transaction {
insert(song.toMediaMetadata())
inLibrary(song.id, LocalDateTime.now())
}
}
}
GridMenuItem(
icon = R.drawable.playlist_add,
title = R.string.add_to_playlist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ fun AlbumScreen(
originalAlbum = Album(albumWithSongs.album, albumWithSongs.artists),
navController = navController,
onDismiss = menuState::dismiss,
selectAction = { selection = true },
)
}
},
Expand Down

0 comments on commit 87ab4eb

Please sign in to comment.