Skip to content

Commit

Permalink
[maro/#43] feat :: 9주차 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed Jun 18, 2024
1 parent 3d3fcde commit 56f79f6
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/other.xml

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.umc_6th

class ApiRepository {
companion object {
const val BASE_URL = "https://edu-api-test.softsquared.com"
}
}
13 changes: 13 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AuthApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.umc_6th

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthApi {
@POST("/users")
fun signUp(@Body user : User) : Call<BaseResponse>

@POST("/users/login")
fun login(@Body user : User) : Call<BaseResponse>
}
58 changes: 58 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.chrome.umcflo

import android.util.Log
import com.example.umc_6th.BaseResponse
import com.example.umc_6th.LoginView
import com.example.umc_6th.RetrofitInstance
import com.example.umc_6th.SignUpView
import com.example.umc_6th.User
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class AuthService {
private lateinit var signUpView: SignUpView
private lateinit var loginView: LoginView

fun setSignUpView(signUpView: SignUpView) {
this.signUpView = signUpView
}

fun setLoginView(loginView: LoginView) {
this.loginView = loginView
}

fun signUp(user : User) {
RetrofitInstance.authApi.signUp(user).enqueue(object: Callback<BaseResponse> {
override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
Log.d("SignUp-Success", response.toString())
val response : BaseResponse = response.body()!!
when(response.code) {
1000 -> signUpView.onSignUpSuccess()
else -> signUpView.onSignUpFailure(response.message)
}
}
override fun onFailure(call: Call<BaseResponse>, t: Throwable) {
Log.d("SignUp-Failure", t.message.toString())
}
})
Log.d("SignUpActivity", "All Finished")
}

fun login(user : User) {
RetrofitInstance.authApi.login(user).enqueue(object: Callback<BaseResponse> {
override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
Log.d("Login-Success", response.toString())
val response : BaseResponse = response.body()!!
when(val code = response.code) {
1000 -> loginView.onLoginSuccess(code, response.result!!)
else -> loginView.onLoginFailure(response.message)
}
}
override fun onFailure(call: Call<BaseResponse>, t: Throwable) {
Log.d("Login-Failure", t.message.toString())
}
})
Log.d("LoginActivity", "All Finished")
}
}
15 changes: 15 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/BaseResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.umc_6th

import com.google.gson.annotations.SerializedName

data class BaseResponse(
@SerializedName("isSuccess") val isSuccess : Boolean,
@SerializedName("code") val code : Int,
@SerializedName("message") val message : String,
@SerializedName("result") val result : Result?
)

data class Result (
@SerializedName("userIdx") var userIdx : Int,
@SerializedName("jwt") var jwt : String
)
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LoginView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.umc_6th

interface LoginView {
fun onLoginSuccess(code : Int, result : Result)
fun onLoginFailure(message : String)
}
7 changes: 7 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LookView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.umc_6th

interface LookView {
fun onGetSongLoading()
fun onGetSongSuccess(code: Int, result: FloChartResult)
fun onGetSongFailure(code: Int, message: String)
}
17 changes: 17 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/RetrofitInstance.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.umc_6th

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class RetrofitInstance {
companion object {
private val retrofit by lazy {
Retrofit.Builder()
.baseUrl(ApiRepository.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
val authApi = retrofit.create(AuthApi::class.java)
val songApi = retrofit.create(SongApi::class.java)
}
}
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SignUpView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.umc_6th

interface SignUpView {
fun onSignUpSuccess()
fun onSignUpFailure(message : String)
}
9 changes: 9 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.umc_6th

import retrofit2.http.GET
import retrofit2.Call

interface SongApi {
@GET("/songs")
fun getSongs(): Call<SongResponse>
}
58 changes: 58 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongRVAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.umc_6th

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.umc_6th.databinding.ItemSongBinding

class SongRVAdapter(val context: Context, val result : FloChartResult) : RecyclerView.Adapter<SongRVAdapter.ViewHolder>() {


override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): SongRVAdapter.ViewHolder {
val binding: ItemSongBinding = ItemSongBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: SongRVAdapter.ViewHolder, position: Int) {
//holder.bind(result.songs[position])

if(result.songs[position].coverImgUrl == "" || result.songs[position].coverImgUrl == null){

} else {
Log.d("image",result.songs[position].coverImgUrl )
Glide.with(context).load(result.songs[position].coverImgUrl).into(holder.coverImg)
}
holder.title.text = result.songs[position].title
holder.singer.text = result.songs[position].singer

}

override fun getItemCount(): Int = result.songs.size


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

val coverImg : ImageView = binding.itemSongImgIv
val title : TextView = binding.itemSongTitleTv
val singer : TextView = binding.itemSongSingerTv

}

interface MyItemClickListener{
fun onRemoveSong(songId: Int)
}

private lateinit var mItemClickListener: MyItemClickListener

fun setMyItemClickListener(itemClickListener: MyItemClickListener){
mItemClickListener = itemClickListener
}
}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongResponnse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.umc_6th

