Skip to content

Commit

Permalink
[nunu/#33] feat: 7주차 구현2
Browse files Browse the repository at this point in the history
- 좋아요 기능 커스텀 toast 구현
  • Loading branch information
Ssamssamukja committed May 28, 2024
1 parent b6e7f1f commit c8b10b7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
24 changes: 23 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 @@ -7,7 +7,10 @@ import android.graphics.PorterDuff
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.graphics.Color
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -242,6 +245,12 @@ class SongActivity : AppCompatActivity() {
currentSong.isLike = newLikeStatus
songDB.songDao().updateIsLikeById(newLikeStatus, currentSong.id)
updateHeartIcon(newLikeStatus)

if (newLikeStatus) {
showToast(this, "좋아요 한 곡에 담겼습니다.")
} else {
showToast(this, "좋아요 한 곡이 취소되었습니다.")
}
}


Expand All @@ -263,5 +272,18 @@ class SongActivity : AppCompatActivity() {
startOrResumeTimer() // 타이머를 다시 시작
}

private fun showToast(context: Context, message: String) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val layout = inflater.inflate(R.layout.custom_like_toast,
findViewById(R.id.custom_toast_container))

}
val text: TextView = layout.findViewById(R.id.toast_text)
text.text = message

with (Toast(context)) {
duration = Toast.LENGTH_SHORT
view = layout
show()
}
}
}
11 changes: 11 additions & 0 deletions UMC_6th/app/src/main/res/drawable/custom_like_toast_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#BB171717" />
<corners android:radius="16dp" />
<padding
android:left="16dp"
android:top="8dp"
android:right="16dp"
android:bottom="8dp" />
</shape>
26 changes: 26 additions & 0 deletions UMC_6th/app/src/main/res/layout/custom_like_toast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_toast_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/custom_like_toast_background"
android:orientation="horizontal"
android:padding="8dp">


<TextView
android:id="@+id/toast_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:text="좋아요 한 곡에 담겼습니다"
android:textColor="#FFFFFF"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit c8b10b7

Please sign in to comment.