Coder Social home page Coder Social logo

jshvarts / offlinesampleapp Goto Github PK

View Code? Open in Web Editor NEW
656.0 25.0 143.0 881 KB

Sample Offline-First MVVM app that uses Android Priority Job Queue, Room, Retrofit2, LiveData, LifecycleObserver, RxJava2, Dagger Android

Home Page: https://proandroiddev.com/offline-apps-its-easier-than-you-think-9ff97701a73f

License: Apache License 2.0

Java 100.00%
offline-first offline-app rxjava2 rxandroid livedata clean-architecture mvvm mvvm-architecture room retrofit2

offlinesampleapp's Introduction

Offline Sample App

Build Status Android Weekly

Medium post covering this app: Building Offline-First App using MVVM, RxJava, Room and Priority Job Queue

What is an Offline App?

Offline App (or Offline-First App) enables user to seamlessly interact with it by using local device storage and then synchronizing the data with some remote storage (cloud database, etc) later via a background process.

With offline apps

  1. users no longer get error messages due to network connection problems.
  2. users benefit from faster loading times and conserving battery life.
  3. users do not see any loading bar since their actions are performed against fast local storage.

App Overview

Comments Screen

This app is a working sample that showcases one way of implementing offline commenting capability on Android platform. Users' comments are stored in local Room database first. Then a background job is spawned to synchronize local data with remote database if and when Internet connection is available.

This background job is designed to be persistent--it is guaranteed to execute even after app or device restarts while waiting for the network connection.

Libraries Used

  • Patterns and frameworks
    • MVVM (Model-View-ViewModel) using Google's new Architecture components ViewModel, LiveData, LifecycleObserver, etc.
    • Clean Architecture with ViewModel interacting with UseCases and the latter interacting with local database. Making each layer highly testable.
  • Database
  • Background Job processing
  • Remote Call APIs
  • Dependency Injection
  • Communication between app layers
    • RxJava2 and RxAndroid for interacting between ViewModel and local database.
    • RxRelay for publishing requests from the background job so that lifecycle observer components can update local database.
  • Other
    • ButterKnife to simplify View and Listener bindings.
    • Travis CI is used for automating continuous integration.
    • The following quality checks are configured: checkstyle, pmd, findbugs, lint and RxLint. You can perform all of them at once by executing ./gradlew check

Branches

  • master - comment sync response is observed and local database is updated by LifecycleObserver. For this to work, the app has to be in foreground.
  • sync-in-background - comment sync response is observed and local database is updated by the background thread whenever connection is available. For this to work, the app does not need to be in foreground.

License

Copyright 2017 James Shvarts

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.

offlinesampleapp's People

Contributors

friederbluemle avatar jshvarts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

offlinesampleapp's Issues

Error in running android 4.4 avd, You must create a service that extends GsmJobSchedulerService,

Hi,

I tried running sample app in android 4.4 and got an error

java.lang.RuntimeException: Unable to create application com.ikhan.test.App: java.lang.IllegalArgumentException: You must create a service that extends GcmJobSchedulerService at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalArgumentException: You must create a service that extends GcmJobSchedulerService at com.birbit.android.jobqueue.scheduling.GcmJobSchedulerService.createSchedulerFor(GcmJobSchedulerService.java:28) at com.ikhan.test.domain.services.jobs.JobManagerFactory.configureJobManager(JobManagerFactory.java:72) at com.ikhan.test.domain.services.jobs.JobManagerFactory.getJobManager(JobManagerFactory.java:26) at com.ikhan.test.App.onCreate(App.java:34) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344) at android.app.ActivityThread.access$1500(ActivityThread.java:135)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5017)  at java.lang.reflect.Method.invokeNative(Native Method) 

missing class

It looks like com.example.offline.di.DaggerAppComponent; is missing

How to use this example?

I tried running your code and I get 500 error? Do I need to do anything with jsonplaceholder.typicode.com such as setting up a server before I can run code on the GitHub?

MVVM?

It seems that the sample is using MVP rather than MVVM.

Enabling sync to remote db for data updates

Hi,

I tried to implement the update method using the same way as the add method, to enable sync to remote db.
However, I realised there will be an infinite loop on the model_view class, which keeps trigger an update to the remote db using the original data.
May I know how this should be done? I am pretty new to RxJava.

  Thanks for your time.

RK

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.