OpenWeatherMap demo

This app is a demo Android app of OpenWeatherMap API with only one feature implemented: to display 7-days weather forecast of a place.

Build and run

To build and run the app, please make sure your OpenWeatherMap API key is properly setup in ./app/build.gradle

buildConfigField("String", "OpenWeatherMapApiKey", "\"${System.getenv("OPEN_WEATHER_MAP_API_KEY")}\"")

There are 2 ways do put your API key there:

  • Set an environment variable named OPEN_WEATHER_MAP_API_KEY
  • Replace ${System.getenv("OPEN_WEATHER_MAP_API_KEY")} part with your API key

A prebuilt APK can be downloaded here:

Download prebuilt APK here

Architecture

This app is easy to be extended and it can be a foundation for future development. Several techniques and frameworks are applied: MVVM, Clean architecture, dependency injection, expandable error handling,… Its stack is implemented with following libraries and frameworks:

  • Kotlin coroutines
  • Jetpack LiveData
  • Koin
  • Retrofit with Moshi for JSON parsing
  • DataState

The app is split into 3 layers with Clean Architecture in mind:

  • Presentation
  • Domain
  • Data

Domain is the core layer, which works with Business logic. Domain shouldn’t depend on Android frameworks.

Presentation works with UI elements. It also handles user interaction and screen navigation.

Data collects data from network API and database (not yet implemented).

Both Presentation and Data depend on Domain .

App structure

Domain layer contains business logic related classes. UseCase and Repo interface should be defined here.

Each UseCase implement a single business logic UseCase.

Repo classes provide required data retrieved from Data domain. Repo classses are implemented on Data layer and injected with Dependency Injection into UseCase.

Data flow

Data is parsed from REST API and/or Database and converted into data entities. Most of the entites are POJOs. The data is mapped into Domain layer with DataMappers. API exceptions are also converted into BaseError, which are Business exception.

Domain data is already formatted and standardized in to busines classes. Depending on Business requirements, an exception can be treated as an Error or a valuable information.

Meaningful data is mapped into UI elements without redundant information. Each error requires different handling. UiErrorMapper can map those errors into UiError that can be presented to users. We can use different error mappers for each UseCase because there are many ways to display an error to users depending on business requirements. Please check OpenWeatherUiErrorMapper for its usage.

GitHub

View Github