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
17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

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

28 changes: 26 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ plugins {
id("dagger.hilt.android.plugin")
id("androidx.navigation.safeargs.kotlin")
id("org.jetbrains.kotlin.kapt")
id("kotlin-kapt")
}

android {
namespace = "umc.study.umc_7th"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "umc.study.umc_7th"
Expand Down Expand Up @@ -48,7 +49,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
kotlinCompilerExtensionVersion = "1.5.13"
}
packaging {
resources {
Expand All @@ -69,6 +70,7 @@ dependencies {
implementation(libs.androidx.storage)
implementation(libs.androidx.lifecycle.runtime.compose.android)
implementation(libs.common)
implementation(libs.firebase.firestore.ktx)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand All @@ -86,6 +88,8 @@ dependencies {
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)

implementation ("me.relex:circleindicator:2.1.6")
implementation ("androidx.viewpager2:viewpager2:1.0.0")
// Hilt Dependency Injection
implementation("com.google.dagger:hilt-android:2.49")
kapt("com.google.dagger:hilt-compiler:2.49")
Expand All @@ -99,6 +103,8 @@ dependencies {
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")

implementation("com.squareup.retrofit2:converter-gson:2.9.0")

// https://github.com/square/okhttp
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.2")

Expand Down Expand Up @@ -132,4 +138,22 @@ dependencies {
annotationProcessor("androidx.room:room-compiler:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")

implementation("androidx.room:room-migration:2.6.0")
implementation("androidx.room:room-runtime:2.6.0")
kapt("androidx.room:room-compiler:2.6.0")

// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")

// okHttp
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")

// Glide
implementation("com.github.bumptech.glide:glide:4.12.0")
annotationProcessor("com.github.bumptech.glide:compiler:4.12.0")
}
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">\
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -19,10 +19,9 @@
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Umc_7th">
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -31,4 +30,6 @@
android:exported="true"/>
</application>

<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
13 changes: 13 additions & 0 deletions app/src/main/java/umc/study/umc_7th/Album.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package umc.study.umc_7th

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

@Entity(tableName = "AlbumTable")
data class Album(
// album의 pk는 임의로 지정해 줄 것이므로, autoGenerate 하지 않음
@PrimaryKey(autoGenerate = false) var id: Int = 0,
var title: String? = "",
var singer: String? = "",
var coverImage: Int? = null
)
37 changes: 37 additions & 0 deletions app/src/main/java/umc/study/umc_7th/AlbumDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package umc.study.umc_7th

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update

@Dao
interface AlbumDao {
@Insert
fun insert(album: Album)

@Update
fun update(album: Album)

@Delete
fun delete(album: Album)

@Query("SELECT * FROM AlbumTable") // 테이블의 모든 값을 가져온다.
fun getAlbums(): List<Album>

@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>
}
105 changes: 88 additions & 17 deletions app/src/main/java/umc/study/umc_7th/AlbumFragment.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package umc.study.umc_7th


import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
import com.google.android.material.tabs.TabLayoutMediator
import com.google.gson.Gson
import umc.study.umc_7th.AlbumRVAdapter
import umc.study.umc_7th.HomeFragment
import umc.study.umc_7th.Like
import umc.study.umc_7th.MainActivity
import umc.study.umc_7th.R
import umc.study.umc_7th.SongDatabase
import umc.study.umc_7th.databinding.FragmentAlbumBinding

class AlbumFragment : Fragment() {

lateinit var binding: FragmentAlbumBinding
private var gson: Gson = Gson()

private var isLiked : Boolean = false

private val information = arrayListOf("수록곡", "상세정보", "영상")

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -20,37 +35,93 @@ class AlbumFragment : Fragment() {
): View? {
binding = FragmentAlbumBinding.inflate(inflater,container,false)

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

setFragmentResultListener("TitleInfo") { requestKey, bundle ->
binding.albumMusicTitleTv.text = bundle.getString("title")
}

setFragmentResultListener("SingerInfo") { requestKey, bundle ->
binding.albumSingerNameTv.text = bundle.getString("singer")
}

// binding.albumMusicTitleTv.text = arguments?.getString("title")
// binding.albumSingerNameTv.text = arguments?.getString("singer")

binding.albumBackIv.setOnClickListener {
(context as MainActivity).supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, HomeFragment())
.commitAllowingStateLoss()
}

binding.songLalacLayout.setOnClickListener {
Toast.makeText(activity, "LILAC", Toast.LENGTH_SHORT).show()
}
val albumAdapter = AlbumVPAdapter(this)
binding.albumContentVp.adapter = albumAdapter

binding.songFluLayout.setOnClickListener {
Toast.makeText(activity,"FLU", Toast.LENGTH_SHORT).show()
}
TabLayoutMediator(binding.albumContentTb, binding.albumContentVp) { tab, position ->
tab.text = information[position]
}.attach()

binding.songCoinLayout.setOnClickListener {
Toast.makeText(activity,"Coin", Toast.LENGTH_SHORT).show()
}
return binding.root
}

binding.songSpringLayout.setOnClickListener {
Toast.makeText(activity,"봄 안녕 봄", Toast.LENGTH_SHORT).show()
}
private fun setInit(album : Album) {
binding.albumAlbumIv.setImageResource(album.coverImage!!)
binding.albumMusicTitleTv.text = album.title.toString()
binding.albumSingerNameTv.text = album.singer.toString()

binding.songCelebrityLayout.setOnClickListener {
Toast.makeText(activity,"Celebrity", Toast.LENGTH_SHORT).show()
if(isLiked) {
binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_on)
}

binding.songSingLayout.setOnClickListener {
Toast.makeText(activity,"돌림노래 (Feat. DEAN)", Toast.LENGTH_SHORT).show()
else {
binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_off)
}
}

return binding.root
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)
}
}

}
}
52 changes: 52 additions & 0 deletions app/src/main/java/umc/study/umc_7th/AlbumRVAapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package umc.study.umc_7th

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import umc.study.umc_7th.databinding.ItemAlbumBinding

