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

Overview

This is the 2nd overview for the Sample Package.

Sample.MVP

In this is a sample of the project structure based of MVP style of an Android app. Why MVP? Simple, easy to manage and troubleshoot.

Activities

All your activities class goes here. Do not create any logic functions here. This class just binds your layouts XML to the java using ButterKnife and handles event listeners. All logics and error checking must be placed in the Presenter package.

You'll need to implement your own SampleView into this and create a Presenter Object which binds the View from your activity to your Presenter.

Models

All your models class goes here. The models usually have a request and respond class for each API depends on the API. Create them seperately. An online tool to convert JSON APIs into GSON Java class annotation is at jsonschema2pojo

Make sure to create a constructor for each models too.

Presenters

All and I meant ALL of your logics and error checking functions for an activity goes here which includes using the Retrofit call handling.

Ensure that each presenters implements the Presenter from the CORE pakage with your activity's view class as its type restriction.

To bind your view to a presenter, create a the view object

YourView yourview;

and then in the OnAttach() function, bind the object to the view param

public void attachView(@NonNull SampleView view) {
    yourview = view;
}

retroRest

This is your core binder for your module/package between the RestRepository and your Models. This is created so that it'll provide a modular approach to binding retrofit, gson models, and RxJava.

In your own rest class, create a class and contructor that bind the APIs fromt the CORE

private APIs mAPIs;
public GetYourSample(APIs APIs) {
    mAPIs = APIs;
}

Then call the corresponding API functions that points to your desired API calls

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

All your rest calling must go through this objects.

All your presenters must have this object in it to starting the API calling.

GetYourSample mGetSample;

Once created, you may use the execute to run the API calling for results.

mGetSample.execute(new Subscriber<SampleResponse>() {
        @Override
        public void onCompleted() {

        @Override
        public void onError(Throwable e) {}

        @Override
        public void onNext(SampleResponse sampleResponse) {}
    });