diff --git a/app/src/main/java/io/github/chronosx88/influence/contracts/observer/Observable.java b/app/src/main/java/io/github/chronosx88/influence/contracts/observer/Observable.java index 85fe33a..142009e 100644 --- a/app/src/main/java/io/github/chronosx88/influence/contracts/observer/Observable.java +++ b/app/src/main/java/io/github/chronosx88/influence/contracts/observer/Observable.java @@ -3,7 +3,7 @@ package io.github.chronosx88.influence.contracts.observer; import org.json.JSONObject; public interface Observable { - void register(Observer observer); - void unregister(Observer observer); - void notifyObservers(JSONObject jsonObject); + void register(Observer observer, int channelID); + void unregister(Observer observer, int channelID); + void notifyObservers(JSONObject jsonObject, int channelID); } diff --git a/app/src/main/java/io/github/chronosx88/influence/observable/MainObservable.java b/app/src/main/java/io/github/chronosx88/influence/observable/MainObservable.java index 8135c59..025a221 100644 --- a/app/src/main/java/io/github/chronosx88/influence/observable/MainObservable.java +++ b/app/src/main/java/io/github/chronosx88/influence/observable/MainObservable.java @@ -8,26 +8,74 @@ import io.github.chronosx88.influence.contracts.observer.Observable; import io.github.chronosx88.influence.contracts.observer.Observer; public class MainObservable implements Observable { - private ArrayList observers; + public static final int UI_ACTIONS_CHANNEL = 0; + public static final int OTHER_ACTIONS_CHANNEL = 1; + + private ArrayList uiObservers; + private ArrayList otherObservers; public MainObservable() { - this.observers = new ArrayList<>(); + this.uiObservers = new ArrayList<>(); + this.otherObservers = new ArrayList<>(); } @Override - public void register(Observer observer) { - observers.add(observer); + public void register(Observer observer, int channelID) { + switch (channelID) { + case UI_ACTIONS_CHANNEL: { + uiObservers.add(observer); + break; + } + + case OTHER_ACTIONS_CHANNEL: { + otherObservers.add(observer); + break; + } + + default: { + otherObservers.add(observer); + break; + } + } } @Override - public void unregister(Observer observer) { - observers.remove(observer); + public void unregister(Observer observer, int channelID) { + switch (channelID) { + case UI_ACTIONS_CHANNEL: { + uiObservers.remove(observer); + break; + } + + case OTHER_ACTIONS_CHANNEL: { + otherObservers.remove(observer); + break; + } + } } @Override - public void notifyObservers(JSONObject jsonObject) { - for (Observer observer : observers) { - observer.handleEvent(jsonObject); + public void notifyObservers(JSONObject jsonObject, int channelID) { + switch (channelID) { + case UI_ACTIONS_CHANNEL: { + for (Observer observer : uiObservers) { + observer.handleEvent(jsonObject); + } + break; + } + + case OTHER_ACTIONS_CHANNEL: { + for (Observer observer : otherObservers) { + observer.handleEvent(jsonObject); + } + break; + } + default: { + for (Observer observer : otherObservers) { + observer.handleEvent(jsonObject); + } + break; + } } } }