Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.

Commit 079c346

Browse files
author
Mark Wei
committed
Implement inline properties for android.
Summary: Fixes material-motion/material-motion#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
1 parent 1475da3 commit 079c346

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

library/src/main/java/com/google/android/material/motion/streams/MotionObservable.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ public static abstract class Predicate<T> {
122122
public abstract boolean evaluate(T value);
123123
}
124124

125+
/**
126+
* An inline property that can be read into a MotionObservable stream.
127+
*/
128+
public static abstract class InlineReadable<T> {
129+
130+
/**
131+
* Reads the property's value.
132+
*/
133+
public abstract T read();
134+
}
135+
136+
/**
137+
* An inline property that can be written from a MotionObservable stream.
138+
*/
139+
public static abstract class InlineWritable<T> {
140+
141+
/**
142+
* Writes the property with the given value.
143+
*/
144+
public abstract void write(T value);
145+
}
146+
125147
/**
126148
* A light-weight operator builder.
127149
* <p>
@@ -194,7 +216,7 @@ public void next(MotionObserver<T> observer, T value) {
194216
}
195217

196218
/**
197-
* Writes the values from an Observable onto the given target and property.
219+
* Writes the values from an Observable onto the given unscoped property.
198220
*
199221
* @see <a href="https://material-motion.github.io/material-motion/starmap/specifications/streams/operators/$.write">The
200222
* write() specification</a>
@@ -208,4 +230,20 @@ public void next(MotionObserver<T> observer, T value) {
208230
}
209231
});
210232
}
233+
234+
/**
235+
* Writes the values from an Observable onto the given inline property.
236+
*
237+
* @see <a href="https://material-motion.github.io/material-motion/starmap/specifications/streams/operators/$.write">The
238+
* write() specification</a>
239+
*/
240+
public <O> MotionObservable<T> write(final InlineWritable<T> property) {
241+
return operator(new Operation<T, T>() {
242+
@Override
243+
public void next(MotionObserver<T> observer, T value) {
244+
property.write(value);
245+
observer.next(value);
246+
}
247+
});
248+
}
211249
}

0 commit comments

Comments
 (0)