-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
707 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.umc_6th | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
|
||
interface SongApi { | ||
@GET("/songs") | ||
fun getSongs(): Call<SongResponse> | ||
} |
56 changes: 56 additions & 0 deletions
56
UMC_6th/app/src/main/java/com/example/umc_6th/SongRVAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.umc_6th | ||
|
||
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.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
22
UMC_6th/app/src/main/java/com/example/umc_6th/SongResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
UMC_6th/app/src/main/java/com/example/umc_6th/SongService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "네트워크 오류가 발생했습니다.") | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.