Skip to content

Commit 7e7d6bd

Browse files
committed
add daemon check button
1 parent a4ebcb0 commit 7e7d6bd

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

app/src/main/java/org/lzh/framework/updateplugin/SampleActivity.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.Manifest;
44
import android.app.Activity;
55
import android.os.Bundle;
6+
import android.support.annotation.NonNull;
67

78
import com.tbruyelle.rxpermissions.RxPermissions;
89

@@ -55,8 +56,18 @@ public void call(Boolean aBoolean) {
5556
});
5657
}
5758

59+
@OnClick(R.id.start_daemon_update)
60+
void onDaemonStartClick() {
61+
createBuilder().checkWithDaemon(1000 * 5);// 后台更新时间间隔设置为5秒。
62+
}
63+
5864
@OnClick(R.id.start_update)
5965
void onStartClick () {
66+
createBuilder().check();
67+
}
68+
69+
@NonNull
70+
private UpdateBuilder createBuilder() {
6071
UpdateBuilder builder = UpdateBuilder.create();
6172
if (!newConfig.isDefaultSelected()) {
6273
builder = UpdateBuilder.create(createNewConfig());
@@ -89,12 +100,7 @@ void onStartClick () {
89100
if (!downloadWorker.isDefaultSelected()) {
90101
builder.setDownloadWorker(OkhttpDownloadWorker.class);
91102
}
92-
/*
93-
* 以上为常用的需要定制的功能模块。如果需要更多的定制需求。请参考
94-
* {@link org.lzh.framework.updatepluginlib.UpdateConfig}
95-
* 类中所使用的其他模块的默认实现方式。
96-
* */
97-
builder.check();
103+
return builder;
98104
}
99105

100106
private UpdateConfig createNewConfig() {

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,10 @@
6666
android:text="@string/start_update"
6767
android:layout_width="match_parent"
6868
android:layout_height="wrap_content" />
69+
<Button
70+
android:id="@+id/start_daemon_update"
71+
android:text="@string/start_daemon_update"
72+
android:layout_width="match_parent"
73+
android:layout_height="wrap_content" />
6974

7075
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<string name="custom_file_creator">使用自定义下载文件创建器指定下载文件名</string>
1111
<string name="show_update_dialog_in_another_activity">跳转到下一页并显示更新</string>
1212
<string name="upgrade_in_back_thread">在子线程中启动更新检查</string>
13+
<string name="start_daemon_update">启动后台更新</string>
1314
</resources>

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/flow/RetryCallback.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ public void onCheckError(Throwable t) {
7070

7171
@Override
7272
public void onUserCancel() {
73-
retry();
7473
}
7574

7675
@Override
7776
public void onCheckIgnore(Update update) {
7877
retry();
7978
}
8079

81-
private final synchronized void retry() {
80+
private synchronized void retry() {
8281
Utils.getMainHandler().removeCallbacks(this);
8382
Utils.getMainHandler().postDelayed(this, retryTime);
8483
}

0 commit comments

Comments
 (0)