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();
}
function logError(error) {
console.log(error);
}
function checkForExtraText() {
window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_TEXT, function(hasExtra) {
if (hasExtra) {
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT, function(content) {
window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_SUBJECT, function(hasSubjectExtra) {
if (hasSubjectExtra) {
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_SUBJECT, function(title) {
var param = {};
param.title = title;
param.content = content;
window.todo.create([param], reloadItems, console.log);
}, console.log);
} else {
var param = {};
param.title = "NewTitle";
param.content = content;
window.todo.create([param], reloadItems, console.log);
}
}, console.log);
}, console.log);
} else {
window.todo.get(reloadItems, console.log);
}
}, console.log);
window.webintent(window.webintent.EXTRA_TEXT, function(content) {
window.webintent(window.webintent.EXTRA_SUBJECT, function(title) {
var param = {};
param.title = title;
param.content = content;
window.todo.create([param], reloadItems, logError);
}, function(error) {
var param = {};
param.title = "NewTitle";
param.content = content;
window.todo.create([param], reloadItems, logError);
});
}, function(error) {
window.todo.get(reloadItems, logError);
});
}
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) {
@ -60,8 +56,8 @@ function onEditItem(e) {
if (newContent == null) {
newContent = oldContent;
}
window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, console.log);
}, alert);
window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, logError);
}, logError);
}
function onLoadContent(e) {
@ -76,7 +72,7 @@ function onLoadContent(e) {
contentDiv.parentNode.getElementsByTagName("img")[0].src = "img/ic_action_collapse.png";
contentDiv.innerHTML = items[id]["content"];
contentDiv.dataset.loaded = true;
}, console.log);
}, logError);
}
}
@ -132,7 +128,7 @@ function reloadItems(items) {
}
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);

View File

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

View File

@ -57,6 +57,10 @@ public class DVHMAStorage extends CordovaPlugin {
return false;
}
}
private void get(CordovaArgs args, CallbackContext callbackContext) {
JSONArray result = queryDatabase();
callbackContext.success(result);
}
private void edit(CordovaArgs args, CallbackContext callbackContext) {
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.close();
get(null, callbackContext);
JSONArray result = queryDatabase();
callbackContext.success(result);
}
private void get(CordovaArgs args, CallbackContext callbackContext) {
private JSONArray queryDatabase() {
SQLiteDatabase db = mDbHelper.getWritableDatabase();
JSONArray array = new JSONArray();
Cursor c = db.rawQuery("SELECT * FROM " + DVHMAStorageDbHelper.TABLE_NAME + ";", null);
@ -98,7 +103,7 @@ public class DVHMAStorage extends CordovaPlugin {
}
c.close();
db.close();
callbackContext.success(array);
return array;
}
private void delete(CordovaArgs args, CallbackContext callbackContext) {
@ -117,7 +122,8 @@ public class DVHMAStorage extends CordovaPlugin {
c.close();
db.close();
get(null, callbackContext);
JSONArray result = queryDatabase();
callbackContext.success(result);
}
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.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
* limitations under the License.
*/
module.exports.create = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'create', params);
}
(function(cordova){
var DVHMAStorage = function() {
module.exports.get = function(success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'get', []);
}
};
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);
}
module.exports.delete = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'delete', params);
}
window.todo = new DVHMAStorage();
// backwards compatibility
window.plugins = window.plugins || {};
window.plugins.webintent = window.webintent;
})(window.PhoneGap || window.Cordova || window.cordova);
module.exports.edit = function(params, success, fail) {
return cordova.exec(success, fail, 'DVHMAStorage', 'edit', params);
}

View File

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

View File

@ -1,20 +1,13 @@
package com.borismus.webintent;
import java.util.HashMap;
import java.util.Map;
import org.apache.cordova.CordovaActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaResourceApi;
import org.apache.cordova.PluginResult;
/**
@ -29,69 +22,35 @@ import org.apache.cordova.PluginResult;
*/
public class WebIntent extends CordovaPlugin {
private CallbackContext onNewIntentCallbackContext = null;
// public boolean execute(String action, JSONArray args, String callbackId) {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
try {
if (action.equals("hasExtra")) {
return hasExtra(args, callbackContext);
} else if (action.equals("getExtra")) {
if (action.equals("getExtra")) {
return getExtra(args, callbackContext);
}
// return new PluginResult(PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
return false;
} catch (JSONException e) {
e.printStackTrace();
String errorMessage = e.getMessage();
// return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage));
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 {
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);
if (i.hasExtra(extraName)) {
// return new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName)));
return true;
} else {
// return new PluginResult(PluginResult.Status.ERROR);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
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
*
*/
(function(cordova) {
var WebIntent = function() {
module.exports = function(params, success, fail) {
return cordova.exec(success, fail, 'WebIntent', 'getExtra', [params]);
};
};
WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND";
WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW";
WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT";
WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM";
WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL";
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);
module.exports.ACTION_SEND = "android.intent.action.SEND";
module.exports.ACTION_VIEW= "android.intent.action.VIEW";
module.exports.EXTRA_TEXT = "android.intent.extra.TEXT";
module.exports.EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
module.exports.EXTRA_STREAM = "android.intent.extra.STREAM";
module.exports.EXTRA_EMAIL = "android.intent.extra.EMAIL";
module.exports.ACTION_CALL = "android.intent.action.CALL";
module.exports.ACTION_SENDTO = "android.intent.action.SENDTO";