Skip to content

Commit

Permalink
change named of some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed Jan 2, 2018
1 parent 7e7d6bd commit 36ff97e
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private static class NotificationCB implements DownloadCallback {
.setSmallIcon(activity.getApplicationInfo().icon)
.setAutoCancel(false)
.setContentText("下载中...")
.setContentText("UpdatePlugin")
.build();
id = Math.abs(UUID.randomUUID().hashCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
* 2. 通过{@link #create(UpdateConfig)}指定使用某个特殊的更新配置。<br>
*
* <p>此Builder中的所有配置项,均在{@link UpdateConfig}中有对应的相同方法名的配置函数。此两者的关系为:
* 在更新流程中当Builder中未设置对应的配置,将会使用在{@link UpdateConfig}更新配置中所提供的默认配置进行使用
* 在更新流程中当Builder中未设置对应的配置,将会使用在{@link UpdateConfig}更新配置中所提供的默认配置。
*
* <p>正常启动:调用{@link #check()}进行启动。
* <p>正常启动:调用{@link #check()}
*
* <p>后台启动:调用{@link #checkWithDaemon(long)}
*
* @author haoge
*/
Expand All @@ -54,21 +56,22 @@ public class UpdateBuilder {
private Class<? extends DownloadWorker> downloadWorker;
private CheckEntity entity;
private UpdateStrategy updateStrategy;
private CheckNotifier updateDialogCreator;
private InstallNotifier installDialogCreator;
private DownloadNotifier downloadDialogCreator;
private UpdateParser jsonParser;
private CheckNotifier checkNotifier;
private InstallNotifier installNotifier;
private DownloadNotifier downloadNotifier;
private UpdateParser updateParser;
private FileCreator fileCreator;
private UpdateChecker updateChecker;
private FileChecker fileChecker;
private InstallStrategy installStrategy;
private UpdateConfig config;

private RetryCallback retryCallback;
private CallbackDelegate callbackDelegate = new CallbackDelegate();
private CallbackDelegate callbackDelegate;

private UpdateBuilder(UpdateConfig config) {
this.config = config;
callbackDelegate = new CallbackDelegate();
callbackDelegate.setCheckDelegate(config.getCheckCallback());
callbackDelegate.setDownloadDelegate(config.getDownloadCallback());
}
Expand Down Expand Up @@ -98,8 +101,8 @@ public void check() {
}

/**
* 启动后台更新任务。此任务特性:当检查更新失败或者当前无更新。则等待指定时间之后,自动重启更新任务。
* @param retryTime 重试时间间隔
* 启动后台更新任务。特性:当检查更新失败或者当前无更新时。等待指定时间之后,自动重启更新任务。
* @param retryTime 重启时间间隔
*/
public void checkWithDaemon(long retryTime) {
RetryCallback retryCallback = getRetryCallback();
Expand Down Expand Up @@ -157,8 +160,8 @@ public UpdateBuilder setCheckCallback(CheckCallback callback) {
return this;
}

public UpdateBuilder setUpdateParser(UpdateParser jsonParser) {
this.jsonParser = jsonParser;
public UpdateBuilder setUpdateParser(UpdateParser updateParser) {
this.updateParser = updateParser;
return this;
}

Expand All @@ -167,18 +170,18 @@ public UpdateBuilder setFileCreator(FileCreator fileCreator) {
return this;
}

public UpdateBuilder setDownloadNotifier(DownloadNotifier downloadDialogCreator) {
this.downloadDialogCreator = downloadDialogCreator;
public UpdateBuilder setDownloadNotifier(DownloadNotifier downloadNotifier) {
this.downloadNotifier = downloadNotifier;
return this;
}

public UpdateBuilder setInstallNotifier(InstallNotifier installDialogCreator) {
this.installDialogCreator = installDialogCreator;
public UpdateBuilder setInstallNotifier(InstallNotifier installNotifier) {
this.installNotifier = installNotifier;
return this;
}

public UpdateBuilder setCheckNotifier(CheckNotifier updateDialogCreator) {
this.updateDialogCreator = updateDialogCreator;
public UpdateBuilder setCheckNotifier(CheckNotifier checkNotifier) {
this.checkNotifier = checkNotifier;
return this;
}

Expand Down Expand Up @@ -218,32 +221,32 @@ public FileChecker getFileChecker() {
return fileChecker != null ? fileChecker : config.getFileChecker();
}

public CheckNotifier getUpdateDialogCreator() {
if (updateDialogCreator == null) {
updateDialogCreator = config.getUpdateDialogCreator();
public CheckNotifier getCheckNotifier() {
if (checkNotifier == null) {
checkNotifier = config.getCheckNotifier();
}
return updateDialogCreator;
return checkNotifier;
}

public InstallNotifier getInstallDialogCreator() {
if (installDialogCreator == null) {
installDialogCreator = config.getInstallDialogCreator();
public InstallNotifier getInstallNotifier() {
if (installNotifier == null) {
installNotifier = config.getInstallNotifier();
}
return installDialogCreator;
return installNotifier;
}

public DownloadNotifier getDownloadDialogCreator() {
if (downloadDialogCreator == null) {
downloadDialogCreator = config.getDownloadDialogCreator();
public DownloadNotifier getDownloadNotifier() {
if (downloadNotifier == null) {
downloadNotifier = config.getDownloadNotifier();
}
return downloadDialogCreator;
return downloadNotifier;
}

public UpdateParser getJsonParser() {
if (jsonParser == null) {
jsonParser = config.getJsonParser();
public UpdateParser getUpdateParser() {
if (updateParser == null) {
updateParser = config.getUpdateParser();
}
return jsonParser;
return updateParser;
}

public Class<? extends CheckWorker> getCheckWorker() {
Expand All @@ -267,11 +270,11 @@ public FileCreator getFileCreator() {
return fileCreator;
}

public CheckCallback getCheckCB() {
public CheckCallback getCheckCallback() {
return callbackDelegate;
}

public DownloadCallback getDownloadCB() {
public DownloadCallback getDownloadCallback() {
return callbackDelegate;
}

Expand All @@ -290,7 +293,7 @@ public boolean isDaemon() {
return isDaemon;
}

public RetryCallback getRetryCallback() {
RetryCallback getRetryCallback() {
if (retryCallback == null) {
retryCallback = new RetryCallback(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
import java.util.concurrent.Executors;

/**
* 此类用于提供一些默认使用的更新配置。在进行更新任务时,当{@link UpdateBuilder} 中未设置对应的配置时。
* 将从此配置类中读取默认的配置进行使用
* 此类用于提供一些默认使用的更新配置。
*
* <p>在进行更新任务时,当{@link UpdateBuilder} 中未设置对应的配置时。将从此配置类中读取默认的配置进行使用
*
* @author haoge
*/
Expand All @@ -58,10 +59,10 @@ public final class UpdateConfig {
private Class<? extends DownloadWorker> downloadWorker;
private CheckEntity entity;
private UpdateStrategy updateStrategy;
private CheckNotifier updateDialogCreator;
private InstallNotifier installDialogCreator;
private DownloadNotifier downloadDialogCreator;
private UpdateParser jsonParser;
private CheckNotifier checkNotifier;
private InstallNotifier installNotifier;
private DownloadNotifier downloadNotifier;
private UpdateParser updateParser;
private FileCreator fileCreator;
private UpdateChecker updateChecker;
private FileChecker fileChecker;
Expand Down Expand Up @@ -193,12 +194,12 @@ public UpdateConfig setCheckCallback(CheckCallback callback) {

/**
* 配置更新数据解析器。
* @param jsonParser 解析器
* @param updateParser 解析器
* @return itself
* @see UpdateParser
*/
public UpdateConfig setUpdateParser(UpdateParser jsonParser) {
this.jsonParser = jsonParser;
public UpdateConfig setUpdateParser(UpdateParser updateParser) {
this.updateParser = updateParser;
return this;
}

Expand All @@ -215,35 +216,35 @@ public UpdateConfig setFileCreator(FileCreator fileCreator) {

/**
* 配置下载进度通知创建器 默认参考{@link DefaultDownloadNotifier}
* @param downloadDialogCreator 下载进度通知创建器
* @param notifier 下载进度通知创建器
* @return itself
* @see DownloadNotifier
*/
public UpdateConfig setDownloadNotifier(DownloadNotifier downloadDialogCreator) {
this.downloadDialogCreator = downloadDialogCreator;
public UpdateConfig setDownloadNotifier(DownloadNotifier notifier) {
this.downloadNotifier = notifier;
return this;
}

/**
* 配置启动安装任务前通知创建器 默认参考{@link DefaultInstallNotifier}
*
* @param installDialogCreator 下载完成后。启动安装前的通知创建器
* @param notifier 下载完成后。启动安装前的通知创建器
* @return itself
* @see InstallNotifier
*/
public UpdateConfig setInstallNotifier(InstallNotifier installDialogCreator) {
this.installDialogCreator = installDialogCreator;
public UpdateConfig setInstallNotifier(InstallNotifier notifier) {
this.installNotifier = notifier;
return this;
}

/**
* 配置检查到有更新时的通知创建器 默认参考{@link DefaultUpdateNotifier}
* @param updateDialogCreator 通知创建器
* @param notifier 通知创建器
* @return itself
* @see CheckNotifier
*/
public UpdateConfig setCheckNotifier(CheckNotifier updateDialogCreator) {
this.updateDialogCreator = updateDialogCreator;
public UpdateConfig setCheckNotifier(CheckNotifier notifier) {
this.checkNotifier = notifier;
return this;
}

Expand Down Expand Up @@ -286,18 +287,18 @@ public CheckEntity getCheckEntity () {
return this.entity;
}

public CheckNotifier getUpdateDialogCreator() {
if (updateDialogCreator == null) {
updateDialogCreator = new DefaultUpdateNotifier();
public CheckNotifier getCheckNotifier() {
if (checkNotifier == null) {
checkNotifier = new DefaultUpdateNotifier();
}
return updateDialogCreator;
return checkNotifier;
}

public InstallNotifier getInstallDialogCreator() {
if (installDialogCreator == null) {
installDialogCreator = new DefaultInstallNotifier();
public InstallNotifier getInstallNotifier() {
if (installNotifier == null) {
installNotifier = new DefaultInstallNotifier();
}
return installDialogCreator;
return installNotifier;
}

public UpdateChecker getUpdateChecker() {
Expand All @@ -314,18 +315,18 @@ public FileChecker getFileChecker() {
return fileChecker;
}

public DownloadNotifier getDownloadDialogCreator() {
if (downloadDialogCreator == null) {
downloadDialogCreator = new DefaultDownloadNotifier();
public DownloadNotifier getDownloadNotifier() {
if (downloadNotifier == null) {
downloadNotifier = new DefaultDownloadNotifier();
}
return downloadDialogCreator;
return downloadNotifier;
}

public UpdateParser getJsonParser() {
if (jsonParser == null) {
public UpdateParser getUpdateParser() {
if (updateParser == null) {
throw new IllegalStateException("update parser is null");
}
return jsonParser;
return updateParser;
}

public Class<? extends CheckWorker> getCheckWorker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public abstract class CheckNotifier {

protected UpdateBuilder builder;
protected Update update;
private CheckCallback checkCB;
private CheckCallback callback;
public final void setBuilder(UpdateBuilder builder) {
this.builder = builder;
this.checkCB = builder.getCheckCB();
this.callback = builder.getCheckCallback();
}

public void setUpdate(Update update) {
Expand Down Expand Up @@ -82,17 +82,17 @@ public final void sendDownloadRequest() {
* 当用户手动取消此次更新任务时,通过此方法进行取消并通知用户
*/
protected final void sendUserCancel() {
if (this.checkCB != null) {
this.checkCB.onUserCancel();
if (this.callback != null) {
this.callback.onUserCancel();
}
}

/**
* 当用户指定需要忽略此版本的更新请求时:通过此方法进行取消并忽略此版本的后续更新请求。
*/
protected final void sendUserIgnore() {
if (this.checkCB != null) {
this.checkCB.onCheckIgnore(update);
if (this.callback != null) {
this.callback.onCheckIgnore(update);
}
UpdatePreference.saveIgnoreVersion(update.getVersionCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected boolean useAsync() {
*/
public final void onResponse(String response) {
try {
UpdateParser jsonParser = builder.getJsonParser();
UpdateParser jsonParser = builder.getUpdateParser();
Update update = jsonParser.parse(response);
if (update == null) {
throw new IllegalArgumentException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public final void sendToInstall() {
* 请求取消更新任务
*/
public final void sendUserCancel() {
if (builder.getCheckCB() != null) {
builder.getCheckCB().onUserCancel();
if (builder.getCheckCallback() != null) {
builder.getCheckCallback().onUserCancel();
}

}
Expand All @@ -97,8 +97,8 @@ public final void sendUserCancel() {
* 请求将此版本加入版本忽略列表
*/
public final void sendCheckIgnore() {
if (builder.getCheckCB() != null) {
builder.getCheckCB().onCheckIgnore(update);
if (builder.getCheckCallback() != null) {
builder.getCheckCallback().onCheckIgnore(update);
}
UpdatePreference.saveIgnoreVersion(update.getVersionCode());
}
Expand Down
Loading

0 comments on commit 36ff97e

Please sign in to comment.