From 0bbe0856a623a598f9ed078dea633bd7eef8173b Mon Sep 17 00:00:00 2001 From: MiN <81948815+leesumin0526@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:30:20 +0900 Subject: [PATCH] =?UTF-8?q?[Maro/#38]=20Feat=20::=208=EC=A3=BC=EC=B0=A8=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C=20(#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [maro/#38] feat :: 로그인, 회원가입 페이지 & 회원가입 구현 * [maro/#38] feat :: 좋아요 표시 유저 구분 * [maro/#38] feat :: 저장 앨범 탭, 둘러보기 페이지 제작 * [maro/#38] feat :: 8주차 구현 완료 --- .idea/workspace.xml | 94 +++--- UMC_6th/app/src/main/AndroidManifest.xml | 8 +- .../main/java/com/example/umc_6th/Album.kt | 3 +- .../main/java/com/example/umc_6th/AlbumDao.kt | 12 + .../java/com/example/umc_6th/AlbumFragment.kt | 74 +++-- .../src/main/java/com/example/umc_6th/Like.kt | 12 + .../com/example/umc_6th/LockerFragment.kt | 45 ++- .../java/com/example/umc_6th/LoginActivity.kt | 65 ++++ .../java/com/example/umc_6th/LookFragment.kt | 94 +++++- .../java/com/example/umc_6th/MainActivity.kt | 4 +- .../com/example/umc_6th/SavedAlbumFragment.kt | 45 ++- .../example/umc_6th/SavedAlbumRVAdapter.kt | 59 ++++ .../com/example/umc_6th/SignUpActivity.kt | 56 ++++ .../java/com/example/umc_6th/SongDatabase.kt | 3 +- .../src/main/java/com/example/umc_6th/User.kt | 12 + .../main/java/com/example/umc_6th/UserDao.kt | 17 + .../res/drawable/btn_editbar_addplaylist.png | Bin 0 -> 348 bytes .../main/res/drawable/not_selected_button.xml | 6 + .../src/main/res/drawable/selected_button.xml | 6 + .../src/main/res/layout/activity_login.xml | 284 +++++++++++++++++ .../src/main/res/layout/activity_sign_up.xml | 222 ++++++++++++++ .../main/res/layout/fragment_bottom_sheet.xml | 40 ++- .../src/main/res/layout/fragment_locker.xml | 2 +- .../app/src/main/res/layout/fragment_look.xml | 290 +++++++++++++++++- .../main/res/layout/fragment_saved_album.xml | 18 +- 25 files changed, 1365 insertions(+), 106 deletions(-) create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/Like.kt create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/SavedAlbumRVAdapter.kt create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/SignUpActivity.kt create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/User.kt create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/UserDao.kt create mode 100644 UMC_6th/app/src/main/res/drawable/btn_editbar_addplaylist.png create mode 100644 UMC_6th/app/src/main/res/drawable/not_selected_button.xml create mode 100644 UMC_6th/app/src/main/res/drawable/selected_button.xml create mode 100644 UMC_6th/app/src/main/res/layout/activity_login.xml create mode 100644 UMC_6th/app/src/main/res/layout/activity_sign_up.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 950f967..133d6ba 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,6 +5,11 @@ + + + @style/Theme.UMC_6th + + @style/Theme.UMC_6th @@ -15,6 +20,11 @@ @style/Theme.UMC_6th + + + @style/Theme.UMC_6th + + @style/Theme.UMC_6th @@ -116,30 +126,10 @@ - - - @@ -906,6 +925,9 @@ - \ No newline at end of file diff --git a/UMC_6th/app/src/main/AndroidManifest.xml b/UMC_6th/app/src/main/AndroidManifest.xml index 13e6aad..9b4930b 100644 --- a/UMC_6th/app/src/main/AndroidManifest.xml +++ b/UMC_6th/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ + - + + + + } diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt index 4018468..15e63bd 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt @@ -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 @@ -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( @@ -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(). @@ -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){ @@ -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) + } + } + + } } \ No newline at end of file diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/Like.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/Like.kt new file mode 100644 index 0000000..54721b2 --- /dev/null +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/Like.kt @@ -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 +} diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt index e4bfc27..e77715d 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt @@ -1,17 +1,19 @@ package com.example.umc_6th +import android.content.Intent import android.os.Bundle 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_6th.databinding.FragmentLockerBinding import com.google.android.material.tabs.TabLayoutMediator class LockerFragment : Fragment() { lateinit var binding: FragmentLockerBinding - private var information = arrayListOf("저장한곡", "음악파일", "저장앨범") + private val information = arrayListOf("저장한곡", "음악파일", "저장앨범") val bottomSheetFragment = BottomSheetFragment() @@ -37,6 +39,45 @@ class LockerFragment : Fragment() { bottomSheetFragment.show(requireFragmentManager(),"BottomSheetDialog") } + binding.lockerLoginTv.setOnClickListener { + val intent = Intent(requireActivity(), LoginActivity::class.java) + startActivity(intent) + } + return binding.root } -} \ No newline at end of file + + override fun onStart() { + super.onStart() + initViews() + } + private fun getJwt() : Int { + val spf = requireActivity().getSharedPreferences("auth", AppCompatActivity.MODE_PRIVATE) + return spf!!.getInt("jwt", 0) + } + + private fun initViews() { + val jwt : Int = getJwt() + if (jwt == 0) { + binding.lockerLoginTv.text="로그인" + binding.lockerLoginTv.setOnClickListener { + startActivity(Intent(requireActivity(), LoginActivity::class.java)) + } + } + + else { + binding.lockerLoginTv.text = "로그아웃" + binding.lockerLoginTv.setOnClickListener { + logout() + startActivity(Intent(requireActivity(), MainActivity::class.java)) + } + } + } + + private fun logout() { + val spf = activity?.getSharedPreferences("auth", AppCompatActivity.MODE_PRIVATE) + val editor = spf!!.edit() + editor.remove("jwt") + editor.apply() + } +} diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt new file mode 100644 index 0000000..e73c11e --- /dev/null +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt @@ -0,0 +1,65 @@ +package com.example.umc_6th + +import android.content.Intent +import android.os.Bundle +import android.util.Log +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import com.example.umc_6th.databinding.ActivityLoginBinding + +class LoginActivity : AppCompatActivity() { + + lateinit var binding : ActivityLoginBinding + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding.root) + + binding.loginSignUpTv.setOnClickListener { + val intent = Intent(this, SignUpActivity::class.java) + startActivity(intent) + } + + 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 : String = binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString() + val pwd : String = binding.loginPasswordEt.text.toString() + + val songDB = SongDatabase.getInstance(this)!! + val user = songDB.userDao().getUser(email, pwd) + + if (user != null) { + Log.d("LoginActivity", user.id.toString()) + saveJwt(user.id) + startMainActivity() + } else { + Toast.makeText(this, "회원 정보가 존재하지 않습니다", Toast.LENGTH_SHORT).show() + } + } + + private fun saveJwt(jwt : Int) { + val spf = getSharedPreferences("auth", MODE_PRIVATE) + val editor = spf.edit() + + editor.putInt("jwt", jwt) + editor.apply() + } + + private fun startMainActivity() { + val intent = Intent(this, MainActivity::class.java) + startActivity(intent) + } +} \ No newline at end of file diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt index 6cff4ae..fd90a41 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt @@ -5,9 +5,37 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button +import android.widget.ScrollView +import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import com.example.umc_6th.databinding.FragmentLookBinding class LookFragment : Fragment() { + lateinit var binding: FragmentLookBinding + private lateinit var songDB: SongDatabase + + private lateinit var chartBtn : Button + private lateinit var videoBtn : Button + private lateinit var genreBtn : Button + private lateinit var situationBtn : Button + private lateinit var audioBtn : Button + private lateinit var atmosphereBtn : Button + + private lateinit var buttonList: List