Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Standard/FLO/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
android:supportsRtl="true"
android:theme="@style/Theme.Umc_flo"
tools:targetApi="31">
<activity
android:name=".SignUpActivity"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="false" />
<activity
android:name=".SongActivity"
android:exported="true" />
Expand Down
12 changes: 12 additions & 0 deletions Standard/FLO/app/src/main/java/com/example/umc_flo/AlbumDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Album>

@Query("SELECT * FROM AlbumTable")
fun getAlbums(): List<Album>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
@@ -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<AlbumLockerRVAdapter.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): 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<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.itemAlbumImgIv.setImageResource(album.coverImg!!)
binding.itemAlbumTitleTv.text = album.title
binding.itemAlbumSingerTv.text = album.singer
}
}

}
26 changes: 14 additions & 12 deletions Standard/FLO/app/src/main/java/com/example/umc_flo/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions Standard/FLO/app/src/main/java/com/example/umc_flo/Like.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.example.umc_flo

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_flo.databinding.FragmentHomeBinding
import com.example.umc_flo.databinding.FragmentLockerBinding
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,
Expand All @@ -26,6 +28,49 @@ class LockerFragment : Fragment() {
tab.text = information[position]
}.attach()

binding.lockerLoginTv.setOnClickListener {
startActivity(Intent(activity, LoginActivity::class.java))
}

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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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
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()

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()
}
}
Loading