Skip to content

Instantly share code, notes, and snippets.

@marcRDZ
marcRDZ / EitherSharedPreferencesExtensions.kt
Last active March 31, 2022 09:44
An extensions utils to deal with SharedPreferences using Arrow https://arrow-kt.io/
import android.content.SharedPreferences
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import org.json.JSONException
import org.json.JSONObject
object Success
@marcRDZ
marcRDZ / EitherCallAdapterFactory.kt
Created March 29, 2022 08:13
A custom Retrofit CallAdapter.Factory to handle Response as Either
import arrow.core.Either
import okhttp3.Request
import okio.Timeout
import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import java.io.IOException
@marcRDZ
marcRDZ / ProgressBodyFeedback.kt
Last active March 29, 2022 07:19
A bunch of helpful classes based on OkHttp and Okio libraries to provide a progress feedback on download/upload files. In the case of upload you can attach this RequestBody as is, for the downloads you need to use the ResponseBody through an Interceptor also included.
import okhttp3.Interceptor
import okhttp3.RequestBody
import okhttp3.Response
import okhttp3.ResponseBody
import okio.*
import java.io.IOException
/**
* Wrapper class for [RequestBody] with a callback