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: 16 additions & 1 deletion nick/Imreallystupid/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -39,13 +40,27 @@ android {
}

dependencies {

implementation("me.relex:circleindicator:2.1.6")
implementation("com.google.code.gson:gson:2.8.7")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

implementation("com.kakao.sdk:v2-all:2.23.1")
// 전체 모듈 추가, 2.11.0 버전부터 지원

val room_version = "2.8.3"
implementation("androidx.room:room-runtime:${room_version}")
implementation("androidx.room:room-ktx:${room_version}")
kapt("androidx.room:room-compiler:$room_version")
}
44 changes: 41 additions & 3 deletions nick/Imreallystupid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?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.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand All @@ -10,10 +16,20 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Imreallystupid">
android:theme="@style/Theme.Imreallystupid"
android:name=".GlobalApplication"
android:usesCleartextTraffic="true">
<service
android:name=".MusicService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="mediaPlayback" >
</service>

<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -22,8 +38,30 @@
</activity>
<activity
android:name=".SongActivity"
android:exported="true" >
</activity>
<activity
android:name=".LoginActivity"
android:exported="true" >
</activity>
<activity
android:name=".SignUpActivity"
android:exported="true" >
</activity>
<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- 리다이렉트 URI: "kakao${NATIVE_APP_KEY}://oauth" -->
<data android:host="oauth"
android:scheme="kakaof4dc4468b7fc42b10f052d84a73e7a79" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.imreallystupid

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

@Entity(tableName = "AlbumTable")
data class Album(
@PrimaryKey(autoGenerate = false) var id: Int = 0,
var title: String = "",
var singer: String = "",
var coverImg: Int? = null
)
//var songs: ArrayList<Song>? = null)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.imreallystupid

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)

@Query("SELECT * FROM AlbumTable")
fun getAlbums(): List<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 getLikedAlbum(userId:Int): List<Album>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ 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 com.example.imreallystupid.databinding.FragmentAlbumBinding
import com.google.android.material.tabs.TabLayoutMediator
import com.google.gson.Gson


class AlbumFragment : Fragment() {



lateinit var binding: FragmentAlbumBinding
private var gson: Gson = Gson()
private val information = arrayListOf("수록곡","상세정보","영상")
private var isLiked : Boolean = false

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -23,8 +27,14 @@ class AlbumFragment : Fragment() {
): View {
binding = FragmentAlbumBinding.inflate(inflater, container, false)

binding.albumTitleTv.text = arguments?.getString("title")
binding.albumSingerTv.text = arguments?.getString("singer")
//binding.albumTitleTv.text = arguments?.getString("title")
//binding.albumSingerTv.text = arguments?.getString("singer")

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


binding.albumBackIv.setOnClickListener {
Expand All @@ -34,11 +44,68 @@ class AlbumFragment : Fragment() {

val albumAdapter = AlbumVPAdapter(this)
binding.albumContentVp.adapter = albumAdapter

TabLayoutMediator(binding.albumContentTb, binding.albumContentVp){
tab, position ->
tab.text = information[position]
}.attach()

return binding.root
}

private fun setinit(album: Album){
binding.albumAlbumIv.setImageResource(album.coverImg!!)
binding.albumTitleTv.text = album.title.toString()
binding.albumSingerTv.text = album.singer.toString()
if (isLiked) {
binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_on)
}
else {
binding.albumLikeIv.setImageResource(R.drawable.ic_my_like_off)
}
}

private fun getJwt(): Int {
val spf = activity?.getSharedPreferences("auth", AppCompatActivity.MODE_PRIVATE)
return spf!!.getInt("jwt",0)
}

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 setOnClickListener(album: Album) {
val userId = 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)
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.imreallystupid

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.imreallystupid.databinding.ItemAlbumBinding

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


interface AlbumListItemClickListener{
fun onItemClick(album: Album)
}
private lateinit var mItemClickListener: AlbumListItemClickListener
fun setMyItemClickListener(itemClickListener: AlbumListItemClickListener){
mItemClickListener = itemClickListener
}



interface AlbumPlayListener{
fun changeText(album: Album)
}
private lateinit var sendMiniPlayer : AlbumPlayListener

fun sendToMiniPlayer(sendTodayAlbum : AlbumPlayListener) {
sendMiniPlayer = sendTodayAlbum
}



override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): AlbumRVAdapter.ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(parent.context), parent,false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
holder.bind(albumlist[position])
holder.itemView.setOnClickListener { mItemClickListener.onItemClick(albumlist[position]) }
holder.binding.homeTodayAlbumArrowIv.setOnClickListener { sendMiniPlayer.changeText(albumlist[position]) }
// holder.binding.homeTodayAlbumTitleTv.setOnClickListener { mItemClickListner.onRemoveAlbum(position) }
}

override fun getItemCount(): Int = albumlist.size


inner class ViewHolder(val binding: ItemAlbumBinding): RecyclerView.ViewHolder(binding.root){

fun bind(album: Album){
binding.homeTodayAlbumTitleTv.text = album.title
binding.homeTodayAlbumSingerTv.text = album.singer
binding.homeTodayAlbumIv.setImageResource(album.coverImg!!)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.imreallystupid

import com.google.gson.annotations.SerializedName

data class AuthResponse(
@SerializedName("status") val status: Boolean,
@SerializedName("code") val code: String,
@SerializedName("message") val message: String,
@SerializedName("data") val data: Data?
)

data class Data (
@SerializedName("name") val name : String,
@SerializedName("memberId") val memberId : Int,
@SerializedName("accessToken") val accessToken : String,
@SerializedName("result") val result : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.imreallystupid

import android.accounts.AccountAuthenticatorResponse
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.PATCH
import retrofit2.http.POST

interface AuthRetrofitInterface {
@POST("signup")
fun signUp(@Body user:User): Call<AuthResponse>

@POST("login")
fun login(@Body user:User): Call<AuthResponse>

// @GET("test")
// fun test(
// @Header("Authorization") token: String,
// ) : Response<AuthResponse>
}
Loading