Skip to content

Commit

Permalink
Add binding for onCompleteUpdate, and Init checkUpdateAvailability (#1)
Browse files Browse the repository at this point in the history
* bind completeUpdate and init checkUpdateStatus

* remove stetho import

* fix module binding arguments

* update README with new method

* add README for onCompleteUpdate

* remove the params on method's section header
  • Loading branch information
ybbond authored Oct 8, 2020
1 parent add2f21 commit 87f056d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void onCatalystInstanceDestroy() {
}

protected void checkUpdate(final Promise promise, int appUpdateType, int clientVersionStalenessDays) {

Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.clientVersionStalenessDays() != null
Expand Down Expand Up @@ -92,6 +92,21 @@ public void checkAppUpdate(int appUpdateType, int clientVersionStalenessDays, fi
checkUpdate(promise, appUpdateType, clientVersionStalenessDays);
}

@ReactMethod
public void checkUpdateStatus(final Promise promise) {
Task<AppUpdateInfo> 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) {
Expand Down
10 changes: 10 additions & 0 deletions src/index.re
Original file line number Diff line number Diff line change
@@ -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)]);

Expand All @@ -16,3 +22,7 @@ let startUpdateFlow =

checkAppUpdate(updateCode, clientVersionStalenessDays);
};

let onCompleteUpdate: unit => string = completeUpdate;

let checkUpdateAvailability: unit => string = checkUpdateStatus;

0 comments on commit 87f056d

Please sign in to comment.