[sword-svn] r3635 - in trunk/bindings/cordova/cordova-plugin-crosswire-sword: . src/android

scribe at crosswire.org scribe at crosswire.org
Sun May 26 12:41:40 MST 2019


Author: scribe
Date: 2019-05-26 12:41:39 -0700 (Sun, 26 May 2019)
New Revision: 3635

Modified:
   trunk/bindings/cordova/cordova-plugin-crosswire-sword/package.json
   trunk/bindings/cordova/cordova-plugin-crosswire-sword/plugin.xml
   trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java
Log:
Fixed a threading bug with renderChapter in cordova-plugin for Android

Modified: trunk/bindings/cordova/cordova-plugin-crosswire-sword/package.json
===================================================================
--- trunk/bindings/cordova/cordova-plugin-crosswire-sword/package.json	2019-05-25 06:54:37 UTC (rev 3634)
+++ trunk/bindings/cordova/cordova-plugin-crosswire-sword/package.json	2019-05-26 19:41:39 UTC (rev 3635)
@@ -1,6 +1,6 @@
 {
   "name": "cordova-plugin-crosswire-sword",
-  "version": "0.0.1",
+  "version": "0.0.3",
   "description": "The SWORD Project Plugin",
   "cordova": {
     "id": "cordova-plugin-crosswire-sword",

Modified: trunk/bindings/cordova/cordova-plugin-crosswire-sword/plugin.xml
===================================================================
--- trunk/bindings/cordova/cordova-plugin-crosswire-sword/plugin.xml	2019-05-25 06:54:37 UTC (rev 3634)
+++ trunk/bindings/cordova/cordova-plugin-crosswire-sword/plugin.xml	2019-05-26 19:41:39 UTC (rev 3635)
@@ -4,7 +4,7 @@
     xmlns:rim="http://www.blackberry.com/ns/widgets"
     xmlns:android="http://schemas.android.com/apk/res/android"
     id="cordova-plugin-crosswire-sword"
-    version="0.0.1">
+    version="0.0.3">
     <name>cordova-plugin-crosswire-sword</name>
     <description>The SWORD Project Plugin</description>
     <license>GNU 2.0</license>

Modified: trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java
===================================================================
--- trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java	2019-05-25 06:54:37 UTC (rev 3634)
+++ trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java	2019-05-26 19:41:39 UTC (rev 3635)
@@ -55,7 +55,6 @@
 	public static InstallMgr installMgr = null;
 	private CallbackContext installReporterContext = null;
 	private CallbackContext searchReporterContext = null;
-	private CallbackContext renderChapterContext = null;
 	private CallbackContext sendContext = null;
 
 	/**
@@ -77,7 +76,6 @@
 		installMgr = new InstallMgr();
 		installReporterContext = null;
 		searchReporterContext = null;
-		renderChapterContext = null;
 	}
 
 	/**
@@ -332,26 +330,28 @@
 			callbackContext.sendPluginResult(result);
 		}
 		else if (action.equals("SWModule_getRenderChapter")) {
-			this.renderChapterContext = callbackContext;
-
+Log.d(TAG, "SWModule_getRenderChapter");
 			final SWModule masterMod = mgr.getModuleByName(args.getString(0));
 			final SWModule mod = mgr.getModuleByName(args.getString(1));
+			final CallbackContext myCallbackContext = callbackContext;
 			if (masterMod == null) { callbackContext.error("couldn't find master module: " + args.getString(0)); return true; }
 			if (mod == null) { callbackContext.error("couldn't find module: " + args.getString(1)); return true; }
 
 			cordova.getThreadPool().execute(new Runnable() {
+				private CallbackContext myThreadRenderChapterContext = myCallbackContext;
 			    @Override
 			    public void run() {
 
 				JSONArray r = new JSONArray();
 				try {
+Log.d(TAG, "... in spawned thread to renderChapter");
 					r = getRenderChapter(masterMod, mod);
+Log.d(TAG, "... finished renderChapter");
 				} catch (JSONException e) { e.printStackTrace(); }
 				PluginResult result = new PluginResult(PluginResult.Status.OK, r);
 				result.setKeepCallback(false);
-				if (renderChapterContext != null) {
-					renderChapterContext.sendPluginResult(result);
-					renderChapterContext = null;
+				if (myThreadRenderChapterContext != null) {
+					myThreadRenderChapterContext.sendPluginResult(result);
 				}
 			    }
 			});
@@ -565,16 +565,20 @@
 
 		String currentKey[]   = masterMod.getKeyChildren();
 
+Log.d(TAG, "getRenderChapter: checking currentKey");
 		// assert we have a valid location
 		if (currentKey.length <= SWModule.VERSEKEY_BOOKABBREV || currentKey.length <= SWModule.VERSEKEY_CHAPTER) return r;
+Log.d(TAG, "getRenderChapter: currentKey valid.");
 
 		masterMod.setKeyText(currentKey[SWModule.VERSEKEY_BOOKABBREV]+"."+currentKey[SWModule.VERSEKEY_CHAPTER]+".1");
+Log.d(TAG, "getRenderChapter: masterMod.setKeyText returned.");
 
 		String [] verseKey = masterMod.getKeyChildren();
 		while (
 				   masterMod.error() == 0
 				&& currentKey[SWModule.VERSEKEY_BOOK].equals(verseKey[SWModule.VERSEKEY_BOOK])
 				&& currentKey[SWModule.VERSEKEY_CHAPTER].equals(verseKey[SWModule.VERSEKEY_CHAPTER])) {
+Log.d(TAG, "looping chapter: " + verseKey[SWModule.VERSEKEY_OSISREF]);
 
 			mod.setKeyText(verseKey[SWModule.VERSEKEY_OSISREF]);
 			char error = mod.error();
@@ -599,6 +603,7 @@
 			masterMod.next();
 			verseKey = masterMod.getKeyChildren();
 		}
+Log.d(TAG, "Done looping chapter");
 
 		masterMod.setKeyText(saveMasterKey);
 		mod.setKeyText(saveKey);




More information about the sword-cvs mailing list