Skip to content

Commit

Permalink
Remove event buses (That was unnecessary)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Dec 22, 2013
1 parent ef516d0 commit aefb3ac
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/main/java/org/kt3k/straw/Straw.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import android.webkit.WebView;

import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;

public class Straw {

private final WebView webView;
private final JsToNativeInterface jsInterface;
private final StrawPluginRegistry registry;
private Bus backKeyBus;


public static final String JS_TO_NATIVE_INTERFACE_NAME = "JS_TO_NATIVE_INTERFACE";
Expand All @@ -24,8 +20,6 @@ public Straw(WebView webView) {
this.jsInterface = new JsToNativeInterfaceImpl(this);

this.setUpJsInterface();

this.initEventBuses();
}

public StrawPluginRegistry getRegistry() {
Expand Down Expand Up @@ -64,21 +58,11 @@ private void setUpJsInterface() {
this.webView.addJavascriptInterface(this.jsInterface, JS_TO_NATIVE_INTERFACE_NAME);
}

/**
* initialize event buses
*/
private void initEventBuses() {
this.backKeyBus = new Bus();

this.backKeyBus.register(this);
}


/**
* handler root registered to otto event bus
* @param e
* handler root (called by each handler)
* @param e event object
*/
@Subscribe
public void rootHandler(StrawEvent e) {

for (StrawEventHandler handler: this.registry.getHandlerRepository().get(e.getType())) {
Expand All @@ -92,8 +76,8 @@ public void rootHandler(StrawEvent e) {
* call this method inside the activity's `onBackPressed`
*/
public void onBackPressed() {
// post back key events to registered handlers
this.backKeyBus.post(new StrawEvent(StrawPlugin.EventType.BACK_PRESSED));
// call rootHandler with event object
this.rootHandler(new StrawEvent(StrawPlugin.EventType.BACK_PRESSED));
}

}

0 comments on commit aefb3ac

Please sign in to comment.