`artistProfileRecyclerView=findViewById(R.id.recyclerViewArtist)
artistProfileRecyclerView.layoutManager=LinearLayoutManager (this@DashBoardActivity)
artistArrayList= arrayListOf()
Код: Выделить всё
artistProfileRecyclerView.adapter=ArtistsProfileAdapter(artistArrayList,this@DashBoardActivity)
// Retrofit API call for artist profiles
val retrofitBuilderArtist=Retrofit.Builder()
.baseUrl("https://deezerdevs-deezer.p.rapidapi.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ArtistProfileApiInterface::class.java)
//call the API to get artist data
val retrofitArtistData=retrofitBuilderArtist.getProductData("artist")
retrofitArtistData.enqueue(object :Callback{
override fun onResponse(call : Call, response: Response) {
val artistsProfileDataList=response.body()?.data ?:return
for (artist in artistsProfileDataList){
val artistName=artist.title
val artistImage=artist.album.cover_medium
val artistsProfile=ArtistsProfile(artistName,artistImage)
artistArrayList.add(artistsProfile)
}
artistProfileRecyclerView.adapter?.notifyDataSetChanged()
}
override fun onFailure(call: Call, t: Throwable) {
Log.d("TAG: onFailure", "onFailure: "+t.message)
}
})`
Подробнее здесь: https://stackoverflow.com/questions/791 ... r-api-call
Мобильная версия