mirror of https://github.com/jlelse/teleposter
Upgrade Fuel to 2.0.1 (also bump min sdk to 19 - required for update)
This commit is contained in:
parent
b17d8802a5
commit
c93a7ae575
|
@ -6,7 +6,7 @@ android {
|
||||||
buildToolsVersion "28.0.3"
|
buildToolsVersion "28.0.3"
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "telegra.ph"
|
applicationId "telegra.ph"
|
||||||
minSdkVersion 17
|
minSdkVersion 19
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 15
|
versionCode 15
|
||||||
versionName "1.5.2"
|
versionName "1.5.2"
|
||||||
|
@ -34,6 +34,7 @@ dependencies {
|
||||||
implementation 'com.github.delight-im:Android-AdvancedWebView:3.1.3'
|
implementation 'com.github.delight-im:Android-AdvancedWebView:3.1.3'
|
||||||
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc10'
|
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc10'
|
||||||
implementation 'com.afollestad.material-dialogs:input:2.0.0-rc10'
|
implementation 'com.afollestad.material-dialogs:input:2.0.0-rc10'
|
||||||
implementation 'com.github.kittinunf.fuel:fuel:1.16.0'
|
implementation 'com.github.kittinunf.fuel:fuel:2.0.1'
|
||||||
implementation 'com.github.kittinunf.fuel:fuel-android:1.16.0'
|
implementation 'com.github.kittinunf.fuel:fuel-android:2.0.1'
|
||||||
|
implementation 'com.github.kittinunf.fuel:fuel-json:2.0.1'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package telegra.ph
|
package telegra.ph
|
||||||
|
|
||||||
import com.github.kittinunf.fuel.android.core.Json
|
|
||||||
import com.github.kittinunf.fuel.android.extension.responseJson
|
|
||||||
import com.github.kittinunf.fuel.core.FuelError
|
import com.github.kittinunf.fuel.core.FuelError
|
||||||
import com.github.kittinunf.fuel.core.FuelManager
|
import com.github.kittinunf.fuel.core.FuelManager
|
||||||
import com.github.kittinunf.fuel.core.Request
|
import com.github.kittinunf.fuel.core.Request
|
||||||
import com.github.kittinunf.fuel.core.Response
|
import com.github.kittinunf.fuel.core.Response
|
||||||
import com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor
|
import com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor
|
||||||
import com.github.kittinunf.fuel.core.interceptors.validatorResponseInterceptor
|
|
||||||
import com.github.kittinunf.fuel.httpPost
|
import com.github.kittinunf.fuel.httpPost
|
||||||
|
import com.github.kittinunf.fuel.json.FuelJson
|
||||||
|
import com.github.kittinunf.fuel.json.responseJson
|
||||||
import com.github.kittinunf.result.Result
|
import com.github.kittinunf.result.Result
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
@ -27,12 +26,11 @@ object TelegraphApi {
|
||||||
// Fix login
|
// Fix login
|
||||||
FuelManager.instance.addResponseInterceptor {
|
FuelManager.instance.addResponseInterceptor {
|
||||||
redirectResponseInterceptor(FuelManager.instance)
|
redirectResponseInterceptor(FuelManager.instance)
|
||||||
validatorResponseInterceptor(200..299)
|
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun callService(method: String, parameters: List<Pair<String, Any?>>, handler: (Request, Response, Result<Json, FuelError>) -> Unit) {
|
private fun callService(method: String, parameters: List<Pair<String, Any?>>, handler: (Request, Response, Result<FuelJson, FuelError>) -> Unit) {
|
||||||
val requestObject = JSONObject()
|
val requestObject = JSONObject()
|
||||||
parameters.forEach {
|
parameters.forEach {
|
||||||
requestObject.put(it.first, it.second)
|
requestObject.put(it.first, it.second)
|
||||||
|
@ -153,7 +151,7 @@ object TelegraphApi {
|
||||||
|
|
||||||
// Teleposter
|
// Teleposter
|
||||||
|
|
||||||
private fun <T> handleResponse(result: Result<Json, FuelError>, handler: (success: Boolean, obj: T?, error: String?) -> Unit, callback: (obj: JSONObject) -> Unit) {
|
private fun <T> handleResponse(result: Result<FuelJson, FuelError>, handler: (success: Boolean, obj: T?, error: String?) -> Unit, callback: (obj: JSONObject) -> Unit) {
|
||||||
val (json, error) = result
|
val (json, error) = result
|
||||||
if (error == null && json != null) {
|
if (error == null && json != null) {
|
||||||
val jsonObj = json.obj()
|
val jsonObj = json.obj()
|
||||||
|
@ -182,8 +180,8 @@ object TelegraphApi {
|
||||||
private fun telegraphLoginInterceptor(): (Request, Response) -> Response =
|
private fun telegraphLoginInterceptor(): (Request, Response) -> Response =
|
||||||
{ _, response ->
|
{ _, response ->
|
||||||
response.headers["Set-Cookie"]
|
response.headers["Set-Cookie"]
|
||||||
?.flatMap { HttpCookie.parse(it) }
|
.flatMap { HttpCookie.parse(it) }
|
||||||
?.find { it.name == "tph_token" }
|
.find { it.name == "tph_token" }
|
||||||
?.let {
|
?.let {
|
||||||
loginAccessToken = it.value
|
loginAccessToken = it.value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue