RequestResponse.kt 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package io.r_a_d.radio2.ui.songs.request
  2. import io.r_a_d.radio2.playerstore.Song
  3. import org.json.JSONObject
  4. class RequestResponse(jsonResponse: JSONObject) {
  5. //val total: Int = jsonResponse.getInt("total")
  6. //val perPage: Int = jsonResponse.getInt("per_page") // should stay 20 but in any case...
  7. val currentPage: Int = jsonResponse.getInt("current_page")
  8. val lastPage: Int = jsonResponse.getInt("last_page")
  9. //val fromNbr: Int = jsonResponse.getInt("from")
  10. //val toNbr: Int = jsonResponse.getInt("to")
  11. var songs : ArrayList<Song> = ArrayList()
  12. init {
  13. val songList = jsonResponse.getJSONArray("data")
  14. for (i in 0 until songList.length())
  15. {
  16. val title = (songList[i] as JSONObject).getString("title")
  17. val artist = (songList[i] as JSONObject).getString("artist")
  18. val id = (songList[i] as JSONObject).getInt("id")
  19. val s = Song("", id)
  20. s.title.value = title
  21. s.artist.value = artist
  22. s.isRequestable = (songList[i] as JSONObject).getBoolean("requestable")
  23. // TODO add the time before being requestable.
  24. songs.add(s)
  25. }
  26. }
  27. override fun toString(): String {
  28. var s = ""
  29. for (i in 0 until songs.size)
  30. {
  31. s += (songs[i].artist.value + " - " + songs[i].title.value + " | ")
  32. }
  33. return s
  34. }
  35. }