Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
minhnhatdeii committed Dec 12, 2024
1 parent 05bd816 commit 5fa427e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .idea/misc.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
Expand Up @@ -20,17 +20,17 @@ class DefaultHomeScreenRepo : HomeScreenRepo {
var result : ResponseHomeScreenData? = null

try {

val client = OkHttpClient()

val request = Request.Builder()
.url("https://spotify-scraper.p.rapidapi.com/v1/home")
.get()
.addHeader("x-rapidapi-key", "89644839e0mshcae86286ffb46fcp1e2f10jsn5dacb407fc3b")
.addHeader("x-rapidapi-key", "bc05c5534fmsh8fb5f0a628eb2c8p1262e2jsn9a210e841cc1")
.addHeader("x-rapidapi-host", "spotify-scraper.p.rapidapi.com")
.build()

val response = client.newCall(request).execute()

// Kiểm tra xem phản hồi có thành công không
if (response.isSuccessful) {
val jsonResponse = response.body?.string()
Expand All @@ -57,23 +57,6 @@ class DefaultHomeScreenRepo : HomeScreenRepo {
listChart?.addAll(PopularChart.map {
ChartOut(it.name, it.images?.get(0)?.get(0)?.url, it.id)
})
// for (i in PopularArtist!!) {
// val subArtist = ArtistOut(i.id, i.name, i.visuals?.avatar?.get(1)?.url)
// listPopularArtist?.add(subArtist)
// }
//
// for (i in PopularAlbums!!) {//duyet phan tu album
// var listArtistInAlbum : MutableList<String> = mutableListOf()
// for( j in i.artists) {// truy van nghe si cua album
// listArtistInAlbum.add(j.name)
// }
// val subAlbum = AlbumOut(i.id, i.name, i.cover[1].url, listArtistInAlbum)
// listPopularAlbums?.add(subAlbum)
// }
// for (i in PopularChart!!) {
// val subChart = ChartOut(i.name, i.images?.get(0)?.get(0)?.url, i.id)
// listChart?.add(subChart)
// }

result = ResponseHomeScreenData(listPopularArtist, listPopularAlbums, listChart)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ class HomeViewModel(
fun fetchHomePageData() {
viewModelScope.launch (Dispatchers.IO){
_state.value = HomeUIState.Loading
Log.d("HomeUIState", "Loading")
val result = homeScreenRepo.updatePopularItem()


_state.value = result?.let {
HomeUIState.Success(it)

} ?: HomeUIState.Error
Log.d("HomeUIState", "other")

}
}
companion object {
Expand Down

0 comments on commit 5fa427e

Please sign in to comment.