Skip to content

Commit

Permalink
fix error api
Browse files Browse the repository at this point in the history
  • Loading branch information
minhnhatdeii committed Dec 1, 2024
1 parent c5e660e commit 05bd816
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .idea/deploymentTargetSelector.xml

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

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".MyApplication"
Expand Down
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", "c18da195b0mshcdebcf46df53015p1a1b64jsn33955d1b96fc")
.addHeader("x-rapidapi-key", "89644839e0mshcae86286ffb46fcp1e2f10jsn5dacb407fc3b")
.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,6 +57,23 @@ 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,12 +29,15 @@ 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

} ?: HomeUIState.Error
Log.d("HomeUIState", "other")
}
}
companion object {
Expand Down

0 comments on commit 05bd816

Please sign in to comment.