Now that we have the required gradle setup let’s start creating the core architecture of the project
Über-quick introduction
MVP (Model — View — Presenter) is an architectural concept aimed to decouple the view (Activity/Fragment/Custom view showing things to the user) from the presenter (layer handling data for the View) and from the model (managing data model). Furthermore in this example we have also the figure of the Repository which acts as the layer where the actual data retrieval happens
This helps a great deal with code clarity, atomic responsibility, project structure and testing (and many more!) The obtained decoupling is awesome and we can use it to establish the MVP architecture via interfaces for the view and the presenter in the following way
Base presenter super class
Each presenter in the app will inherit from this abstract class
Here we defined the view the specific presenter refers to (needs to be attached when the view is created and detached when the view is destroyed to avoid memory leaks)
Base repository super class
Each repository in the app will inherit from this abstract class
This base class creates a cache for the flowables emitted by RxJava and caches them for future re-use
I realize this class may raise more questions than it answers, but this is more a post to put in practice what all those technologies/libraries/patterns promise, for specific tutorials on what a Scheduler is or what a Disposable or Single are I suggest reading this or other posts specific on RxJava/RxAndroid
Next topic will be creation of core classes for Butterknife and Icepick
Leave a Comment