Skip to content

MVC in Android Client

Ka-Ping Yee edited this page Jun 27, 2019 · 3 revisions
2019 status: Current

Summary

The Buendia client is (roughly) modeled around the MVC pattern. This document describes how the client architecture conforms to this pattern.

Model

The model is split into two pieces--the server data model and the client data model, as the server's representation of data differs in some ways from the client model.

The server data model is represented by simple beans in the <base>/net/model package.

The client data model is represented by classes in the /data/app package and described in detail here.

View

The view is provided by fragments and activities in the /ui package. Each view should, ideally, define and update UI elements.

Views inherit from a few common base classes:

  • BaseActivity acts as the basis for all activities, providing a status update and troubleshooting mechanism.
  • BaseLoggedInActivity, which extends BaseActivity, acts as the basis for most activities, adding a logged-in user and logout/settings menu to the action bar, as well as basic state tracking (LOADING, SYNCING, LOADED).
  • ProgressFragment, which is used in most activities, displays a progress bar/spinner or content based on its state (LOADING, ERROR, LOADED).
  • PatientSearchActivity, which is the basis for many activities, adds Search and Add Patient buttons. Controller

Each activity is controlled primarily by one or more controllers. The controller(s) are responsible for:

  • Listening for events on one or more EventBus and/or CrudEventBus objects, which provide a publisher/subscriber interface for various events
  • Performing CRUD operations on any application data
  • Changing the state of a ProgressFragment or BaseLoggedInActivity
  • Making network requests

Most controllers should also provide methods for requesting and releasing resources, including database handles, cursors, etc. These methods should also register and unregister from EventBus and CrudEventBus objects, as necessary. Currently, all controllers have init() and suspend() methods for this purpose, which are called when the view is paused or resumed, respectively. There is no base interface asserting that these methods must exist, however.

Clone this wiki locally