Giter Club home page Giter Club logo

zigeorge / offline-first-android-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 810 KB

A currency converter app using open exchange API(free). This app is developed with kotlin and jetpack compose. And it demonstrate a basic workaround for an offline first application following modern android app architecture

License: Apache License 2.0

Kotlin 100.00%
android-architecture coroutines-flow coroutines-retrofit hilt-android kotlin-android mvvm-android repository-pattern retrofit room unit-testing

offline-first-android-demo's Introduction

Currency conversion app

A currency converter app that allows a user to view a given amount in a given currency converted into other currencies

Description

This is a single page app with a topbar containing title, a textfield to enter amount, a dropdown to select a currency and a grid view to show all other currencies

Technologies used

Android Studio Electric Eel | 2022.1.1 Patch 2 Current Desktop: ubuntu:GNOME

Android versions

The minimum Android SDK version is 24 The compile SDK version is 33 The target SDK version is 33

It uses the following libraries

  • Jetbrains Kotlin Android 1.8.0
  • Jetpack compose 1.4.0
  • coroutines 1.3.9
  • lifecycle 2.6.0-alpha01
  • room 2.4.3
  • retrofit 2.9.0
  • dagger-hilt 2.44
  • turbine 0.9.0
  • Google Truth 1.1.3
  • kotlinx-coroutines-test 1.6.4
  • Junit 4.12
  • core_testing_version 2.1.0

Build

extract the zip file and open using Android studio make sure the Android versions and configurations are the same

Disclaimer

I've used kotlin to write this application as it provides an easy and simpler syntax than Java. Besides that kotlin provides support for coroutines which makes it very easy to write android lifecycle aware processes.

  • Jetpack Compose - Jetpack compose enables declarative UI which provide control structures developers can use to manipulate the drawing of the UI. Its easy and take less time than Android xml view.
  • Coroutine - Kotlin's coroutine enables asynchronous and non blocking programming. Coroutines are aware of lifecycle so there's no chance of threads processing out of contexts. Coroutines suspend functions makes it looks like I'm writing a synchronous program hence, the classes looks cleaner. Live data and Flow helps implementing the observer pattern, which I could've done using Rx. At first I used Rx with retrofit and room but the code at viewModel looked clumsier. So I've decided to migrate to coroutine and livedata.
  • Retrofit - Retrofit makes it is easy to manipulate and maintain a clean architecture and it enables network calling with a very minimum amount of codes. It also supports implementation with coroutines and liveData.
  • Room - The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. It also work with coroutines and helps maintaining the clean architecture.
  • Hilt - Dagger-hilt enables dependency inversion one of the 5 principles of SOLID. It helped me separate my business logics from repository, dao and API layer. It enhances the scalability of the project so that in future if want to implement a different UI I'd merely have to make any change in the technical part of this project.

Testing

  • FunctionsTest - this test class was written to test functions in Functions.kt file under other package
  • CurrencyDaoTest - contains test cases for CurrencyDao.kt class of db package
  • CurrencyConverterHomeViewModelTest - contains all test cases for all the functions and flows of CurrencyConverterViewModel

Conclusion

I have tried to use the latest tools of Android SDK hence, I've used Jetpack compose for UI design and Dagger-Hilt for dependency injection. To inherit android app architectural guidelines I tried to briefly divide the app in 3 different layers. In the ui layer there are composable, theme and viewModels where UI elements and UI states are in composable files, viewModels are working as UI holder, theme defines colors and resources In the data layer there are db containing database, entity and dao object, network containing retrofit instance and api interfaces, repository containing the feature repository. In the domain layer I kept the connectivity observer.

offline-first-android-demo's People

Contributors

george3159 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.