Skip to content
Eugene Wang edited this page Apr 28, 2018 · 1 revision

Introduction Hi, welcome aboard Hachy. Architecture: MVP M: modal – logic, and data V: View – UI P: Presenter – doer Modal never doesnt talk to View, everthing is done through Presenter. This include both view to modal and modal to view directions communication • Wiki • StyleGuide by Francesco

Activities(Android Component) An activity (read this doc) is a single, focused thing that the user can do. we have Activity Purpose MainActivity Display Catalogue of eggs ->Calls database reference via DbDatabaseReader (this is a presenter) ->Receives list of eggs from presenter ->populate the list via the adaptor DetailedActivity Display information of a single egg FacebookLogin Activity Enable user to login CameraActivity Well, facilitate Camera usage, send taken picture back to Main

Presenter Presenter is not an android component, meaning that you do not necessarily need them. In fact you call put all the code from presenter into Activities yet they still work. But you don’t want to do that because:

  1. You do not own activities, android does, Android may choose to terminate the activities whenever. So it is best practice for seperating logic into separate classes
  2. Seperation of concern: less context issues and easier unit test, and easier debugging.

Presenter Purpose AzurePresenter Uses Retrofit to : ->send image to Azure Comstomvision.ai for recognition ->recieves recognition and pack them into AzurePrediction Object EggDeterminator Recieves Egg and call AzurePresenter for determination, and store on Google real time database FbDatabasePresenter Abstract class storing reference to Firebase and current user’s database FbDatabaseRead Read Eggs: recieves datasnapshot and unpack them into Egg Objects, then return egg via callbacks FbDatabaseWrite Write egg with given parameter to databse, return whether the write is successful via Callbacks FbStoragePresenter Abstraction for storage logics FbStorageWrite Write Egg pictures FbStorageRead It is a joke, not yet used

By the way, this is my first app adopting MVP, there are lots of mistakes, feel free to correct them. I used MVC before. CallBack Technically part of Presenter, Callbacks execute tasks demanded by presenter Asynchronously upon the finish of some other task: for example, when finished image recognition, and upon results recieved, onAzureSuccess is called to return the data. Why do we want to execute data asynchronously? In short, because we dont want to execute time consuming tasks such as loading downloading on UI(Main) Thread. If we do the screen will freeze and not refresh. But what is executed on the main thread? Any small, instant action received directly from UI. Another Great Tutorial by http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html CallBacks Purpose MainActivity Display Catalogue of eggs ->Calls database reference via DbDatabaseReader (this is a presenter) ->Receives list of eggs from presenter ->populate the list via the adaptor DetailedActivity Display information of a single egg FacebookLogin Activity Enable user to login CameraActivity Well, facilitate Camera usage, send taken picture back to Main

Clone this wiki locally