From ad6a447bded7e64c1bc7b9d0785f636de508ebb8 Mon Sep 17 00:00:00 2001 From: fkloft Date: Mon, 2 Dec 2013 23:18:55 +0100 Subject: [PATCH] Allow plugins to add panes to mobile nav drawer --- code/hooks.js | 6 +++++- code/panes.js | 5 ++--- .../src/com/cradle/iitc_mobile/IITC_JSInterface.java | 10 ++++++++++ .../com/cradle/iitc_mobile/IITC_NavigationHelper.java | 5 +++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/code/hooks.js b/code/hooks.js index b4959745..60eefe45 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -50,6 +50,10 @@ // iitcLoaded: called after IITC and all plugins loaded // portalDetailLoaded: called when a request to load full portal detail // completes. guid, success, details parameters +// paneChanged called when the current pane has changed. On desktop, +// this only selects the current chat pane; on mobile, it +// also switches between map, info and other panes defined +// by plugins window._hooks = {} window.VALID_HOOKS = [ @@ -60,7 +64,7 @@ window.VALID_HOOKS = [ 'publicChatDataAvailable', 'factionChatDataAvailable', 'requestFinished', 'nicknameClicked', 'geoSearch', 'iitcLoaded', - 'portalDetailLoaded']; + 'portalDetailLoaded', 'paneChanged']; window.runHooks = function(event, data) { if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event); diff --git a/code/panes.js b/code/panes.js index 4c3898d4..c5ea4eea 100644 --- a/code/panes.js +++ b/code/panes.js @@ -3,6 +3,8 @@ window.show = function(id) { window.hideall(); + runHooks("paneChanged", id); + switch(id) { case 'full': window.chat.show('full'); @@ -27,9 +29,6 @@ window.show = function(id) { case 'info': window.smartphone.sideButton.click(); break; - default: - window.smartphone.mapButton.click(); - break; } if (typeof android !== 'undefined' && android && android.switchToPane) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index d86e3e0e..010afcdd 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -168,4 +168,14 @@ public class IITC_JSInterface { } }); } + + @JavascriptInterface + public void addPane(final String name, final String label, final String icon) { + mIitc.runOnUiThread(new Runnable() { + @Override + public void run() { + mIitc.getNavigationHelper().addPane(name, label, icon); + } + }); + } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_NavigationHelper.java b/mobile/src/com/cradle/iitc_mobile/IITC_NavigationHelper.java index 35b8a504..f3e00f12 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_NavigationHelper.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_NavigationHelper.java @@ -168,6 +168,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt } } + public void addPane(String name, String label, String icon) { + // TODO handle icon + mNavigationAdapter.add(new Pane(name, label, 0)); + } + public void closeDrawers() { mDrawerLayout.closeDrawers(); }