Skip to content

Commit

Permalink
ui: Remove like when removing from library
Browse files Browse the repository at this point in the history
* fixes #33
  • Loading branch information
mikooomich committed Sep 8, 2024
1 parent 8e4382c commit f5f0996
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/dd3boh/outertune/db/DatabaseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,20 @@ interface DatabaseDao {
incrementPlayCount(songId, time.year, time.monthValue)
}

@Transaction
fun toggleInLibrary(songId: String, inLibrary: LocalDateTime?) {
inLibrary(songId, inLibrary)
if (inLibrary == null) {
removeLike(songId)
}
}

@Query("UPDATE song SET inLibrary = :inLibrary WHERE id = :songId")
fun inLibrary(songId: String, inLibrary: LocalDateTime?)

@Query("UPDATE song SET liked = 0, likedDate = null WHERE id = :songId")
fun removeLike(songId: String)

@Query("UPDATE song SET inLibrary = null WHERE localPath = null")
fun disableInvalidLocalSongs()
@Query("UPDATE song SET inLibrary = null, localPath = null WHERE id = :songId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ data class SongEntity(
}
}

fun toggleLibrary() = copy(inLibrary = if (inLibrary == null) LocalDateTime.now() else null)
fun toggleLibrary() = copy(
inLibrary = if (inLibrary == null) LocalDateTime.now() else null,
liked = if (inLibrary == null) liked else false,
likedDate = if (inLibrary == null) likedDate else null
)

/**
* Returns a full date string. If no full date is present, returns the year.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/ui/menu/AlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fun AlbumMenu(
) {
database.transaction {
songs.forEach {
inLibrary(it.id, null)
toggleInLibrary(it.id, null)
}
}
}
Expand All @@ -297,7 +297,7 @@ fun AlbumMenu(
) {
database.transaction {
songs.forEach {
inLibrary(it.id, LocalDateTime.now())
toggleInLibrary(it.id, LocalDateTime.now())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/ui/menu/PlayerMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fun PlayerMenu(
title = R.string.remove_from_library,
) {
database.query {
inLibrary(mediaMetadata.id, null)
toggleInLibrary(mediaMetadata.id, null)
}
}
} else {
Expand All @@ -345,7 +345,7 @@ fun PlayerMenu(
) {
database.transaction {
insert(mediaMetadata)
inLibrary(mediaMetadata.id, LocalDateTime.now())
toggleInLibrary(mediaMetadata.id, LocalDateTime.now())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fun SelectionSongMenu(
) {
database.transaction {
songSelection.forEach { song ->
inLibrary(song.id, null)
toggleInLibrary(song.id, null)
}
}
}
Expand All @@ -249,7 +249,7 @@ fun SelectionSongMenu(
database.transaction {
songSelection.forEach { song ->
if (!song.song.isLocal) {
inLibrary(song.id, LocalDateTime.now())
toggleInLibrary(song.id, LocalDateTime.now())
}
}
}
Expand Down

0 comments on commit f5f0996

Please sign in to comment.