Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Added isUpdateAvailableForInstallation() method to Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Apr 22, 2016
1 parent 94229d3 commit 0204a2e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
Expand Down Expand Up @@ -229,6 +231,8 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
jsSetPluginOptions(args, callbackContext);
} else if (JSAction.REQUEST_APP_UPDATE.equals(action)) {
jsRequestAppUpdate(args, callbackContext);
} else if (JSAction.IS_UPDATE_AVAILABLE_FOR_INSTALLATION.equals(action)) {
jsIsUpdateAvailableForInstallation(callbackContext);
} else {
cmdProcessed = false;
}
Expand Down Expand Up @@ -394,6 +398,27 @@ private void jsRequestAppUpdate(final CordovaArgs arguments, final CallbackConte
new AppUpdateRequestDialog(cordova.getActivity(), msg, storeURL, callback).show();
}

/**
* Check if new version was loaded and can be installed.
*
* @param callback callback where to send the result
* */
private void jsIsUpdateAvailableForInstallation(final CallbackContext callback) {
Map<String, Object> data = null;
ChcpError error = null;
final String readyForInstallationVersionName = pluginInternalPrefs.getReadyForInstallationReleaseVersionName();
if (!TextUtils.isEmpty(readyForInstallationVersionName)) {
data = new HashMap<String, Object>();
data.put("readyToInstallVersion", readyForInstallationVersionName);
data.put("currentVersion", pluginInternalPrefs.getCurrentReleaseVersionName());
} else {
error = ChcpError.NOTHING_TO_INSTALL;
}

PluginResult pluginResult = PluginResultHelper.createPluginResult(null, data, error);
callback.sendPluginResult(pluginResult);
}

/**
* Perform update availability check.
*
Expand Down
1 change: 1 addition & 0 deletions src/android/src/com/nordnetab/chcp/main/js/JSAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class JSAction {
public static final String INSTALL_UPDATE = "jsInstallUpdate";
public static final String CONFIGURE = "jsConfigure";
public static final String REQUEST_APP_UPDATE = "jsRequestAppUpdate";
public static final String IS_UPDATE_AVAILABLE_FOR_INSTALLATION = "jsIsUpdateAvailableForInstallation";

// Private API
public static final String INIT = "jsInitPlugin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private static PluginResult getResult(String action, JsonNode data, JsonNode err
JsonNodeFactory factory = JsonNodeFactory.instance;

ObjectNode resultObject = factory.objectNode();
resultObject.set(JsParams.General.ACTION, factory.textNode(action));
if (action != null) {
resultObject.set(JsParams.General.ACTION, factory.textNode(action));
}

if (data != null) {
resultObject.set(JsParams.General.DATA, data);
Expand Down

0 comments on commit 0204a2e

Please sign in to comment.