Skip to content

Instantly share code, notes, and snippets.

View julianfalcionelli's full-sized avatar
🐉
Turning coffee into code

Julian Falcionelli julianfalcionelli

🐉
Turning coffee into code
View GitHub Profile
@julianfalcionelli
julianfalcionelli / RetrofitManager.kt
Created October 28, 2019 10:52
Retrofit Manager + Offline Mode Support in Kotlin Version
import android.app.Application
import android.util.Log
import co.myapp.BuildConfig
import co.myapp.infrastructure.manager.InternetManager
import co.myapp.infrastructure.manager.interfaces.AuthenticationManager
import com.facebook.stetho.Stetho
import com.facebook.stetho.okhttp3.StethoInterceptor
import com.google.gson.Gson
import com.readystatesoftware.chuck.ChuckInterceptor
import okhttp3.Cache
@julianfalcionelli
julianfalcionelli / ServerException.kt
Created October 28, 2019 08:41
ServerException Kotlin Version
import retrofit2.Response
import retrofit2.Retrofit
import timber.log.Timber
import java.io.IOException
class ServerException internal constructor(
message: String?,
/**
* The request URL which produced the error.
*/
@julianfalcionelli
julianfalcionelli / config.yml
Created January 29, 2018 13:45
Circle CI + Slack Config
version: 2
jobs:
check-build:
docker:
# specify the version you desire here
- image: circleci/android:api-27-alpha
working_directory: ~/code
steps:
- checkout
- run: echo "Running..."
@julianfalcionelli
julianfalcionelli / DetailsActivity.java
Last active November 29, 2017 20:01
Using Retrofit with Cache
//-------
private ExampleNetwork mExampleNetwork;
private void getDetails(String id) {
mExampleNetwork.getCachedDetails(id) // From Cache
.doFinally(() -> {
mExampleNetwork
.getDetails(id) // From Network
// -------
private IExampleNetwork mIExampleNetwork, mICachedExampleNetwork;
ExampleNetwork(RetrofitManager retrofitManager) {
mIExampleNetwork = retrofitManager.getRetrofit().create(IExampleNetwork.class);
mICachedExampleNetwork = retrofitManager.getCachedRetrofit().create(IExampleNetwork.class);
}
interface IExampleNetwork {
@julianfalcionelli
julianfalcionelli / RetrofitOfflineMode.java
Created November 28, 2017 18:48
Retrofit with offline mode
//-------
public static final String BASE_URL = "https://lateralview.co";
public static final String HEADER_CACHE_CONTROL = "Cache-Control";
public static final String HEADER_PRAGMA = "Pragma";
private Context mContext;
//-------
@julianfalcionelli
julianfalcionelli / RetrofitManager.java
Created November 28, 2017 18:35
Retrofit Manager + Offline Mode + Cache Mode Full example
public class RetrofitManager {
public static final String TAG = "RetrofitManager";
public static final String BASE_URL = "https://lateralview.co";
public static final String HEADER_CACHE_CONTROL = "Cache-Control";
public static final String HEADER_PRAGMA = "Pragma";
private Context mContext;
private Retrofit mRetrofit, mCachedRetrofit;
@julianfalcionelli
julianfalcionelli / RxErrorHandlingCallAdapterFactory.java
Last active June 21, 2022 08:55
Rx Error Handling for Retrofit2
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Single;
import io.reactivex.SingleSource;
import io.reactivex.annotations.NonNull;
//---
Single.create((SingleOnSubscribe<String>) e -> e.onSuccess(makeBlockingTask()))
.subscribeOn(Schedulers.io()) //Run on IO Thread
.observeOn(AndroidSchedulers.mainThread()) //Run on UI Thread
.doOnSubscribe(__ -> showLoadingIndicator())
.doFinally(() -> hideLoadingIndicator())
.subscribe(this::processResult,
this::processError);
@julianfalcionelli
julianfalcionelli / MainActivity.java
Last active May 16, 2017 00:03
Observable Example with Lambda
//---
Observable
.just(1, 2, 3, 4, 5)
.filter(integer -> integer % 2 != 0)
.subscribe(
integer -> Log.i(TAG, String.valueOf(integer)),
error -> Log.e(TAG, "Error"),
() -> Log.i(TAG, "No more results")
);