Merge branch 'master' of github.com:ZertApps/DVHMA

This commit is contained in:
Achim D. Brucker 2016-07-24 21:01:40 +01:00
commit 94907fa5de
7 changed files with 62 additions and 152 deletions

View File

@ -17,34 +17,30 @@ function onDeviceReady() {
checkForExtraText(); checkForExtraText();
} }
function logError(error) {
console.log(error);
}
function checkForExtraText() { function checkForExtraText() {
window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_TEXT, function(hasExtra) { window.webintent(window.webintent.EXTRA_TEXT, function(content) {
if (hasExtra) { window.webintent(window.webintent.EXTRA_SUBJECT, function(title) {
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT, function(content) { var param = {};
window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_SUBJECT, function(hasSubjectExtra) { param.title = title;
if (hasSubjectExtra) { param.content = content;
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_SUBJECT, function(title) { window.todo.create([param], reloadItems, logError);
var param = {}; }, function(error) {
param.title = title; var param = {};
param.content = content; param.title = "NewTitle";
window.todo.create([param], reloadItems, console.log); param.content = content;
}, console.log); window.todo.create([param], reloadItems, logError);
} else { });
var param = {}; }, function(error) {
param.title = "NewTitle"; window.todo.get(reloadItems, logError);
param.content = content; });
window.todo.create([param], reloadItems, console.log);
}
}, console.log);
}, console.log);
} else {
window.todo.get(reloadItems, console.log);
}
}, console.log);
} }
function onRemoveItem(e) { function onRemoveItem(e) {
window.todo.delete([e.target.parentNode.parentNode.dataset.id], reloadItems, console.log); window.todo.delete([e.target.parentNode.parentNode.dataset.id], reloadItems, logError);
} }
function onEditItem(e) { function onEditItem(e) {
@ -60,8 +56,8 @@ function onEditItem(e) {
if (newContent == null) { if (newContent == null) {
newContent = oldContent; newContent = oldContent;
} }
window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, console.log); window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, logError);
}, alert); }, logError);
} }
function onLoadContent(e) { function onLoadContent(e) {
@ -76,7 +72,7 @@ function onLoadContent(e) {
contentDiv.parentNode.getElementsByTagName("img")[0].src = "img/ic_action_collapse.png"; contentDiv.parentNode.getElementsByTagName("img")[0].src = "img/ic_action_collapse.png";
contentDiv.innerHTML = items[id]["content"]; contentDiv.innerHTML = items[id]["content"];
contentDiv.dataset.loaded = true; contentDiv.dataset.loaded = true;
}, console.log); }, logError);
} }
} }
@ -132,7 +128,7 @@ function reloadItems(items) {
} }
function onNewItemClick() { function onNewItemClick() {
window.todo.create([{"title" : "NewTitle", "content" : "New Content"}], reloadItems, console.log); window.todo.create([{"title" : "NewTitle", "content" : "New Content"}], reloadItems, logError);
} }
document.addEventListener("deviceready", onDeviceReady); document.addEventListener("deviceready", onDeviceReady);

View File

@ -4,7 +4,7 @@ version="1.0.0">
<name>DVHMA-Storage</name> <name>DVHMA-Storage</name>
<description>DVHMA Storage Backend</description> <description>DVHMA Storage Backend</description>
<js-module src="www/DVHMA-Storage.js" name="DVHMA-Storage"> <js-module src="www/DVHMA-Storage.js" name="DVHMA-Storage">
<clobbers target="DVHMA-Storage" /> <clobbers target="window.todo" />
</js-module> </js-module>
<!-- android --> <!-- android -->

View File

@ -57,6 +57,10 @@ public class DVHMAStorage extends CordovaPlugin {
return false; return false;
} }
} }
private void get(CordovaArgs args, CallbackContext callbackContext) {
JSONArray result = queryDatabase();
callbackContext.success(result);
}
private void edit(CordovaArgs args, CallbackContext callbackContext) { private void edit(CordovaArgs args, CallbackContext callbackContext) {
int index; int index;
@ -77,10 +81,11 @@ public class DVHMAStorage extends CordovaPlugin {
db.execSQL("UPDATE " + DVHMAStorageDbHelper.TABLE_NAME + " SET title='" + newTitle + "',content='" + newContent + "' WHERE id=" + c.getInt(c.getColumnIndex("id")) + ";"); db.execSQL("UPDATE " + DVHMAStorageDbHelper.TABLE_NAME + " SET title='" + newTitle + "',content='" + newContent + "' WHERE id=" + c.getInt(c.getColumnIndex("id")) + ";");
db.close(); db.close();
get(null, callbackContext); JSONArray result = queryDatabase();
callbackContext.success(result);
} }
private void get(CordovaArgs args, CallbackContext callbackContext) { private JSONArray queryDatabase() {
SQLiteDatabase db = mDbHelper.getWritableDatabase(); SQLiteDatabase db = mDbHelper.getWritableDatabase();
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
Cursor c = db.rawQuery("SELECT * FROM " + DVHMAStorageDbHelper.TABLE_NAME + ";", null); Cursor c = db.rawQuery("SELECT * FROM " + DVHMAStorageDbHelper.TABLE_NAME + ";", null);
@ -98,7 +103,7 @@ public class DVHMAStorage extends CordovaPlugin {
} }
c.close(); c.close();
db.close(); db.close();
callbackContext.success(array); return array;
} }
private void delete(CordovaArgs args, CallbackContext callbackContext) { private void delete(CordovaArgs args, CallbackContext callbackContext) {
@ -117,7 +122,8 @@ public class DVHMAStorage extends CordovaPlugin {
c.close(); c.close();
db.close(); db.close();
get(null, callbackContext); JSONArray result = queryDatabase();
callbackContext.success(result);
} }
private void create(CordovaArgs args, CallbackContext callbackContext) { private void create(CordovaArgs args, CallbackContext callbackContext) {
@ -135,6 +141,7 @@ public class DVHMAStorage extends CordovaPlugin {
db.execSQL("INSERT INTO " + DVHMAStorageDbHelper.TABLE_NAME + " (title,content) VALUES('" + newTitle + "','" + newContent + "');"); db.execSQL("INSERT INTO " + DVHMAStorageDbHelper.TABLE_NAME + " (title,content) VALUES('" + newTitle + "','" + newContent + "');");
db.close(); db.close();
get(null, callbackContext); JSONArray result = queryDatabase();
callbackContext.success(result);
} }
} }

