Skip to content

A PRIVATE PROJECT in KOTLIN - Traffic@NSW displays the most important information from the livetraffic.com web site in a form easily digested on a mobile device.

Notifications You must be signed in to change notification settings

replicant1/TrafficAtNSW

Repository files navigation

Traffic@NSW

Monday 31 Jul 7 2017

An Android application that captures a subset of the information presented on the https://livetraffic.com web site but in a form more easily digested on a mobile device.

This is the very first Android app I ever wrote, which I have converted from Java to Kotlin as a learning exercise.

Libraries

The app makes use of these libraries:

  • Android Annotations - I mainly use these annotations:
    • @EActivity
    • @EFragment
    • @ViewById
    • @AfterViews
    • @FragmentArg
    • @Extra
    • @OptionsMenu
    • @OptionsItem
  • Dagger - Dependency injection, switching between test and real implementations of IDataService
  • GSON - For parsing of JSON data files
  • RxJava - For asynchronous loading of data
  • Timber - For logging

Design

IView and IPresenter interfaces

IView and IPresenter Class Diagram

The two fundamental interfaces in the app are IView and IPresenter, which represent the View and Presenter parties in the classic MVP pattern. The IView is just a tag interface implemented by Fragments and Activities that are views. The IPresenter is generally injected into the IView implementation. It attaches itself to the IPresenter and detaches itself from the IPresenter at the appropriate times in its Android lifecycle. Typically the onResume and onPause lifecycle methods are the appropriate places to attach and detach the View from the Presenter.

Hazards List screen

Hazards View and Presenter Class Diagram

The following shows IView and IPresenter implementations for the Hazards screens. Both the "Sydney Incidents" and "Regional Incidents" screens use the same Presenter and View classes, just with different IHazardFilter implementations applied.

IDataService

IDataService

All domain data is retrieved via the IDataService interface. In production, the RemoteDataService implementation is used, but for testing the TestDataService implementation is provided by Dagger instead. This is achieved by having different Dagger modules defined for each implementation.

Refresh Hazards

Refresh Hazards Collaboration Diagram

  1. HazardsListFragment tells its Presenter to load Hazards from the Data Service
  2. HazardsOverviewPresenter constructs a DownloadHazardsCommand to perform the download asynchronously
  3. HazardsOverviewPresenter constructs a DownloadSuccessHandler to receive the hazards when they are later returned
  4. HazardsOverviewPresenter passes the DownloadHazardsCommand and the SuccesHandler to the CommandEngine for asynchronous execution.
  5. The CommandEngine executes the DownloadHazardsCommand asynchronously
  6. The RemoteDataService gets the incident.json file from the remote web server and...
  7. ... returns them to the DownloadSuccessHandler for parsing into data objects.
  8. The resulting List of Hazards is stored away in the HazardCacheSingleton for future reference
  9. The DownloadSuccessHandler, via the HazardOverviewPresenter, tells the view (HazardListFragment) to refresh its display of Hazards because new hazard data is now available in the HazardCacheSingleton
  10. The HazardListFragment constructs a new HazardListAdapter which interrogates the HazardCacheSingleton for its new data which is then used to populate the Hazards List on the screen.

Screenshots

Navigation

Navigation Drawer

The Navigation drawer slides out from left of top level screens.

Incidents List

Hazard List

A list of Hazards (Incidents) in Regional NSW, grouped by RMS Region.

Hazard Details

Hazard Details

Details screen for an individual Incident.

Hazard Map

Map

Clicking the Location icon on the Hazards Detail screen shows the GPS location of the Incident.

Traffic Cameras

Camera List

List of traffic cameras in the Sydney area, grouped by RMS Region.

Traffic Camera Image

Camera Image

Image from an individual traffic camera. Images update on the server every minute. The star action toggles the inclusion of this camera in the "Favourite Cameras" set.

Travel Times

Travel Times

Travel Times on the M1 Motorway. Touching individual rows toggles the rows' travel time in and out of the total travel time for a given direction of travel on the Motorway.

About

A PRIVATE PROJECT in KOTLIN - Traffic@NSW displays the most important information from the livetraffic.com web site in a form easily digested on a mobile device.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published