Giter Club home page Giter Club logo

canarytest's Introduction

android-mvvm

Demo Android app that consume https://api.weatherapi.com

This demo use Free plan, which support only 3 forecast days For more detail about the api: https://www.weatherapi.com/

The app have two screens:

  • A first screen to present a viewpager2 with 3 pages.
  • A second screen presenting forecast day details.

The first time app request permissions for get the location of user, after that the app get data from API and store the result in one internal DB

if the app doesn't have access to internet, the data will be get from internal DB.

This app works in offline using the data from internalDB.

It has been built with clean architecture principles, Repository Pattern and MVVM pattern as well as Architecture Components.

Min Api Level : 24 (https://developer.android.com/about/dashboards)

Build System : Gradle

Table of Contents

Architecture

The Application is split into a three layer architecture:

  • Presentation
  • Domain
  • Data

Architecture Flow Diagram

The 3 layered architectural approach is majorly guided by clean architecture which provides a clear separation of concerns with its Abstraction Principle.

Koin is used for dependency injection.

Presentation

app contains the UI files and handles binding of DI components from other modules. Binding of data is facilitated by jetpacks data binding by serving data from the viewmodel to the UI.The data being received is part of a viewstate class that has properties contained in the relevant state.

Domain

The domain module contains domain model classes which represent the data we will be handling across presentation and data layer.

Use cases are also provided in the domain layer and orchestrate the flow of data from the data layer onto the presentation layer and a split into modular pieces serving one particular purpose.

The UseCases use a BaseUseCase interface that defines the parameters its taking in and output this helps in creating fakes using in testing.

Data

  • data

Handles data interacting with the network and is later serverd up to the presentation layer through domain object

Handles persistence of object with Room ORM from.This module is responsible for handling all local related logic and serves up data to and from the presentation layer through domain objects.

Testing

Types of Test:

  • Unit test
  • UI Test (Espresso)

Each module has its own tests(Unit Test) except for the domain module which is catered for since its part of the behavior under test.

All server responses in the tests are served by mock web server by appending relative urls to the localhost and the connected port as the base url.

In the data module the responses are mocked using the mockwebserver and verified that they are what we expect. And in this module an memory database is being used to run the tests,this makes it a little faster compared to an actual db. In this module the repositories are been tested.

In the app module there are:

  • Unit tests for the Viewmodels
  • UI tests for the UI Screens.

The test instrumentation app uses modules that have been swaped(using Koin) with fakes for:

  • The network module so as to run requests on localhost with mockwebserver, this removes flakiness compared to relying on actual data from the real server aspects such as internet connection or network service might bring up issues
  • An in memory database for local data that also allows main thread queries since tests should also be fast and we are just asserting stuff works.

View models testing on live data were guided by this article

Libraries

Libraries used in the whole application are:

  • Jetpack๐Ÿš€
    • Viewmodel - Manage UI related data in a lifecycle conscious way and act as a channel between use cases and ui
    • Data Binding - support library that allows binding of UI components in layouts to data sources,binds character details and search results to UI
    • Room - Provides abstraction layer over SQLite
  • Retrofit - type safe http client and supports coroutines out of the box.
  • Moshi - JSON Parser,used to parse requests on the data layer for Entities and understands Kotlin non-nullable and default parameters
  • okhttp-logging-interceptor - logs HTTP request and response data.
  • kotlinx.coroutines - Library Support for coroutines,provides runBlocking coroutine builder used in tests
  • Truth - Assertions Library,provides readability as far as assertions are concerned
  • MockWebServer - web server for testing HTTP clients ,verify requests and responses on the star wars api with the retrofit client.
  • Leak Canary - Leak Detection Library
  • Material Design - build awesome beautiful UIs.๐Ÿ”ฅ๐Ÿ”ฅ
  • Firebase - Backend As A Service for faster mobile development.
    • Crashylitics - Provide Realtime crash reports from users end.
  • Koin - A pragmatic lightweight dependency injection framework for Kotlin
  • Robolectric - Unit test on android framework.
  • Espresso - Test framework to write UI Tests
  • recyclerview-animators - Recycler View Animations
  • AboutLibraries -provide info on used open source libraries.
  • Stetho - debug bridge
  • Kiel - Kiel RecyclerView Adapter Builders

Demo

||||

License

  Copyright 2022 Cesar Sosa
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

canarytest's People

Contributors

cdavidsp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.