1. Overview 1 - addam01/android-rx-retro-kickstart GitHub Wiki

Overview

This is a skeleton android project files which incorporates the RxJava, and Retrofit.

As such, here I'll explain each packages and what does it do.

Core Package

This packeage handles all the core RxJava and Retrofit but excluding the Models since each Model are represented in their very own Package module.

Never, I repeat! Never! Add any MVPs or adapters here. Each should be outside the Core package. If you have multiple Service API , please add them into their respective package then add them into this line in the Core -> Rest -> RestRepository.java

mRestServices = mRetrofit.create(RestServices.class);
yourService = mRetrofit.create(RestServices.class);

Presenter.java

This interface handler for Presenters that extends to their respective Views.

To use this, create a Presenter in your module/package, and implement this Presenter as so

public class YourPresenter implements Presenter<YourView>{}

View.java

This is a stubbed interface to replace the default android.view class into an interface.

To use this, create a View in your module/package, and extend this View rather than the default view as so

public interface YourView extend View{}

RetrofitExecutable.java

This is a Retrofit interface for each of your API - Model bindings to retrofit. It helps define the RxJava Subcription for your API callings on Retrofit since the Retrofit is now Observed by RxJava. So just Subcribe to the observer only.

To use this, create a REST class in your module/package, and implement this ReftrofitExecutable as so

public class GetYourRest implements RetrofitExecutable{}

You'll be prompted to implement the function in it, accept it and update the default Subscription with your API calling along with the parameters for your model.

@Override
public Subscription execute(Subscriber subscriber) {
    return mAPIs.getYourResponse(name,password) <- Here
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(subscriber);

Rest Package

This an interface for the RestRepository.class which also binds all your services into it as a parameters.

So once you are done creating your Services in your module/package and have included into the RestRepository, create an Observer in this that mirrors your Service as so

Observable<YourResponseModel> getYourResponse(Your request model parameters);

An Example:

Observable<YourResponseModel> getYourResponse(String sampleName, String samplePassword);

This is what makes and breaks this project. It is the core class that does the heavy duty of binding Network threads with RxJava, Retrofit, and OkHttp handlers.

It does :

  1. Handling your GSON Adapters for nested JSONs
  2. Hanlding your network profile such as SSL/TLS credentials
  3. Binding Retrofit to OKHttp
  4. Binding your Services to the Retrofit handler
  5. Binding your Services to an Observer

More guide to using this here.

RestService

This is just a sample of a Rest Service for your reference. It uses the Retrofit annotation for the API callings. Create your own RestSerive end point outside this CORE packaage!! Just ensure your define the Root URL in the RestRepository's

mRetrofit = new Retrofit.Builder()
            .baseUrl(baseURL) <- Here
            .client(clientLIVE)
⚠️ **GitHub.com Fallback** ⚠️