boorujelly/app/src/main/java/com/example/testes/BooruImage.kt

40 lines
1.2 KiB
Kotlin
Raw Normal View History

2022-02-06 18:12:27 +00:00
package com.example.testes
import android.util.Log
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
data class BooruImage (
var id: String,
2022-02-18 21:48:14 +00:00
var rating: String,
2022-02-06 18:12:27 +00:00
var tags: String,
2022-02-18 21:48:14 +00:00
var file_url: String,
var preview_url: String,
2022-02-06 18:12:27 +00:00
) {
fun clone(): BooruImage {
return BooruImage(id, rating, tags, file_url, preview_url)
}
2022-02-06 18:12:27 +00:00
companion object {
@Throws(JSONException::class)
fun imageFromJson(json: JSONObject): BooruImage {
val id = json.getInt("id").toString()
2022-02-18 21:48:14 +00:00
val rating = json.getString("rating")
2022-02-06 18:12:27 +00:00
val tags = json.getString("tags")
2022-02-18 21:48:14 +00:00
val file_url = json.getString("file_url")
val preview_url = json.getString("preview_url")
return BooruImage(id, rating, tags, file_url, preview_url)
2022-02-06 18:12:27 +00:00
}
@Throws(JSONException::class)
fun listFromJsonArray(array: JSONArray): MutableList<BooruImage> {
val imageList: MutableList<BooruImage> = mutableListOf()
for (i in 0 until array.length()) {
imageList.add(imageFromJson(array.getJSONObject(i)))
}
return imageList
}
}
}