Alemoore

Pomogite

Dec 1st, 2020 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. interface AlbumsAPIService {
  2. @GET("search?")
  3. suspend fun getAllAlbums(
  4. @Query("term") term: String = "hate",
  5. @Query("media") media: String = "music",
  6. @Query("entity") entityType: String = "album",
  7. @Query("attribute") attribute: String = "albumTerm"
  8. ): Response<ITunesResponse>
  9. }
  10.  
  11. class AlbumsRepository @Inject constructor(private val api: AlbumsAPIService) {
  12. suspend fun getAllAlbums() = api.getAllAlbums()
  13. }
  14.  
  15. class AlbumsViewModel @ViewModelInject constructor(
  16. private val repository: AlbumsRepository
  17. ): ViewModel() {
  18.  
  19. init {
  20. getAllAlbums()
  21. }
  22.  
  23. private fun getAllAlbums() {
  24. viewModelScope.launch {
  25. val response = repository.getAllAlbums()
  26. Log.d("ViewModel", response.body()!!.toString())
  27. }
  28. }
  29. }
  30.  
  31. data class ITunesResponse(
  32. val resultCount: Int,
  33. val albums: List<Album>
  34. )
  35.  
  36. data class Album(
  37. @field:Json(name = "amgArtistId") val amgArtistId: Int?,
  38. @field:Json(name = "artistId") val artistId: Int?,
  39. @field:Json(name = "artistName") val artistName: String?,
  40. @field:Json(name = "artistViewUrl") val artistViewUrl: String?,
  41. @field:Json(name = "artworkUrl100") val artworkUrl100: String?,
  42. @field:Json(name = "artworkUrl60") val artworkUrl60: String?,
  43. @field:Json(name = "collectionCensoredName") val collectionCensoredName: String?,
  44. @field:Json(name = "collectionExplicitness") val collectionExplicitness: String?,
  45. @field:Json(name = "collectionId") val collectionId: Int?,
  46. @field:Json(name = "collectionName") val collectionName: String?,
  47. @field:Json(name = "collectionPrice") val collectionPrice: Double?,
  48. @field:Json(name = "collectionType") val collectionType: String?,
  49. @field:Json(name = "collectionViewUrl") val collectionViewUrl: String?,
  50. @field:Json(name = "contentAdvisoryRating") val contentAdvisoryRating: String?,
  51. @field:Json(name = "copyright") val copyright: String?,
  52. @field:Json(name = "country") val country: String?,
  53. @field:Json(name = "currency") val currency: String?,
  54. @field:Json(name = "primaryGenreName") val primaryGenreName: String?,
  55. @field:Json(name = "releaseDate") val releaseDate: String?,
  56. @field:Json(name = "trackCount") val trackCount: Int?,
  57. @field:Json(name = "wrapperType") val wrapperType: String?
  58. )
Advertisement
Add Comment
Please, Sign In to add comment