Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c7bd53f authored by Nishant D's avatar Nishant D
Browse files

Update as per code review comment

parent 8357ebe7
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -3,5 +3,8 @@ package app.lounge.extension
import com.google.gson.Gson
import com.google.gson.Gson
import java.util.Properties
import java.util.Properties


/** Convert Properties parameter to byte array*/
/**
 * Convert Properties parameter to byte array
 * @return Byte Array of Properties
 * */
fun Properties.toByteArray() = Gson().toJson(this).toByteArray()
fun Properties.toByteArray() = Gson().toJson(this).toByteArray()
 No newline at end of file
+9 −9
Original line number Original line Diff line number Diff line
@@ -8,7 +8,7 @@ import java.net.UnknownHostException




//region Retrofit Asynchronous Networking
//region Retrofit Asynchronous Networking
interface RetrofitFetching {
interface NetworkFetching {
    val executor: Executor get() = callEnqueue
    val executor: Executor get() = callEnqueue


    val checkNetwork: (() -> Boolean)? get() = null
    val checkNetwork: (() -> Boolean)? get() = null
@@ -61,8 +61,8 @@ interface RetrofitFetching {
 * @param success Success callback with the response `R`
 * @param success Success callback with the response `R`
 * @param failure Failure callback with an error case from `AnyFetchError` subtypes
 * @param failure Failure callback with an error case from `AnyFetchError` subtypes
 */
 */
inline fun <reified R> RetrofitFetching.fetch(
inline fun <reified R> NetworkFetching.fetch(
    usingExecutor: RetrofitFetching.Executor = executor,
    usingExecutor: NetworkFetching.Executor = executor,
    endpoint: Call<R>,
    endpoint: Call<R>,
    noinline success: (R) -> Unit,
    noinline success: (R) -> Unit,
    noinline failure: (FetchError) -> Unit
    noinline failure: (FetchError) -> Unit
@@ -84,10 +84,10 @@ inline fun <reified R> RetrofitFetching.fetch(
 * @param success Success callback with the response `R`
 * @param success Success callback with the response `R`
 * @param failure Failure callback with an error case from given error subtype `E`
 * @param failure Failure callback with an error case from given error subtype `E`
 */
 */
fun <R, E> RetrofitFetching.fetch(
fun <R, E> NetworkFetching.fetch(
    usingExecutor: RetrofitFetching.Executor = executor,
    usingExecutor: NetworkFetching.Executor = executor,
    endpoint: Call<R>,
    endpoint: Call<R>,
    resultProcessing: RetrofitFetching.ResultProcessing<R, E>,
    resultProcessing: NetworkFetching.ResultProcessing<R, E>,
    success: (R) -> Unit,
    success: (R) -> Unit,
    failure: (E) -> Unit
    failure: (E) -> Unit
) {
) {
@@ -107,9 +107,9 @@ sealed class RetrofitResult<R, E> {
}
}


private fun <R, E> fetch(
private fun <R, E> fetch(
    usingExecutor: RetrofitFetching.Executor,
    usingExecutor: NetworkFetching.Executor,
    endpoint: Call<R>,
    endpoint: Call<R>,
    resultProcessing: RetrofitFetching.ResultProcessing<R, E>,
    resultProcessing: NetworkFetching.ResultProcessing<R, E>,
    callback: (RetrofitResult<R, E>) -> Unit,
    callback: (RetrofitResult<R, E>) -> Unit,
) {
) {
    usingExecutor.fetchAndCallback(endpoint, object : Callback<R> {
    usingExecutor.fetchAndCallback(endpoint, object : Callback<R> {
@@ -132,7 +132,7 @@ open class RetrofitResultProcessing<R, E>(
    override val tryCastResponseBody: (Any?) -> R?,
    override val tryCastResponseBody: (Any?) -> R?,
    override val errorFromNetworkFailure: (AnyFetchError) -> E,
    override val errorFromNetworkFailure: (AnyFetchError) -> E,
    hasNetwork: (() -> Boolean)? = null,
    hasNetwork: (() -> Boolean)? = null,
) : RetrofitFetching.ResultProcessing<R, E> {
) : NetworkFetching.ResultProcessing<R, E> {


    companion object {
    companion object {
        inline operator fun <reified R, E> invoke(
        inline operator fun <reified R, E> invoke(
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,7 +2,7 @@ package app.lounge.users.anonymous


import app.lounge.extension.toByteArray
import app.lounge.extension.toByteArray
import app.lounge.networking.FetchError
import app.lounge.networking.FetchError
import app.lounge.networking.RetrofitFetching
import app.lounge.networking.NetworkFetching
import app.lounge.networking.appLounge
import app.lounge.networking.appLounge
import app.lounge.networking.fetch
import app.lounge.networking.fetch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MediaType.Companion.toMediaTypeOrNull
@@ -18,7 +18,7 @@ internal class RetrofitAnonymousAPI(
    baseURL: String,
    baseURL: String,
    anonymousUserEndpointFollowsRedirects: Boolean,
    anonymousUserEndpointFollowsRedirects: Boolean,
    callTimeoutInSeconds: Long,
    callTimeoutInSeconds: Long,
): AnonymousAPI, RetrofitFetching {
): AnonymousAPI, NetworkFetching {


    private val anonymousUserEndPoint: AnonymousUserEndPointEndpoint = Retrofit.Builder().appLounge(
    private val anonymousUserEndPoint: AnonymousUserEndPointEndpoint = Retrofit.Builder().appLounge(
        baseURL = baseURL,
        baseURL = baseURL,
@@ -30,7 +30,7 @@ internal class RetrofitAnonymousAPI(


        @POST
        @POST
        fun authDataRequest(
        fun authDataRequest(
            @Url url: String = "https://eu.gtoken.ecloud.global",
            @Url url: String = AnonymousAPI.tokenBaseURL,
            @HeaderMap headers: Map<String, String>,
            @HeaderMap headers: Map<String, String>,
            @Body requestBody: RequestBody
            @Body requestBody: RequestBody
        ): Call<LoginResponse>
        ): Call<LoginResponse>