View File

@ -12,46 +12,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
module.exports.create = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'create', params);
}
(function(cordova){ module.exports.get = function(success, fail) {
var DVHMAStorage = function() { return cordova.exec(success, fail, 'DVHMAStorage', 'get', []);
}
}; module.exports.delete = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'delete', params);
DVHMAStorage.prototype.create = function(params, success, fail) { }
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'DVHMAStorage', 'create', params);
}
DVHMAStorage.prototype.get = function(success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'DVHMAStorage', 'get', []);
}
DVHMAStorage.prototype.delete = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'DVHMAStorage', 'delete', params);
}
DVHMAStorage.prototype.edit = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'DVHMAStorage', 'edit', params);
}
window.todo = new DVHMAStorage(); module.exports.edit = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'edit', params);
// backwards compatibility }
window.plugins = window.plugins || {};
window.plugins.webintent = window.webintent;
})(window.PhoneGap || window.Cordova || window.cordova);

View File

@ -9,7 +9,7 @@
<keywords>cordova,webintent</keywords> <keywords>cordova,webintent</keywords>
<js-module src="www/webintent.js" name="WebIntent"> <js-module src="www/webintent.js" name="WebIntent">
<clobbers target="WebIntent" /> <clobbers target="window.webintent" />
</js-module> </js-module>
<!-- android --> <!-- android -->

View File

@ -1,20 +1,13 @@
package com.borismus.webintent; package com.borismus.webintent;
import java.util.HashMap;
import java.util.Map;
import org.apache.cordova.CordovaActivity; import org.apache.cordova.CordovaActivity;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaResourceApi;
import org.apache.cordova.PluginResult; import org.apache.cordova.PluginResult;
/** /**
@ -29,69 +22,35 @@ import org.apache.cordova.PluginResult;
*/ */
public class WebIntent extends CordovaPlugin { public class WebIntent extends CordovaPlugin {
private CallbackContext onNewIntentCallbackContext = null;
// public boolean execute(String action, JSONArray args, String callbackId) {
@Override @Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
try { try {
if (action.equals("getExtra")) {
if (action.equals("hasExtra")) {
return hasExtra(args, callbackContext);
} else if (action.equals("getExtra")) {
return getExtra(args, callbackContext); return getExtra(args, callbackContext);
} }
// return new PluginResult(PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
return false; return false;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
String errorMessage = e.getMessage(); String errorMessage = e.getMessage();
// return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage));
return false; return false;
} }
} }
boolean hasExtra(JSONArray args, CallbackContext callbackContext) throws JSONException {
if (args.length() != 1) {
// return new PluginResult(PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
return false;
}
Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent();
String extraName = args.getString(0);
// return new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName)));
return true;
}
boolean getExtra(JSONArray args, CallbackContext callbackContext) throws JSONException { boolean getExtra(JSONArray args, CallbackContext callbackContext) throws JSONException {
if (args.length() != 1) { if (args.length() != 1) {
// return new PluginResult(PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
return false; return false;
} }
Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent();
String extraName = args.getString(0); String extraName = args.getString(0);
if (i.hasExtra(extraName)) { if (i.hasExtra(extraName)) {
// return new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName)));
return true; return true;
} else { } else {
// return new PluginResult(PluginResult.Status.ERROR);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
return false; return false;
} }
} }
@Override
public void onNewIntent(Intent intent) {
if (this.onNewIntentCallbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
result.setKeepCallback(true);
this.onNewIntentCallbackContext.sendPluginResult(result);
}
}
} }

View File

@ -3,39 +3,15 @@
* Copyright (c) Boris Smus 2010 * Copyright (c) Boris Smus 2010
* *
*/ */
(function(cordova) { module.exports = function(params, success, fail) {
var WebIntent = function() { return cordova.exec(success, fail, 'WebIntent', 'getExtra', [params]);
};
}; module.exports.ACTION_SEND = "android.intent.action.SEND";
module.exports.ACTION_VIEW= "android.intent.action.VIEW";
WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; module.exports.EXTRA_TEXT = "android.intent.extra.TEXT";
WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; module.exports.EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; module.exports.EXTRA_STREAM = "android.intent.extra.STREAM";
WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; module.exports.EXTRA_EMAIL = "android.intent.extra.EMAIL";
WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; module.exports.ACTION_CALL = "android.intent.action.CALL";
WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; module.exports.ACTION_SENDTO = "android.intent.action.SENDTO";
WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL";
WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO";
WebIntent.prototype.hasExtra = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'hasExtra', [params]);
};
WebIntent.prototype.getExtra = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'getExtra', [params]);
};
window.webintent = new WebIntent();
// backwards compatibility
window.plugins = window.plugins || {};
window.plugins.webintent = window.webintent;
})(window.PhoneGap || window.Cordova || window.cordova);