mirror of https://github.com/readrops/Readrops.git
Add adapter for Fever favicons call
This commit is contained in:
parent
5975458011
commit
562f11e2cc
|
@ -0,0 +1,70 @@
|
|||
package com.readrops.api.services.fever.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import com.readrops.api.utils.extensions.skipField
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonReader
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
data class Favicon(
|
||||
val id: Int,
|
||||
val data: ByteArray
|
||||
)
|
||||
|
||||
class FeverFaviconsAdapter {
|
||||
|
||||
@ToJson
|
||||
fun toJson(favicons: List<Favicon>) = ""
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@FromJson
|
||||
fun fromJson(reader: JsonReader): List<Favicon> = with(reader) {
|
||||
return try {
|
||||
val favicons = arrayListOf<Favicon>()
|
||||
|
||||
beginObject()
|
||||
|
||||
repeat(3) {
|
||||
skipField()
|
||||
}
|
||||
|
||||
nextName() // beginning of favicon array
|
||||
beginArray()
|
||||
|
||||
while (hasNext()) {
|
||||
beginObject()
|
||||
|
||||
var id = 0
|
||||
var data: ByteArray? = null
|
||||
|
||||
while (hasNext()) {
|
||||
when (selectName(NAMES)) {
|
||||
0 -> id = nextInt()
|
||||
1 -> data = nextString().toByteArray()
|
||||
else -> skipValue()
|
||||
}
|
||||
}
|
||||
|
||||
if (id > 0 && data != null) {
|
||||
favicons += Favicon(
|
||||
id = id,
|
||||
data = data,
|
||||
)
|
||||
}
|
||||
|
||||
endObject()
|
||||
}
|
||||
|
||||
endArray()
|
||||
|
||||
favicons
|
||||
} catch (e: Exception) {
|
||||
throw ParseException(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val NAMES: JsonReader.Options = JsonReader.Options.of("id", "data")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.readrops.api.services.fever.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import com.readrops.api.utils.extensions.skipField
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonReader
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
class FeverItemsIdsAdapter {
|
||||
|
||||
@ToJson
|
||||
fun toJson(ids: List<String>) = ""
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@FromJson
|
||||
fun fromJson(reader: JsonReader): List<String> = with(reader) {
|
||||
return try {
|
||||
|
||||
beginObject()
|
||||
repeat(3) {
|
||||
skipField()
|
||||
}
|
||||
|
||||
nextName() // unread_items_ids field
|
||||
val ids = nextString().split(",")
|
||||
|
||||
endObject()
|
||||
ids
|
||||
} catch (e: Exception) {
|
||||
throw ParseException(e.message)
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue