-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- AlbumFragment에 하트 누르면 User 구분하여 Like Table 업데이트 기능 구현 - 저장앨범 탭에 띄우기 기능 구현 - 앨범 리사이클러뷰 구현 - 기존 item_locker_album.xml -> item_locker_song.xml로 변경 - fragment에 onResume, onStart에 설정하여 바로바로 업데이트 되게 보여줌.
- Loading branch information
1 parent
afed4a9
commit 9ce2f97
Showing
13 changed files
with
331 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
UMC_6th/app/src/main/java/com/example/umc_6th/LockerSavedAlbumFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.umc_6th | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import com.example.umc_6th.adapter.LockerSavedAlbumRecyclerAdapter | ||
import com.example.umc_6th.databinding.FragmentLockerSavedAlbumBinding | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
|
||
class LockerSavedAlbumFragment : Fragment() { | ||
lateinit var binding: FragmentLockerSavedAlbumBinding | ||
lateinit var albumDB: SongDatabase | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = FragmentLockerSavedAlbumBinding.inflate(inflater, container, false) | ||
|
||
albumDB = SongDatabase.getInstance(requireContext())!! | ||
|
||
return binding.root | ||
} | ||
override fun onStart() { | ||
super.onStart() | ||
initRecyclerview() | ||
} | ||
|
||
private fun initRecyclerview(){ | ||
binding.lockerSavedSongRecyclerView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) | ||
|
||
val lockerSavedAlbumRecyclerAdapter = LockerSavedAlbumRecyclerAdapter() | ||
//리스너 객체 생성 및 전달 | ||
|
||
lockerSavedAlbumRecyclerAdapter.setMyItemClickListener(object : LockerSavedAlbumRecyclerAdapter.MyItemClickListener{ | ||
override fun onRemoveSong(songId: Int) { | ||
albumDB.albumDao().getLikedAlbums(getJwt()) | ||
} | ||
}) | ||
|
||
binding.lockerSavedSongRecyclerView.adapter = lockerSavedAlbumRecyclerAdapter | ||
|
||
lockerSavedAlbumRecyclerAdapter.addAlbums(albumDB.albumDao().getLikedAlbums(getJwt()) as ArrayList) | ||
} | ||
|
||
private fun getJwt() : Int { | ||
val spf = activity?.getSharedPreferences("auth" , AppCompatActivity.MODE_PRIVATE) | ||
val jwt = spf!!.getInt("jwt", 0) | ||
Log.d("MAIN_ACT/GET_JWT", "jwt_token: $jwt") | ||
|
||
return jwt | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
UMC_6th/app/src/main/java/com/example/umc_6th/adapter/LockerSavedAlbumRecyclerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.umc_6th.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.umc_6th.Album | ||
import com.example.umc_6th.databinding.ItemLockerAlbumBinding | ||
|
||
class LockerSavedAlbumRecyclerAdapter : RecyclerView.Adapter<LockerSavedAlbumRecyclerAdapter.ViewHolder>() { | ||
private val albums = ArrayList<Album>() | ||
|
||
interface MyItemClickListener{ | ||
fun onRemoveSong(songId: Int) | ||
} | ||
|
||
private lateinit var mItemClickListener: MyItemClickListener | ||
|
||
fun setMyItemClickListener(itemClickListener: MyItemClickListener){ | ||
mItemClickListener = itemClickListener | ||
} | ||
|
||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): LockerSavedAlbumRecyclerAdapter.ViewHolder { | ||
val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false) | ||
|
||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: LockerSavedAlbumRecyclerAdapter.ViewHolder, position: Int) { | ||
holder.bind(albums[position]) | ||
holder.binding.imgItemLockerAlbumMore.setOnClickListener { | ||
mItemClickListener.onRemoveSong(albums[position].id) | ||
removeSong(position) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = albums.size | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
fun addAlbums(albums: ArrayList<Album>) { | ||
this.albums.clear() | ||
this.albums.addAll(albums) | ||
|
||
notifyDataSetChanged() | ||
} | ||
|
||
fun removeSong(position: Int){ | ||
albums.removeAt(position) | ||
notifyDataSetChanged() | ||
} | ||
|
||
inner class ViewHolder(val binding: ItemLockerAlbumBinding) : RecyclerView.ViewHolder(binding.root){ | ||
fun bind(album: Album){ | ||
binding.imgItemLockerAlbumCover.setImageResource(album.coverImg!!) | ||
binding.txItemLockerAlbumTitle.text = album.title | ||
binding.txItemLockerAlbumArtist.text = album.artist | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
UMC_6th/app/src/main/res/layout/fragment_locker_saved_album.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/locker_savedSong_recyclerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:listitem="@layout/item_locker_album" | ||
android:overScrollMode="never" | ||
android:orientation="vertical" | ||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.