Replace deprecated Gson JsonParser usages
This commit is contained in:
parent
724e1d33b6
commit
b3daf7d760
@ -194,7 +194,7 @@ class BackupRestoreService : Service() {
|
|||||||
return Observable.just(Unit)
|
return Observable.just(Unit)
|
||||||
.map {
|
.map {
|
||||||
val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader())
|
val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader())
|
||||||
val json = JsonParser().parse(reader).asJsonObject
|
val json = JsonParser.parseReader(reader).asJsonObject
|
||||||
|
|
||||||
// Get parser version
|
// Get parser version
|
||||||
val version = json.get(VERSION)?.asInt ?: 1
|
val version = json.get(VERSION)?.asInt ?: 1
|
||||||
|
@ -21,7 +21,6 @@ import rx.Observable
|
|||||||
|
|
||||||
class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
||||||
|
|
||||||
private val parser = JsonParser()
|
|
||||||
private val jsonMime = "application/json; charset=utf-8".toMediaTypeOrNull()
|
private val jsonMime = "application/json; charset=utf-8".toMediaTypeOrNull()
|
||||||
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).obj
|
val response = JsonParser.parseString(responseBody).obj
|
||||||
track.library_id = response["data"]["SaveMediaListEntry"]["id"].asLong
|
track.library_id = response["data"]["SaveMediaListEntry"]["id"].asLong
|
||||||
track
|
track
|
||||||
}
|
}
|
||||||
@ -138,7 +137,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).obj
|
val response = JsonParser.parseString(responseBody).obj
|
||||||
val data = response["data"]!!.obj
|
val data = response["data"]!!.obj
|
||||||
val page = data["Page"].obj
|
val page = data["Page"].obj
|
||||||
val media = page["media"].array
|
val media = page["media"].array
|
||||||
@ -198,7 +197,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).obj
|
val response = JsonParser.parseString(responseBody).obj
|
||||||
val data = response["data"]!!.obj
|
val data = response["data"]!!.obj
|
||||||
val page = data["Page"].obj
|
val page = data["Page"].obj
|
||||||
val media = page["mediaList"].array
|
val media = page["mediaList"].array
|
||||||
@ -242,7 +241,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).obj
|
val response = JsonParser.parseString(responseBody).obj
|
||||||
val data = response["data"]!!.obj
|
val data = response["data"]!!.obj
|
||||||
val viewer = data["Viewer"].obj
|
val viewer = data["Viewer"].obj
|
||||||
Pair(viewer["id"].asInt, viewer["mediaListOptions"]["scoreFormat"].asString)
|
Pair(viewer["id"].asInt, viewer["mediaListOptions"]["scoreFormat"].asString)
|
||||||
|
@ -22,7 +22,6 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
class BangumiApi(private val client: OkHttpClient, interceptor: BangumiInterceptor) {
|
class BangumiApi(private val client: OkHttpClient, interceptor: BangumiInterceptor) {
|
||||||
|
|
||||||
private val gson: Gson by injectLazy()
|
private val gson: Gson by injectLazy()
|
||||||
private val parser = JsonParser()
|
|
||||||
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
||||||
|
|
||||||
fun addLibManga(track: Track): Observable<Track> {
|
fun addLibManga(track: Track): Observable<Track> {
|
||||||
@ -91,7 +90,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
|
|||||||
if (responseBody.contains("\"code\":404")) {
|
if (responseBody.contains("\"code\":404")) {
|
||||||
responseBody = "{\"results\":0,\"list\":[]}"
|
responseBody = "{\"results\":0,\"list\":[]}"
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).obj["list"]?.array
|
val response = JsonParser.parseString(responseBody).obj["list"]?.array
|
||||||
response?.filter { it.obj["type"].asInt == 1 }?.map { jsonToSearch(it.obj) }
|
response?.filter { it.obj["type"].asInt == 1 }?.map { jsonToSearch(it.obj) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
|
|||||||
.map { netResponse ->
|
.map { netResponse ->
|
||||||
// get comic info
|
// get comic info
|
||||||
val responseBody = netResponse.body?.string().orEmpty()
|
val responseBody = netResponse.body?.string().orEmpty()
|
||||||
jsonToTrack(parser.parse(responseBody).obj)
|
jsonToTrack(JsonParser.parseString(responseBody).obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInterceptor) {
|
class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInterceptor) {
|
||||||
|
|
||||||
private val gson: Gson by injectLazy()
|
private val gson: Gson by injectLazy()
|
||||||
private val parser = JsonParser()
|
|
||||||
private val jsonime = "application/json; charset=utf-8".toMediaTypeOrNull()
|
private val jsonime = "application/json; charset=utf-8".toMediaTypeOrNull()
|
||||||
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
private val authClient = client.newBuilder().addInterceptor(interceptor).build()
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).array
|
val response = JsonParser.parseString(responseBody).array
|
||||||
response.map { jsonToSearch(it.obj) }
|
response.map { jsonToSearch(it.obj) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +123,7 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter
|
|||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
.map { netResponse ->
|
.map { netResponse ->
|
||||||
val responseBody = netResponse.body?.string().orEmpty()
|
val responseBody = netResponse.body?.string().orEmpty()
|
||||||
parser.parse(responseBody).obj
|
JsonParser.parseString(responseBody).obj
|
||||||
}.flatMap { mangas ->
|
}.flatMap { mangas ->
|
||||||
authClient.newCall(request)
|
authClient.newCall(request)
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
@ -133,7 +132,7 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter
|
|||||||
if (responseBody.isEmpty()) {
|
if (responseBody.isEmpty()) {
|
||||||
throw Exception("Null Response")
|
throw Exception("Null Response")
|
||||||
}
|
}
|
||||||
val response = parser.parse(responseBody).array
|
val response = JsonParser.parseString(responseBody).array
|
||||||
if (response.size() > 1) {
|
if (response.size() > 1) {
|
||||||
throw Exception("Too much mangas in response")
|
throw Exception("Too much mangas in response")
|
||||||
}
|
}
|
||||||
@ -147,7 +146,7 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter
|
|||||||
|
|
||||||
fun getCurrentUser(): Int {
|
fun getCurrentUser(): Int {
|
||||||
val user = authClient.newCall(GET("$apiUrl/users/whoami")).execute().body?.string()
|
val user = authClient.newCall(GET("$apiUrl/users/whoami")).execute().body?.string()
|
||||||
return parser.parse(user).obj["id"].asInt
|
return JsonParser.parseString(user).obj["id"].asInt
|
||||||
}
|
}
|
||||||
|
|
||||||
fun accessToken(code: String): Observable<OAuth> {
|
fun accessToken(code: String): Observable<OAuth> {
|
||||||
|
Loading…
Reference in New Issue
Block a user