reference_project_structure_sample_project - NibiruOS/mobile GitHub Wiki

Sample project

A sample application can be found in the ar.com.oxen.nibiru.mobile.sample.app project. It can be found at sample directory, along with different platform implementations.

Typical project structure

Typically, a project will be divided into two or more modules:

  • A module containing app-specific components, which are generic and re-usable.
  • One or more modules containing platform-specific components.

These modules are explained in the following sections. For a deeper undestanding, please look at the sample application.

Application module

The application module usually will depend on ar.com.oxen.nibiru.mobile.core module, in order to access the platform-agnostic API. In a typical application, this module will contain:

  • An ar.com.oxen.nibiru.mobile.core.api.app.EntryPoint implementation, for application startup logic.
  • UI logic:
    • All the presenters.
    • A enumeration for custom places.
    • A presenter mapper, for mapping places with presentes.
  • Text internationalization resources (properties and an interface).
  • Business logic components (which may be divide into API and implementation).
  • Data access API (DAOs and domain model).
  • Remote services API.

Some packaging issues must be taken into account:

  • In order to compile from GWT, you must include:
    • A Module.gwt.xml file, with proper configuraiton for source paths.
    • Java source files.

Platform modules

Platform specific modules will depend on application module and on Nibiru Mobile platform-specific module. Such modules typically will inlcude:

  • Classes for configuring dependency injection.
  • View components, in order to implement presenter displays.
  • Any platform-specific file or class required for proper application operation.

Android

Android modules will depend on application module and on ar.com.oxen.nibiru.mobile.android module. Android specific components can be set up as follows:

  • In the AndroidManifest.xml file declare the ar.com.oxen.nibiru.mobile.android.app.BootstrapActivity as launcher. For each presenter, you must declare a ar.com.oxen.nibiru.mobile.android.ui.mvp.PresenterActivity. The action name must match {app package name}.place.{place name}.
  • Dependency injection is configured using Guice, so you must just write a com.google.inject.AbstractModule subclass for each module. Since RoboGuice is the framework which startups Guice, you must declare a string array resource called roboguice_modules, which indicates what modules must be used (check the roboguice.xml file in the sample).
  • The ar.com.oxen.nibiru.mobile.android.ui.mvp.BaseAndroidView class can be used as the super class for all the view implementations.
  • Persistence is managed using OrmLite, so you must create a com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper subclass for database creation, upgrade, etc.
  • Jackson JSON serialization is configured using an org.codehaus.jackson.map.ObjectMapper instance. If you need yo customize serialization, you can write a javax.inject.Provider<ObjectMapper> for this class.

GWT

GWT modules have more options on the UI layer. Usually, you will choose an UI implementation for your application (however, since they are HTML-based, you can mix UI technologies.

The following modules are provided for different UI technologies support:

  • ar.com.oxen.nibiru.mobile.gwt: For generic GWT components and cross technologies (such as GWT-PhoneGap, GWT-Mobile-Persistence, etc.).
  • ar.com.oxen.nibiru.mobile.mgwt: MGWT user interface implementation.

Regarding platform-specific components, you will typically need:

  • A Module.gwt.xml inhetinting the application module and the platform specific modules.
  • A com.google.gwt.core.client.EntryPoint in order to startup the GWT application. This will typically just call the Nibiru Mobile bootstrap.
  • Dependency injection is done through GIN. Because of this, you must create a ar.com.oxen.nibiru.mobile.gwt.ioc.GwtInjector subinterface and a com.google.gwt.inject.client.AbstractGinModule sublcass for each module.
  • An interface extending both, application message internationalization interface and com.google.gwt.i18n.client.Messages. This way, GWT knows that it must be treated as an i18n interface. Also, you must declare the used languages in the Module.gwt.xml file.