I am trying to implement some simple change detection on a database. However the call back is never firing. Here is my code. I am using forestDB.
private static Manager dbmgr = null;
private static HashMap<String, Database> dbs = null;
private void initDb(final JSONArray args, final CallbackContext callback) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
String dbName = args.getString(0);
if (dbs == null) dbs = new HashMap<String, Database>();
DatabaseOptions options = new DatabaseOptions();
options.setCreate(true);
options.setStorageType(Manager.FORESTDB_STORAGE);
dbs.put(dbName, dbmgr.openDatabase(dbName, options));
callback.success("CBL db init success");
} catch (final Exception e) {
callback.error(e.getMessage());
}
}
});
}
private void changesDatabase(final JSONArray args, final CallbackContext callback) {
PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
result.setKeepCallback(true);
callback.sendPluginResult(result);
try{
String dbName = args.getString(0);
dbs.get(dbName).addChangeListener(new Database.ChangeListener() {
@Override
public void changed(Database.ChangeEvent event) {
List<DocumentChange> changes = event.getChanges();
for (DocumentChange change : changes) {
PluginResult result = new PluginResult(PluginResult.Status.OK, change.getDocumentId());
result.setKeepCallback(true);
callback.sendPluginResult(result);
}
}
});
}
catch(Exception e){}
}