class AlbumRVAdapter(private val albumList: ArrayList<Album>) : RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>(){

// 뷰홀더를 생성해줘야 할 때 호출되는 함수 => 아이템 뷰 객체를 만들어서 뷰홀더에 던져줍니다.
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumRVAdapter.ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)

return ViewHolder(binding)
}

// 뷰홀더에 데이터를 바인딩해줘야 할 때마다 호출되는 함수 => 엄청나게 많이 호출
override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
holder.bind(albumList[position])
holder.itemView.setOnClickListener {
itemClickListener.onItemClick(albumList[position])
}

holder.binding.itemAlbumPlayImgIv.setOnClickListener {
itemClickListener.onPlayAlbum(albumList[position])
}
}

// 데이터 세트 크기를 알려주는 함수 => 리사이클러뷰가 마지막이 언제인지를 알게 된다.
override fun getItemCount(): Int = albumList.size

// 뷰홀더
inner class ViewHolder(val binding: ItemAlbumBinding): RecyclerView.ViewHolder(binding.root){

fun bind(album: Album){
binding.itemAlbumTitleTv.text = album.title
binding.itemAlbumSingerTv.text = album.singer
binding.itemAlbumCoverImgIv.setImageResource(album.coverImage!!)
}
}

interface OnItemClickListener {
fun onItemClick(album : Album)
fun onPlayAlbum(album : Album)
}

private lateinit var itemClickListener : OnItemClickListener

fun setItemClickListener(onItemClickListener: OnItemClickListener) {
this.itemClickListener = onItemClickListener
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/umc/study/umc_7th/AlbumVPAdpter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package umc.study.umc_7th

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class AlbumVPAdapter(fragment : Fragment) : FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 3

override fun createFragment(position: Int): Fragment {
return when(position) {
0 -> SongFragment()
1 -> DetailFragment()
else -> VideoFragment()
}
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/umc/study/umc_7th/ApiRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package umc.study.umc_7th

class ApiRepository {
companion object {
const val BASE_URL = "http://3.35.121.185/"
}
}
Loading