Bump gplayapi to 3.1.0

Also, override required responseCode StateFlow for HttpClient

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-04-23 17:37:33 +05:30
parent b590edacce
commit 53854a8a67
3 changed files with 25 additions and 3 deletions

View File

@@ -168,7 +168,7 @@ dependencies {
implementation "com.github.topjohnwu.libsu:core:${versions.libsu}"
//Love <3
implementation "com.gitlab.AuroraOSS:gplayapi:3.0.1"
implementation "com.gitlab.AuroraOSS:gplayapi:3.1.0"
//Test
testImplementation 'junit:junit:4.13.2'

View File

@@ -26,9 +26,16 @@ import com.aurora.store.util.Log
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.*
import java.nio.charset.Charset
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
object FuelClient : IHttpClient {
private val _responseCode = MutableStateFlow(0)
override val responseCode: StateFlow<Int>
get() = _responseCode.asStateFlow()
override fun get(url: String, headers: Map<String, String>): PlayResponse {
return get(url, headers, hashMapOf())
}
@@ -104,6 +111,9 @@ object FuelClient : IHttpClient {
@JvmStatic
private fun buildPlayResponse(response: Response, request: Request): PlayResponse {
// Reset response code as flow doesn't sends the same value twice
_responseCode.value = 0
return PlayResponse().apply {
isSuccessful = response.isSuccessful
code = response.statusCode
@@ -117,7 +127,8 @@ object FuelClient : IHttpClient {
errorString = String(errorBytes)
}
}.also {
_responseCode.value = response.statusCode
Log.i("FUEL [${request.method}:${response.statusCode}] ${response.url}")
}
}
}
}

View File

@@ -31,12 +31,19 @@ import okhttp3.OkHttpClient
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
object OkHttpClient : IHttpClient {
private const val POST = "POST"
private const val GET = "GET"
private val _responseCode = MutableStateFlow(100)
override val responseCode: StateFlow<Int>
get() = _responseCode.asStateFlow()
private val okHttpClient = OkHttpClient().newBuilder()
.connectTimeout(25, TimeUnit.SECONDS)
.readTimeout(25, TimeUnit.SECONDS)
@@ -140,6 +147,9 @@ object OkHttpClient : IHttpClient {
}
private fun processRequest(request: Request): PlayResponse {
// Reset response code as flow doesn't sends the same value twice
_responseCode.value = 0
val call = okHttpClient.newCall(request)
return buildPlayResponse(call.execute())
}
@@ -165,7 +175,8 @@ object OkHttpClient : IHttpClient {
errorString = response.message
}
}.also {
_responseCode.value = response.code
Log.i("OKHTTP [${response.code}] ${response.request.url}")
}
}
}
}