Git Product home page Git Product logo

realm-sync-android's Introduction

realm-sync-android

Realm-sync simplifies data retrieval from any REST API and caches it to local realm.io database on android devices.Built on top of loaders which was introduced in Android 3.0 and volley for transmitting Network Data.

Realm sync provides the following

  1. Seamless network calls - provides interfaces to make network calls with very little code.
  2. Serialisation - serailizes json data into respective realm models and returns a list of realm objects.
  3. Orientation changes - preserves state on orientation changes on an android device.
  4. Offline caching.
  5. All done under the hood with very little code and configuration.

Use

To start off create a realm-sync object as follows

new RealmSync(MainActivity.this,
                          USER_OBJECT, 
                          END_POINT,   
                          REQUEST METHOD,
                          JSON_OBJECT); 

Use a loader to add your callbaks to your activity or fragment

public LoaderManager.LoaderCallbacks<List<RealmObject>> loaderCallbacks =
          new LoaderManager.LoaderCallbacks<List<RealmObject>>() {

              public Loader<List<RealmObject>> onCreateLoader(int id, Bundle args) {
                  return new RealmSync(
                          MainActivity.this,
                          realmUser,
                          EndpointsEnum.Endpoints.OPEN_WEATHER,
                          Request.Method.GET, 
                          null);
              }

              @Override
              public void onLoadFinished(Loader<List<RealmObject>> loader,
                                         List<RealmObject> data) {
                  if (data.size() == 0) {
                      listViewAdapter.swapData(Collections.<RealmObject>emptyList());
                      Toast.makeText(MainActivity.this, getResources().getString(R.string.refresh_error), Toast.LENGTH_LONG).show();
                  } else {
                      listViewAdapter.swapData(data);
                  }
                  swipeContainer.setRefreshing(false);
              }

              @Override
              @SuppressWarnings("all")
              public void onLoaderReset(Loader<List<RealmObject>> loader) {
                  loader = null;
              }
          };
          

realm-sync-android's People

Contributors

tejasna avatar

Watchers

James Cloos avatar Facu Echenique 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.