diff --git a/README.md b/README.md index d5e5775..9759f6b 100644 --- a/README.md +++ b/README.md @@ -51,27 +51,58 @@ try { ``` ## Reference ### Methods -`startUpdateFlow()` +#### startUpdateFlow() ```javascript promise string startUpdateFlow(appUpdateType,clientVersionStalenessDays) ``` -**Input** +##### Input | Input | Description | Type | Default Value | ------------- | ------------- | ------------- | ------------- | | appUpdateType | Android In-app updates type | enum(`flexible` or `immediate`) | immediate | | clientVersionStalenessDays | If an update is available In-app modal will only triger after `x` number of days since the Google Play Store app on the user's device has learnt about an available update. | `int` | 0 | -**Promise Resolve** +##### Promise Resolve | Value | Description | ------------- | ------------- | `Canceled` | In-app modal canceled by user | `Successful` | User press the update button -**Promise Reject** +##### Promise Reject | Value | Description | ------------- | ------------- | `checkAppUpdate failure:` | `appUpdateInfoTask` failed getting result. This can mean numerous reason check the log for more explanation. -| `No update available:` | There is no update available with the `appUpdateType` type. +| `No update available` | There is no update available with the `appUpdateType` type. | `startUpdateFlow failure:` | Failed starting the Google Play In-app updates modal. +#### checkUpdateAvailability() +```javascript +promise string checkUpdateAvailability() +``` + +##### Promise Resolve +| Value | Description +| ------------- | ------------- +| `Update available` | Application update is available + +##### Promise Reject +| Value | Description +| ------------- | ------------- +| `checkAppUpdate failure:` | `appUpdateInfoTask` failed getting result. This can mean numerous reason check the log for more explanation. +| `No update available` | There is no update available + +#### onCompleteUpdate() +```javascript +promise string onCompleteUpdate() +``` + +##### Promise Resolve +| Value | Description +| ------------- | ------------- +| `success` | Application update succeed + +##### Promise Reject +| Value | Description +| ------------- | ------------- +| `Download is not completed` | Application update process fail + ❤️ From Indonesia diff --git a/android/src/main/java/com/agastya/androidinappupdates/AndroidInappUpdatesModule.java b/android/src/main/java/com/agastya/androidinappupdates/AndroidInappUpdatesModule.java index 6608aab..d3b03fd 100644 --- a/android/src/main/java/com/agastya/androidinappupdates/AndroidInappUpdatesModule.java +++ b/android/src/main/java/com/agastya/androidinappupdates/AndroidInappUpdatesModule.java @@ -59,8 +59,8 @@ public void onCatalystInstanceDestroy() { } protected void checkUpdate(final Promise promise, int appUpdateType, int clientVersionStalenessDays) { - Task appUpdateInfoTask = appUpdateManager.getAppUpdateInfo(); + appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> { if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.clientVersionStalenessDays() != null @@ -92,6 +92,21 @@ public void checkAppUpdate(int appUpdateType, int clientVersionStalenessDays, fi checkUpdate(promise, appUpdateType, clientVersionStalenessDays); } + @ReactMethod + public void checkUpdateStatus(final Promise promise) { + Task appUpdateInfoTask = appUpdateManager.getAppUpdateInfo(); + + appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> { + if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) { + promise.resolve("Update available"); + } else { + promise.reject("reject", "No update available"); + } + }).addOnFailureListener(failure -> { + promise.reject("reject", "checkUpdateStatus failure: " + failure.toString()); + }); + } + @ReactMethod public void completeUpdate(final Promise promise) { if (this.isDownloadSuccess) { diff --git a/src/index.re b/src/index.re index beaac85..32ace24 100644 --- a/src/index.re +++ b/src/index.re @@ -1,6 +1,12 @@ [@bs.module "react-native"] [@bs.scope ("NativeModules", "AndroidInappUpdates")] external checkAppUpdate: (int, int) => string = "checkAppUpdate"; +[@bs.module "react-native"] +[@bs.scope ("NativeModules", "AndroidInappUpdates")] +external completeUpdate: unit => string = "completeUpdate"; +[@bs.module "react-native"] +[@bs.scope ("NativeModules", "AndroidInappUpdates")] +external checkUpdateStatus: unit => string = "checkUpdateStatus"; let updateFlowDict = Js.Dict.fromList([("IMMEDIATE", 1), ("FLEXIBLE", 0)]); @@ -16,3 +22,7 @@ let startUpdateFlow = checkAppUpdate(updateCode, clientVersionStalenessDays); }; + +let onCompleteUpdate: unit => string = completeUpdate; + +let checkUpdateAvailability: unit => string = checkUpdateStatus;