Skip to content

Add two optional options that are used to skip dialogs #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ Just clone and install this demo.
`cordova plugin add cordova-plugin-app-update --save`

# Usage
- Simple:

- Simple:
```js
var updateUrl = "http://192.168.0.1/version.xml";
window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl);
```
- Verbose

- Verbose
```js
var appUpdate = cordova.require('cordova-plugin-app-update.AppUpdate');
var updateUrl = "http://192.168.0.1/version.xml";
Expand All @@ -54,6 +56,14 @@ appUpdate.checkAppUpdate(onSuccess, onFail, updateUrl, {
})
```

- Skip dialog boxes
```js
appUpdate.checkAppUpdate(onSuccess, onFail, updateUrl, {
'skipPromptDialog' : true,
'skipProgressDialog' : true
})
```

### versionCode

You can simply get the versionCode from typing those code in `Console`
Expand Down
13 changes: 7 additions & 6 deletions src/android/DownloadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ public void updateProgress(int progress) {
}

public void updateMsgDialog() {
mDownloadDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); //Update in background
mDownloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.VISIBLE); //Install Manually
mDownloadDialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.VISIBLE); //Download Again

mDownloadDialog.setTitle(msgHelper.getString(MsgHelper.DOWNLOAD_COMPLETE_TITLE));
mDownloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL)
.setOnClickListener(downloadCompleteOnClick);
if (mDownloadDialog.isShowing()) {
mDownloadDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); //Update in background
mDownloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.VISIBLE); //Install Manually
mDownloadDialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.VISIBLE); //Download Again

mDownloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(downloadCompleteOnClick);
}
}

private OnClickListener downloadCompleteOnClick = new OnClickListener() {
Expand Down
15 changes: 9 additions & 6 deletions src/android/MsgBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public Dialog showNoticeDialog(OnClickListener onClickListener) {
*/
public Map<String, Object> showDownloadDialog(OnClickListener onClickListenerNeg,
OnClickListener onClickListenerPos,
OnClickListener onClickListenerNeu) {
OnClickListener onClickListenerNeu,
boolean showDialog) {
if (downloadDialog == null) {
LOG.d(TAG, "showDownloadDialog");

Expand All @@ -84,14 +85,16 @@ public Map<String, Object> showDownloadDialog(OnClickListener onClickListenerNeg
downloadDialog = builder.create();
}

if (!downloadDialog.isShowing()) downloadDialog.show();
if (showDialog && !downloadDialog.isShowing()) downloadDialog.show();

downloadDialog.setTitle(msgHelper.getString(MsgHelper.UPDATING));
downloadDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.VISIBLE); //Update in background
downloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.GONE); //Install Manually
downloadDialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.GONE); //Download Again

downloadDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
if (downloadDialog.isShowing()) {
downloadDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.VISIBLE); //Update in background
downloadDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.GONE); //Install Manually
downloadDialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.GONE); //Download Again
}

Map<String, Object> ret = new HashMap<String, Object>();
ret.put("dialog", downloadDialog);
ret.put("progress", downloadDialogProgress);
Expand Down
32 changes: 27 additions & 5 deletions src/android/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,31 @@ private void compareVersions() {
int versionCodeLocal = version.getLocal();
int versionCodeRemote = version.getRemote();

boolean skipPromptDialog = false;
try {
skipPromptDialog = options.getBoolean("skipPromptDialog");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest you move skipPromptDialog / skipProgressDialog into Constants

} catch (JSONException e) {}

boolean skipProgressDialog = false;
try {
skipProgressDialog = options.getBoolean("skipProgressDialog");
} catch (JSONException e) {}

//比对版本号
//检查软件是否有更新版本
if (versionCodeLocal < versionCodeRemote) {
if (isDownloading) {
msgBox.showDownloadDialog(null, null, null);
msgBox.showDownloadDialog(null, null, null, !skipProgressDialog);
mHandler.sendEmptyMessage(Constants.VERSION_UPDATING);
} else {
LOG.d(TAG, "need update");
// 显示提示对话框
msgBox.showNoticeDialog(noticeDialogOnClick);
mHandler.sendEmptyMessage(Constants.VERSION_NEED_UPDATE);
if (skipPromptDialog) {
mHandler.sendEmptyMessage(Constants.DOWNLOAD_CLICK_START);
} else {
// 显示提示对话框
msgBox.showNoticeDialog(noticeDialogOnClick);
mHandler.sendEmptyMessage(Constants.VERSION_NEED_UPDATE);
}
}
} else {
mHandler.sendEmptyMessage(Constants.VERSION_UP_TO_UPDATE);
Expand All @@ -169,11 +183,19 @@ public void onClick(DialogInterface dialog, int which) {

private void emitNoticeDialogOnClick() {
isDownloading = true;

boolean skipProgressDialog = false;
try {
skipProgressDialog = options.getBoolean("skipProgressDialog");
} catch (JSONException e) {}

// 显示下载对话框
Map<String, Object> ret = msgBox.showDownloadDialog(
downloadDialogOnClickNeg,
downloadDialogOnClickPos,
downloadDialogOnClickNeu);
downloadDialogOnClickNeu,
!skipProgressDialog);

// 下载文件
downloadApk((AlertDialog) ret.get("dialog"), (ProgressBar) ret.get("progress"));
}
Expand Down