Giter Club home page Giter Club logo

indefinite-observable-android's Introduction

Indefinite Observable for Android

Build Status codecov Release Docs

The Indefinite Observable for Android repo.

Learn more about the APIs defined in the library by reading our technical documentation and our Starmap.

Installation

Installation with Jitpack

Add the Jitpack repository to your project's build.gradle:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Depend on the latest version of the library. Take care to occasionally check for updates.

dependencies {
    compile 'com.github.material-motion:indefinite-observable-android:2.0.0'
}

For more information regarding versioning, see:

Using the files from a folder local to the machine

You can have a copy of this library with local changes and test it in tandem with its client project. To add a local dependency on this library, add this library's identifier to your project's local.dependencies:

com.github.material-motion:indefinite-observable-android

Because local.dependencies is never to be checked into Version Control Systems, you must also ensure that any local dependencies are also defined in build.gradle as explained in the previous section.

Important

For each local dependency listed, you must run gradle install from its project root every time you make a change to it. That command will publish your latest changes to the local maven repository. If your local dependencies have local dependencies of their own, you must gradle install them as well.

You must gradle clean your project every time you add or remove a local dependency.

Usage

How to use the library in your project.

Editing the library in Android Studio

Open Android Studio, choose File > New > Import, choose the root build.gradle file.

Example apps/unit tests

To build the sample application, run the following commands:

git clone https://github.com/material-motion/indefinite-observable-android.git
cd indefinite-observable-android
gradle installDebug

To run all unit tests, run the following commands:

git clone https://github.com/material-motion/indefinite-observable-android.git
cd indefinite-observable-android
gradle test

Guides

  1. How to create a synchronous stream
  2. How to create an asynchronous stream using callbacks
  3. How to subscribe to a stream
  4. How to unsubscribe from a stream
  5. How to create an synchronous stream using objects
  6. How to make a custom observable

How to create a synchronous stream

IndefiniteObservable<Observer<Integer>> observable = new IndefiniteObservable<>(
  new Connector<Observer<Integer>>() {
    @Nullable
    @Override
    public Disconnector connect(Observer<Integer> observer) {
      observer.next(5);
      return null;
    }
  });
}

How to create an asynchronous stream using callbacks

If you have an API that provides a callback-based mechanism for registering listeners then you can create an asynchronous stream like so:

IndefiniteObservable<Observer<Integer>> observable = new IndefiniteObservable<>(
  new Connector<Observer<Integer>>() {
   public Disconnector connect(Observer<Integer> observer) {
     final SomeToken token = registerSomeCallback(new SomeCallback() {
       public void onCallbackValue(Integer value) {
         observer.next(value);
       }
     });

     return new Disconnector() {
       public void disconnect() {
         unregisterSomeCallback(token);
       }
     };
   }
  });

How to subscribe to a stream

Subscription subscription = observable.subscribe(new Observer<Integer>() {
  public void next(Integer value) {
   Log.d(TAG, "Received value: " + value);
  }
});

How to unsubscribe from a stream

subscription.unsubscribe();

How to make a custom observable

To create an observable that supports custom channels, extend Observer and IndefiniteObservable.

public abstract class CustomObserver<T> extends Observer<T> {
  public abstract void next(T value);
  public abstract void customChannel(Foobar value);
}

public class CustomObservable<T> extends IndefiniteObservable<CustomObserver<T>> {
  public CustomObservable(Connector<CustomObserver<T>> connector) {
    super(connector);
  }
}

Contributing

We welcome contributions!

Check out our upcoming milestones.

Learn more about our team, our community, and our contributor essentials.

License

Licensed under the Apache 2.0 license. See LICENSE for details.

indefinite-observable-android's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

indefinite-observable-android's Issues

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.