MVP Design for Android: how do I get to my application?

I am writing an application that will have a JSON file that contains data that needs to be parsed and stored in ItemModel POJOs.

Suppose for now I have a simple Activity that doesn’t display anything - all I want my application to do is to parse JSON at startup and create model objects (I would like to find out the basic architecture of these items before move on to big / better things). I would like to unit test this code before creating any user interface components to make sure my model classes work fine.

So ItemModel is obviously a model object.

Where does JSON parsing fall in terms of MVP? A library for data analysis ( Gson , Jackson or something else?) Gson certainly require an Android Context for this, so should I parse this information into Activity ? If so, now the view knows about Model classes, which violates MVP.

Also, if I wanted them to ItemModel / JSON data in a database, where would this be done? The database should technically be in the model, but this requires Context to work correctly ...

Any thoughts? Thanks!

0
source share
1 answer

There is no exact / correct definition of the MVP implementation in Android

Here is a great article on MVP

I would do MVP as follows.

  • The model is POJO, parsing, storing (SQLlite) and receiving data (http). Obviously, I would separate the POJO logic, parsing and database logic into subfolders - but this all applies to the Model for me.
  • View - Activity , Fragment , Adapters - Actions and a fragment hold a link to the presenter, which gives them the data to display. How these data / messages are displayed, view + feel, etc. In view.
  • Lead . The average person provides logic to the inputs, i.e. button presses, data extraction, input validation, and then returns the result to the view ( Activity or Fragment ).

Here's a simplified MVP diagram

enter image description here

0
source

All Articles