From e7d40f1dd961f9c3619a1d685c2ed5c604618c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=EA=B8=B0=EC=A4=80?= Date: Sat, 31 May 2025 13:36:37 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=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 --- Standard/FLO/app/src/main/AndroidManifest.xml | 6 + .../com/example/umc_flo/LockerFragment.kt | 5 + .../java/com/example/umc_flo/LoginActivity.kt | 24 ++ .../com/example/umc_flo/SignUpActivity.kt | 46 +++ .../java/com/example/umc_flo/SongDatabase.kt | 3 +- .../src/main/java/com/example/umc_flo/User.kt | 12 + .../main/java/com/example/umc_flo/UserDao.kt | 18 ++ .../src/main/res/layout/activity_login.xml | 287 ++++++++++++++++++ .../src/main/res/layout/activity_sign_up.xml | 227 ++++++++++++++ 9 files changed, 627 insertions(+), 1 deletion(-) create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/User.kt create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/UserDao.kt create mode 100644 Standard/FLO/app/src/main/res/layout/activity_login.xml create mode 100644 Standard/FLO/app/src/main/res/layout/activity_sign_up.xml diff --git a/Standard/FLO/app/src/main/AndroidManifest.xml b/Standard/FLO/app/src/main/AndroidManifest.xml index 478e3b2..33ff607 100644 --- a/Standard/FLO/app/src/main/AndroidManifest.xml +++ b/Standard/FLO/app/src/main/AndroidManifest.xml @@ -12,6 +12,12 @@ android:supportsRtl="true" android:theme="@style/Theme.Umc_flo" tools:targetApi="31"> + + diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt index f039af2..a8f0339 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt @@ -1,5 +1,6 @@ package com.example.umc_flo +import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater @@ -26,6 +27,10 @@ class LockerFragment : Fragment() { tab.text = information[position] }.attach() + binding.lockerLoginTv.setOnClickListener { + startActivity(Intent(activity, LoginActivity::class.java)) + } + return binding.root } } \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt new file mode 100644 index 0000000..8f58685 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt @@ -0,0 +1,24 @@ +package com.example.umc_flo + +import android.content.Intent +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import com.example.umc_flo.databinding.ActivityLoginBinding + +class LoginActivity : AppCompatActivity() { + + lateinit var binding: ActivityLoginBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_login) + + binding.loginSignUpTv.setOnClickListener { + startActivity(Intent(this, SignUpActivity::class.java)) + } + } +} \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt new file mode 100644 index 0000000..8cede80 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt @@ -0,0 +1,46 @@ +package com.example.umc_flo + +import android.os.Bundle +import android.util.Log +import android.widget.Toast +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import com.example.umc_flo.databinding.ActivitySignUpBinding + +class SignUpActivity : AppCompatActivity() { + + lateinit var binding : ActivitySignUpBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_sign_up) + + binding.signUpSignUpBtn.setOnClickListener { + signUp() + finish() + } + } + private fun getUser() : User { + val email : String = binding.signUpIdEt.text.toString() + "@" + binding.signUpDirectInputEt.text.toString() + val pwd : String = binding.signUpPasswordEt.text.toString() + + return User(email, pwd) + } + + private fun signUp() { + if (binding.signUpIdEt.text.toString().isEmpty() || binding.signUpDirectInputEt.text.toString().isEmpty()) { + Toast.makeText(this, "이메일 형식이 잘못되었습니다.", Toast.LENGTH_SHORT).show() + } + if (binding.signUpPasswordEt.text.toString() != binding.signUpPasswordCheckEt.text.toString()) { + Toast.makeText(this, "비밀번호가 일치하지 않습니다.", Toast.LENGTH_SHORT).show() + } + val userDB = SongDatabase.getInstance(this)!! + userDB.UserDao().insert(getUser()) + + val user = userDB.UserDao().getUsers() + Log.d("SIGNUPACT", user.toString()) + } +} \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt index 56979a9..95d6e2d 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt @@ -5,10 +5,11 @@ import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -@Database(entities = [Song::class, Album::class], version = 2) +@Database(entities = [Song::class, Album::class, User::class], version = 1) abstract class SongDatabase: RoomDatabase() { abstract fun songDao(): SongDao abstract fun albumDao(): AlbumDao + abstract fun UserDao() : UserDao companion object { private var instance: SongDatabase? = null diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/User.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/User.kt new file mode 100644 index 0000000..f1d4c96 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/User.kt @@ -0,0 +1,12 @@ +package com.example.umc_flo + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "UserTable") +data class User( + var email : String, + var password : String +) { + @PrimaryKey(autoGenerate = true) var id : Int = 0 +} diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/UserDao.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/UserDao.kt new file mode 100644 index 0000000..f42e855 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/UserDao.kt @@ -0,0 +1,18 @@ +package com.example.umc_flo + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.Query + +@Dao +interface UserDao { + + @Insert + fun insert(user: User) + + @Query("SELECT * FROM UserTable") + fun getUsers() : List + + @Query("SELECT * FROM UserTable WHERE email = :email AND password = :password") + fun getUser(email : String, password : String) : User? +} \ No newline at end of file diff --git a/Standard/FLO/app/src/main/res/layout/activity_login.xml b/Standard/FLO/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..ee22a6d --- /dev/null +++ b/Standard/FLO/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml b/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml new file mode 100644 index 0000000..8eab681 --- /dev/null +++ b/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f2bab85c4af4f681ed43015ce75dd802a4ded2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=EA=B8=B0=EC=A4=80?= Date: Sat, 31 May 2025 16:10:15 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EA=B8=B0?= =?UTF-8?q?=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 --- .../com/example/umc_flo/LockerFragment.kt | 40 +++++++++++++++ .../java/com/example/umc_flo/LoginActivity.kt | 50 ++++++++++++++++++- .../com/example/umc_flo/SignUpActivity.kt | 6 ++- .../src/main/res/layout/activity_sign_up.xml | 23 +-------- 4 files changed, 95 insertions(+), 24 deletions(-) diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt index a8f0339..ea40d9a 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt @@ -6,6 +6,7 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import com.example.umc_flo.databinding.FragmentHomeBinding import com.example.umc_flo.databinding.FragmentLockerBinding import com.google.android.material.tabs.TabLayoutMediator @@ -33,4 +34,43 @@ class LockerFragment : Fragment() { return binding.root } + + override fun onStart() { + super.onStart() + initViews() + } + + private fun initViews() { + val jwt: Int = getJwt() + + if (jwt == 0){ + binding.lockerLoginTv.text = "로그인" + + binding.lockerLoginTv.setOnClickListener { + startActivity(Intent(activity, LoginActivity::class.java)) + } + } + else{ + binding.lockerLoginTv.text = "로그아웃" + + binding.lockerLoginTv.setOnClickListener { + logout() + startActivity(Intent(activity, MainActivity::class.java)) + } + } + } + + private fun getJwt(): Int { + val spf = activity?.getSharedPreferences("auth" , AppCompatActivity.MODE_PRIVATE) + + return spf!!.getInt("jwt", 0) + } + + private fun logout() { + val spf = activity?.getSharedPreferences("auth" , AppCompatActivity.MODE_PRIVATE) + val editor = spf!!.edit() + + editor.remove("jwt") + editor.apply() + } } \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt index 8f58685..5dae54b 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LoginActivity.kt @@ -2,6 +2,8 @@ package com.example.umc_flo import android.content.Intent import android.os.Bundle +import android.util.Log +import android.widget.Toast import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat @@ -15,10 +17,56 @@ class LoginActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - setContentView(R.layout.activity_login) + + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding.root) binding.loginSignUpTv.setOnClickListener { startActivity(Intent(this, SignUpActivity::class.java)) + + binding.loginSignInBtn.setOnClickListener { + login() + } + } + } + + private fun login() { + if (binding.loginIdEt.text.toString().isEmpty() || binding.loginDirectInputEt.text.toString().isEmpty()) { + Toast.makeText(this, "이메일을 입력해주세요.", Toast.LENGTH_SHORT).show() + return } + + if (binding.loginPasswordEt.text.toString().isEmpty()) { + Toast.makeText(this, "비밀번호를 입력해주세요.", Toast.LENGTH_SHORT).show() + return + } + + val email = binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString() + val password = binding.loginPasswordEt.text.toString() + + val songDB = SongDatabase.getInstance(this)!! + + val user = songDB.UserDao().getUser(email, password) + + + user?.let { + Log.d("LOGIN_ACT/GET_USER", "userId: ${user.id}, $user") + saveJwt(user.id) + + startMainActivity() + } + } + + private fun startMainActivity() { + val intent = Intent(this, MainActivity::class.java) + startActivity(intent) + } + + private fun saveJwt(jwt: Int) { + val spf = getSharedPreferences("auth" , MODE_PRIVATE) + val editor = spf.edit() + + editor.putInt("jwt", jwt) + editor.apply() } } \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt index 8cede80..def6197 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/SignUpActivity.kt @@ -1,5 +1,6 @@ package com.example.umc_flo +import android.os.Build import android.os.Bundle import android.util.Log import android.widget.Toast @@ -7,6 +8,7 @@ import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import com.example.umc_flo.databinding.ActivityLoginBinding import com.example.umc_flo.databinding.ActivitySignUpBinding class SignUpActivity : AppCompatActivity() { @@ -16,7 +18,9 @@ class SignUpActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - setContentView(R.layout.activity_sign_up) + binding = ActivitySignUpBinding.inflate(layoutInflater) + setContentView(binding.root) + binding.signUpSignUpBtn.setOnClickListener { signUp() diff --git a/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml b/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml index 8eab681..2cd7a3d 100644 --- a/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml +++ b/Standard/FLO/app/src/main/res/layout/activity_sign_up.xml @@ -106,28 +106,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/sign_up_id_underscore_view"/> - - Date: Sat, 31 May 2025 17:13:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EC=95=A8=EB=B2=94=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=20=EB=B3=B4=EA=B4=80=ED=95=A8=EC=97=90=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/umc_flo/AlbumDao.kt | 12 +++ .../java/com/example/umc_flo/AlbumFragment.kt | 44 +++++++++- .../example/umc_flo/AlbumLockerRVAdapter.kt | 59 +++++++++++++ .../java/com/example/umc_flo/HomeFragment.kt | 26 +++--- .../src/main/java/com/example/umc_flo/Like.kt | 12 +++ .../com/example/umc_flo/LockerFragment.kt | 2 +- .../com/example/umc_flo/LockerVPAdapter.kt | 5 +- .../com/example/umc_flo/SavedAlbumFragment.kt | 58 +++++++++++++ .../java/com/example/umc_flo/SongDatabase.kt | 2 +- .../src/main/res/layout/fragment_locker.xml | 2 +- .../res/layout/fragment_locker_savedalbum.xml | 18 ++++ .../src/main/res/layout/item_locker_album.xml | 83 +++++++++++++++++++ 12 files changed, 302 insertions(+), 21 deletions(-) create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumLockerRVAdapter.kt create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/Like.kt create mode 100644 Standard/FLO/app/src/main/java/com/example/umc_flo/SavedAlbumFragment.kt create mode 100644 Standard/FLO/app/src/main/res/layout/fragment_locker_savedalbum.xml create mode 100644 Standard/FLO/app/src/main/res/layout/item_locker_album.xml diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumDao.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumDao.kt index ad366c2..1b3f055 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumDao.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumDao.kt @@ -13,6 +13,18 @@ interface AlbumDao { @Delete fun delete(album: 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 + @Query("SELECT * FROM AlbumTable") fun getAlbums(): List diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumFragment.kt index 3a73e77..147b06e 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumFragment.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumFragment.kt @@ -2,11 +2,13 @@ package com.example.umc_flo import android.content.Context import android.os.Bundle +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.activity.OnBackPressedCallback +import androidx.appcompat.app.AppCompatActivity import com.example.umc_flo.databinding.FragmentAlbumBinding import com.google.android.material.tabs.TabLayoutMediator import com.google.gson.Gson @@ -32,23 +34,25 @@ class AlbumFragment : Fragment() { val albumJson = arguments?.getString("album") val gson = Gson() val album = gson.fromJson(albumJson, Album::class.java) - - + isLiked = isLikedAlbum(album.id) setInit(album) initViewPager() - setClickListeners(album) + setOnClickListeners(album) return binding.root } - private fun setClickListeners(album: Album) { + private fun setOnClickListeners(album: Album) { + val userId: Int = getJwt() binding.albumLikeIv.setOnClickListener { if(isLiked) { binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_off) + disLikedAlbum(album.id) } else { binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_on) + likeAlbum(userId, album.id) } isLiked = !isLiked @@ -100,4 +104,36 @@ class AlbumFragment : Fragment() { binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_off) } } + + private fun likeAlbum(userId: Int, albumId: Int) { + val songDB = SongDatabase.getInstance(requireContext())!! + val like = Like(userId, albumId) + + songDB.albumDao().likeAlbum(like) + } + + private fun isLikedAlbum(albumId: Int): Boolean { + val songDB = SongDatabase.getInstance(requireContext())!! + val userId = getJwt() + + val likeId: Int? = songDB.albumDao().isLikedAlbum(userId, albumId) + + return likeId != null + } + + private fun disLikedAlbum(albumId: Int) { + val songDB = SongDatabase.getInstance(requireContext())!! + val userId = getJwt() + + songDB.albumDao().disLikedAlbum(userId, albumId) + } + + 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 + } + } \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumLockerRVAdapter.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumLockerRVAdapter.kt new file mode 100644 index 0000000..46a2298 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumLockerRVAdapter.kt @@ -0,0 +1,59 @@ +package com.example.umc_flo + +import android.annotation.SuppressLint +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.example.umc_flo.databinding.ItemLockerAlbumBinding + +class AlbumLockerRVAdapter (): RecyclerView.Adapter() { + private val albums = ArrayList() + + interface MyItemClickListener{ + fun onRemoveSong(songId: Int) + } + + private lateinit var mItemClickListener: MyItemClickListener + + fun setMyItemClickListener(itemClickListener: MyItemClickListener){ + mItemClickListener = itemClickListener + } + + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumLockerRVAdapter.ViewHolder { + val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false) + + return ViewHolder(binding) + } + + override fun onBindViewHolder(holder: AlbumLockerRVAdapter.ViewHolder, position: Int) { + holder.bind(albums[position]) + holder.binding.itemAlbumMoreIv.setOnClickListener { + mItemClickListener.onRemoveSong(albums[position].id) + removeSong(position) + } + } + + override fun getItemCount(): Int = albums.size + + @SuppressLint("NotifyDataSetChanged") + fun addAlbums(albums: ArrayList) { + 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.itemAlbumImgIv.setImageResource(album.coverImg!!) + binding.itemAlbumTitleTv.text = album.title + binding.itemAlbumSingerTv.text = album.singer + } + } + +} \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/HomeFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/HomeFragment.kt index 49eec75..31ccf08 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/HomeFragment.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/HomeFragment.kt @@ -19,6 +19,7 @@ class HomeFragment :Fragment() { fun onAlbumSelected(album: Album) } + private lateinit var songDB : SongDatabase private lateinit var albumSelectedListener: AlbumSelectedListener lateinit var binding: FragmentHomeBinding @@ -52,7 +53,8 @@ class HomeFragment :Fragment() { ): View { binding = FragmentHomeBinding.inflate(inflater, container, false) - + songDB = SongDatabase.getInstance(requireContext())!! + albumDatas.addAll(songDB.albumDao().getAlbums()) // binding.homeAlbumImg1Iv.setOnClickListener { // (context as MainActivity).supportFragmentManager.beginTransaction() @@ -88,17 +90,17 @@ class HomeFragment :Fragment() { albumRVAdapter.setMyItemClickListener(object : AlbumRVAdapter.MyItemClickListener { override fun onItemClick(album: Album) { albumSelectedListener.onAlbumSelected(album) -// val gson = Gson() -// val albumJson = gson.toJson(album) -// -// val albumFragment = AlbumFragment() -// val bundle = Bundle() -// bundle.putString("album", albumJson) -// albumFragment.arguments = bundle -// -// (context as MainActivity).supportFragmentManager.beginTransaction() -// .replace(R.id.main_fragment_container, albumFragment) -// .commitAllowingStateLoss() + val gson = Gson() + val albumJson = gson.toJson(album) + + val albumFragment = AlbumFragment() + val bundle = Bundle() + bundle.putString("album", albumJson) + albumFragment.arguments = bundle + + (context as MainActivity).supportFragmentManager.beginTransaction() + .replace(R.id.main_fragment_container, albumFragment) + .commitAllowingStateLoss() } override fun onRemoveAlbum(position: Int) { diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/Like.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/Like.kt new file mode 100644 index 0000000..ff53e5e --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/Like.kt @@ -0,0 +1,12 @@ +package com.example.umc_flo + +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 +} diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt index ea40d9a..3ec39e4 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerFragment.kt @@ -13,7 +13,7 @@ import com.google.android.material.tabs.TabLayoutMediator class LockerFragment : Fragment() { lateinit var binding: FragmentLockerBinding - private val information = arrayListOf("저장한곡", "음악파일") + private val information = arrayListOf("저장한곡", "음악파일", "저장한 앨범") override fun onCreateView( inflater: LayoutInflater, diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerVPAdapter.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerVPAdapter.kt index 097b3b8..e9e38ef 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerVPAdapter.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/LockerVPAdapter.kt @@ -4,12 +4,13 @@ import androidx.fragment.app.Fragment import androidx.viewpager2.adapter.FragmentStateAdapter class LockerVPAdapter (fragment : Fragment) : FragmentStateAdapter(fragment) { - override fun getItemCount(): Int = 2 + override fun getItemCount(): Int = 3 override fun createFragment(position: Int): Fragment { return when(position){ 0 -> SavedSongFragment() - else -> MusicFileFragment() + 1 -> MusicFileFragment() + else -> SavedAlbumFragment() } } } \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/SavedAlbumFragment.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/SavedAlbumFragment.kt new file mode 100644 index 0000000..aa5f384 --- /dev/null +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/SavedAlbumFragment.kt @@ -0,0 +1,58 @@ +package com.example.umc_flo + +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 androidx.recyclerview.widget.LinearLayoutManager +import com.example.umc_flo.databinding.FragmentLockerSavedalbumBinding + +class SavedAlbumFragment : 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 albumRVAdapter = AlbumLockerRVAdapter() + //리스너 객체 생성 및 전달 + + albumRVAdapter.setMyItemClickListener(object : AlbumLockerRVAdapter.MyItemClickListener{ + override fun onRemoveSong(songId: Int) { + albumDB.albumDao().getLikedAlbums(getJwt()) + } + }) + + binding.lockerSavedSongRecyclerView.adapter = albumRVAdapter + + albumRVAdapter.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 + } +} \ No newline at end of file diff --git a/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt b/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt index 95d6e2d..040f74e 100644 --- a/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt +++ b/Standard/FLO/app/src/main/java/com/example/umc_flo/SongDatabase.kt @@ -5,7 +5,7 @@ import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -@Database(entities = [Song::class, Album::class, User::class], version = 1) +@Database(entities = [Song::class, Album::class, User::class, Like::class], version = 1) abstract class SongDatabase: RoomDatabase() { abstract fun songDao(): SongDao abstract fun albumDao(): AlbumDao diff --git a/Standard/FLO/app/src/main/res/layout/fragment_locker.xml b/Standard/FLO/app/src/main/res/layout/fragment_locker.xml index eebd9e1..d9b2885 100644 --- a/Standard/FLO/app/src/main/res/layout/fragment_locker.xml +++ b/Standard/FLO/app/src/main/res/layout/fragment_locker.xml @@ -32,7 +32,7 @@ + + + + + \ No newline at end of file diff --git a/Standard/FLO/app/src/main/res/layout/item_locker_album.xml b/Standard/FLO/app/src/main/res/layout/item_locker_album.xml new file mode 100644 index 0000000..2399723 --- /dev/null +++ b/Standard/FLO/app/src/main/res/layout/item_locker_album.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file