From 079c346c915111b10a5d683f169b3fa4ecf467a9 Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Thu, 8 Dec 2016 02:47:04 -0800 Subject: [PATCH] Implement inline properties for android. Summary: Fixes https://github.com/material-motion/material-motion/issues/31 Reviewers: O2 Material Motion!, miguelandres, O6 Material Motion Android platform reviewers, #material_motion Reviewed By: miguelandres, O6 Material Motion Android platform reviewers Subscribers: featherless Tags: #material_motion Differential Revision: http://codereview.cc/D2171 --- .../motion/streams/MotionObservable.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/google/android/material/motion/streams/MotionObservable.java b/library/src/main/java/com/google/android/material/motion/streams/MotionObservable.java index ee06c98..97ec63d 100644 --- a/library/src/main/java/com/google/android/material/motion/streams/MotionObservable.java +++ b/library/src/main/java/com/google/android/material/motion/streams/MotionObservable.java @@ -122,6 +122,28 @@ public static abstract class Predicate { public abstract boolean evaluate(T value); } + /** + * An inline property that can be read into a MotionObservable stream. + */ + public static abstract class InlineReadable { + + /** + * Reads the property's value. + */ + public abstract T read(); + } + + /** + * An inline property that can be written from a MotionObservable stream. + */ + public static abstract class InlineWritable { + + /** + * Writes the property with the given value. + */ + public abstract void write(T value); + } + /** * A light-weight operator builder. *

@@ -194,7 +216,7 @@ public void next(MotionObserver observer, T value) { } /** - * Writes the values from an Observable onto the given target and property. + * Writes the values from an Observable onto the given unscoped property. * * @see The * write() specification @@ -208,4 +230,20 @@ public void next(MotionObserver observer, T value) { } }); } + + /** + * Writes the values from an Observable onto the given inline property. + * + * @see The + * write() specification + */ + public MotionObservable write(final InlineWritable property) { + return operator(new Operation() { + @Override + public void next(MotionObserver observer, T value) { + property.write(value); + observer.next(value); + } + }); + } }