Skip to content

Commit

Permalink
[Maro/#38] Feat :: 8주차 구현 완료 (#41)
Browse files Browse the repository at this point in the history
* [maro/#38] feat :: 로그인, 회원가입 페이지 & 회원가입 구현

* [maro/#38] feat :: 좋아요 표시 유저 구분

* [maro/#38] feat :: 저장 앨범 탭, 둘러보기 페이지 제작

* [maro/#38] feat :: 8주차 구현 완료
  • Loading branch information
leesumin0526 authored Jun 5, 2024
1 parent 32eca6d commit 0bbe085
Show file tree
Hide file tree
Showing 25 changed files with 1,365 additions and 106 deletions.
94 changes: 58 additions & 36 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />


<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -16,10 +17,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.UMC_6th"
tools:targetApi="31">
<service
android:name=".ForegroundService"
android:enabled="true"
android:exported="true"></service>

<activity android:name=".SignUpActivity" />
<activity android:name=".LoginActivity"/>

<activity
android:name=".MainActivity"
Expand Down
3 changes: 2 additions & 1 deletion UMC_6th/app/src/main/java/com/example/umc_6th/Album.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class Album(
var id: Int = 0,
var title: String? = "",
var singer: String? = "",
var coverImg: Int? = null
var coverImg: Int? = null,
var isLike : Boolean = true,
)
12 changes: 12 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ interface AlbumDao {
@Query("SELECT * FROM AlbumTable WHERE id = :id")
fun getAlbum(id : Int): Album

@Insert
fun likeAlbum(like : Like)

@Query("select id from LikeTable where userId =:userId and albumId = :albumId")
fun isLikedAlbum(userId : Int, albumId : Int) : Int?

@Query("delete from LikeTable where userId =:userId and albumId = :albumId")
fun dislikedAlbum(userId : Int, albumId : Int)

@Query("select at.* from LikeTable as lt left join AlbumTable as at on lt.albumId = at.id where lt.userId = :userId")
fun getLikedAlbums(userId : Int) : List<Album>

}
74 changes: 48 additions & 26 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
import com.example.umc_6th.databinding.FragmentAlbumBinding
Expand All @@ -15,6 +16,7 @@ class AlbumFragment : Fragment() {

lateinit var binding : FragmentAlbumBinding
private var gson : Gson = Gson()
private var isLiked : Boolean = false

private val information = arrayListOf("수록곡","상세정보","영상")
override fun onCreateView(
Expand All @@ -24,9 +26,11 @@ class AlbumFragment : Fragment() {
): View? {
binding = inflate(inflater,container,false)

val albumJson = arguments?.getString("album")
val album = gson.fromJson(albumJson, Album::class.java)
val albumToJson = arguments?.getString("album")
val album = gson.fromJson(albumToJson, Album::class.java)
isLiked = isLikedAlbum(album.id)
setInit(album)
setOnClickListener(album)

binding.albumBackIv.setOnClickListener{
(context as MainActivity).supportFragmentManager.beginTransaction().
Expand All @@ -50,30 +54,6 @@ class AlbumFragment : Fragment() {
tab.text = information[position]
}.attach()


// binding.songLalacLayout.setOnClickListener{
// Toast.makeText(activity,"LILAC",Toast.LENGTH_SHORT).show()
// }
//
// binding.songFluLayout.setOnClickListener {
// Toast.makeText(activity,"FLU", Toast.LENGTH_SHORT).show()
// }
//
// binding.songCoinLayout.setOnClickListener {
// Toast.makeText(activity,"Coin", Toast.LENGTH_SHORT).show()
// }
//
// binding.songSpringLayout.setOnClickListener {
// Toast.makeText(activity,"봄 안녕 봄", Toast.LENGTH_SHORT).show()
// }
//
// binding.songCelebrityLayout.setOnClickListener {
// Toast.makeText(activity,"Celebrity", Toast.LENGTH_SHORT).show()
// }
//
// binding.songSingLayout.setOnClickListener {
// Toast.makeText(activity,"돌림노래 (Feat. DEAN)", Toast.LENGTH_SHORT).show()
// }
return binding.root
}
private fun setInit(album: Album){
Expand All @@ -82,4 +62,46 @@ class AlbumFragment : Fragment() {
binding.albumSingerNameTv.text = album.singer.toString()
}

private fun getJwt() : Int {
val spf = requireActivity().getSharedPreferences("auth", AppCompatActivity.MODE_PRIVATE)
return spf.getInt("jwt", 0)
}

private fun likeAlbum(userId : Int, albumId : Int) {
val songDB = SongDatabase.getInstance(requireActivity())!!
val like = Like(userId, albumId)

songDB.albumDao().likeAlbum(like)
}

private fun isLikedAlbum(albumId : Int) : Boolean {
val songDB = SongDatabase.getInstance(requireActivity())!!
val userId = getJwt()

val likeId : Int? = songDB.albumDao().isLikedAlbum(userId, albumId)
return likeId != null
}

private fun disLikeAlbum(albumId : Int) {
val songDB = SongDatabase.getInstance(requireActivity())!!
val userId = getJwt()

songDB.albumDao().dislikedAlbum(userId, albumId)
}

private fun setOnClickListener(album : Album) {
val userId = getJwt()
binding.albumLikeIv.setOnClickListener {
if(isLiked) {
binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_off)
disLikeAlbum(album.id)
}

else {
binding.albumLikeIv.setImageResource((R.drawable.ic_my_like_on))
likeAlbum(userId, album.id)
}
}

}
}
12 changes: 12 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/Like.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.umc_6th

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "LikeTable")
data class Like(
var userId : Int,
var albumId : Int
) {
@PrimaryKey(autoGenerate = true) var id : Int = 0
}
Loading

0 comments on commit 0bbe085

Please sign in to comment.