Skip to content

Commit

Permalink
[simba/#33] feat:: 좋아요 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed May 26, 2024
1 parent beb7aec commit 8a57a6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 21 additions & 1 deletion UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class SongActivity : AppCompatActivity() {
binding.songPreviousIv.setOnClickListener{
moveSong(-1)
}
binding.songLikeIv.setOnClickListener {
setLike(songs[nowPos].isLike)
}
}

private fun initSong(){
Expand All @@ -148,6 +151,17 @@ class SongActivity : AppCompatActivity() {
setPlayer(songs[nowPos])
}

private fun setLike(isLike: Boolean){
songs[nowPos].isLike = !isLike
songDB.songDao().updateIsLikeById(!isLike,songs[nowPos].id)

if(!isLike){
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_on)
} else{
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_off)
}
}

private fun moveSong(direct: Int){
if(nowPos + direct < 0){
// nowPos = songs.size -1
Expand All @@ -171,7 +185,6 @@ class SongActivity : AppCompatActivity() {
}
}


private fun getPlayingSongPosition(songId: Int): Int{
for(i in 0 until songs.size){
if(songs[i].id == songId){
Expand All @@ -191,6 +204,13 @@ class SongActivity : AppCompatActivity() {

val music = resources.getIdentifier(song.music,"raw",this.packageName)
mediaPlayer = MediaPlayer.create(this,music)

if(song.isLike){
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_on)
} else{
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_off)
}

setPlayerStatus(song.isPlaying)
}

Expand Down
3 changes: 3 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ interface SongDao {

@Query("SELECT * FROM SongTable WHERE id =:id")
fun getSong(id: Int): Song

@Query("UPDATE SongTable SET isLike= :isLike WHERE id = :id")
fun updateIsLikeById(isLike: Boolean, id: Int)
}

0 comments on commit 8a57a6d

Please sign in to comment.