import com.google.gson.annotations.SerializedName

data class SongResponse(
@SerializedName("isSuccess") val isSuccess: Boolean,
@SerializedName("code") val code: Int,
@SerializedName("message") val message: String,
@SerializedName("result") val result: FloChartResult
)

data class FloChartResult(
@SerializedName("songs") val songs: List<FloChartSongs>
)

data class FloChartSongs(
@SerializedName("songIdx") val songIdx: Int,
@SerializedName("albumIdx") val albumIdx: Int,
@SerializedName("singer") val singer: String,
@SerializedName("title") val title:String,
@SerializedName("coverImgUrl") val coverImgUrl : String
)
40 changes: 40 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.umc_6th

import android.util.Log
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class SongService() {
private lateinit var lookView: LookView

fun setLookView(lookView: LookView) {
this.lookView = lookView
}

fun getSongs() {
lookView.onGetSongLoading()

RetrofitInstance.songApi.getSongs().enqueue(object : Callback<SongResponse> {
override fun onResponse(call: Call<SongResponse>, response: Response<SongResponse>) {
if (response.isSuccessful && response.code() == 200) {
val songResponse: SongResponse = response.body()!!

Log.d("SONG-RESPONSE", songResponse.toString())

when (val code = songResponse.code) {
1000 -> {
lookView.onGetSongSuccess(code, songResponse.result!!)
}

else -> lookView.onGetSongFailure(code, songResponse.message)
}
}
}

override fun onFailure(call: Call<SongResponse>, t: Throwable) {
lookView.onGetSongFailure(400, "네트워크 오류가 발생했습니다.")
}
})
}
}
71 changes: 71 additions & 0 deletions UMC_6th/app/src/main/res/layout/item_song.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="18dp"
android:paddingVertical="10dp">

<androidx.cardview.widget.CardView
android:id="@+id/item_song_img_cardView"
android:layout_width="50dp"
android:layout_height="50dp"
app:cardCornerRadius="7dp"
app:cardElevation="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/item_song_img_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/img_album_exp2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/item_song_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lilac"
android:textSize="16dp"
android:textColor="@color/black"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toTopOf="@id/item_song_img_cardView"
app:layout_constraintBottom_toTopOf="@id/item_song_singer_tv"
app:layout_constraintStart_toEndOf="@id/item_song_img_cardView"/>

<TextView
android:id="@+id/item_song_singer_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이유 (IU)"
android:textSize="13dp"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/item_song_title_tv"
app:layout_constraintBottom_toBottomOf="@id/item_song_img_cardView"
app:layout_constraintStart_toEndOf="@id/item_song_img_cardView"/>

<ImageView
android:id="@+id/item_song_play_iv"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/btn_player_play"
android:layout_marginRight="5dp"
app:layout_constraintEnd_toStartOf="@id/item_song_more_iv"
app:layout_constraintTop_toTopOf="@id/item_song_more_iv"
app:layout_constraintBottom_toBottomOf="@id/item_song_more_iv"/>

<ImageView
android:id="@+id/item_song_more_iv"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/btn_player_more"
android:layout_marginRight="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 56f79f6

Please sign in to comment.