0

I am writing an application that will have a JSON file which contains data that should be parsed and saved into ItemModel POJOs.

Let's assume for now I have a simple Activity that displays nothing at all - all I want my application to do is on startup parse the JSON and create the model objects (I'd like to figure out the basic architecture of these pieces before moving onto bigger/better things). I'd like to unit test this code before making any UI components to ensure my model classes are working OK.

So, the ItemModel is obviously a model object.

Where does the JSON parsing fall in terms of MVP? The library to parse the data (Gson, Jackson, or something else?) will surely require an Android Context to achieve this, so should I be parsing that information in the Activity? If yes, now the view knows about Model classes, which breaks MVP.

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

Any thoughts? Thanks!

Zach
  • 3,909
  • 6
  • 25
  • 50
  • You can take a look at this sample project http://github.com/mmirhoseini/marvel and this article https://hackernoon.com/yet-another-mvp-article-part-1-lets-get-to-know-the-project-d3fd553b3e21 to get more familiar with MVP. – Mohsen Mirhoseini Dec 16 '16 at 17:59

1 Answers1

0

There is no exact/correct definition of implementing MVP in Android

Here's a great article on MVP

I'd do MVP as follow.

  1. Model - POJO's, parsing, Storing (SQLlite) and retrieving data (http). Obviously I'd divide the POJO's, parsing and DB logic into sub folders - but this all falls into Model for me.
  2. View - Activity, Fragment, Adapters - Activities & Fragment hold reference to a Presenter that gives them data to display. How this data/messages are displayed, look + feel etc. is dealt with in the View.
  3. Presenter - The Middle man, provides the logic to inputs i.e. Button Clicks, retrieval of data, validation of inputs & then passes the result back to the View (Activity or Fragment)

Here's a simplified diagram of MVP

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zain
  • 2,336
  • 1
  • 16
  • 25