Skip to content

Instantly share code, notes, and snippets.

Avatar
🐉
Turning coffee into code

Julian Falcionelli julianfalcionelli

🐉
Turning coffee into code
View GitHub Profile
@julianfalcionelli
julianfalcionelli / RetrofitManager.kt
Created Oct 28, 2019
Retrofit Manager + Offline Mode Support in Kotlin Version
View RetrofitManager.kt
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 Oct 28, 2019
ServerException Kotlin Version
View ServerException.kt
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 Jan 29, 2018
Circle CI + Slack Config
View config.yml
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 Nov 29, 2017
Using Retrofit with Cache
View DetailsActivity.java
//-------
private ExampleNetwork mExampleNetwork;
private void getDetails(String id) {
mExampleNetwork.getCachedDetails(id) // From Cache
.doFinally(() -> {
mExampleNetwork
.getDetails(id) // From Network
View ExampleNetwork.java
// -------
private IExampleNetwork mIExampleNetwork, mICachedExampleNetwork;
ExampleNetwork(RetrofitManager retrofitManager) {
mIExampleNetwork = retrofitManager.getRetrofit().create(IExampleNetwork.class);
mICachedExampleNetwork = retrofitManager.getCachedRetrofit().create(IExampleNetwork.class);
}
interface IExampleNetwork {
View RetrofitOfflineMode.java
//-------
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 Nov 28, 2017
Retrofit Manager + Offline Mode + Cache Mode Full example
View RetrofitManager.java
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;
View RxErrorHandlingCallAdapterFactory.java
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;
View MainActivity.java
//---
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
Observable Example with Lambda
View MainActivity.java
//---
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")
);