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

Implement MotionRuntime.interactions() API #75

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class MotionRuntime {

private final List<Subscription> subscriptions = new ArrayList<>();
private final SimpleArrayMap<View, ReactiveView> cachedReactiveViews = new SimpleArrayMap<>();
private final SimpleArrayMap<Object, List<Interaction>> cachedInteractions = new SimpleArrayMap<>();

/**
* Subscribes to the stream, writes its output to the given property, and observes its state.
Expand Down Expand Up @@ -62,6 +63,13 @@ public final <O, T> void addInteraction(
public final <O, T> void addInteraction(
Interaction<O, T> interaction, O target, ConstraintApplicator<T> constraints) {
interaction.apply(this, target, constraints);
List<Interaction> interactions = cachedInteractions.get(target);
if (interactions == null) {
interactions = new ArrayList<>();
cachedInteractions.put(target, interactions);
}

interactions.add(interaction);
}

/**
Expand All @@ -76,4 +84,15 @@ public ReactiveView get(View view) {

return reactiveView;
}

public <I extends Interaction> List<I> interactions(View view, Class<I> klass) {
List<Interaction> interactions = cachedInteractions.get(view);
List<I> filteredInteractions = new ArrayList<>();

for (Interaction i: interactions) {
if(klass.isInstance(i))
filteredInteractions.add((I)i);
}
return filteredInteractions;
}
}