From 8a57a6d95e2fe32480c202a13c9d7005fb0f6e1f Mon Sep 17 00:00:00 2001 From: BAEK0111 Date: Sun, 26 May 2024 16:12:59 +0900 Subject: [PATCH] =?UTF-8?q?[simba/#33]=20feat::=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/umc_6th/SongActivity.kt | 22 ++++++++++++++++++- .../main/java/com/example/umc_6th/SongDao.kt | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt index c70d708..c6fc97d 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt @@ -125,6 +125,9 @@ class SongActivity : AppCompatActivity() { binding.songPreviousIv.setOnClickListener{ moveSong(-1) } + binding.songLikeIv.setOnClickListener { + setLike(songs[nowPos].isLike) + } } private fun initSong(){ @@ -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 @@ -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){ @@ -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) } diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/SongDao.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/SongDao.kt index 541d189..6141817 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/SongDao.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/SongDao.kt @@ -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) } \ No newline at end of file