Skip to content

Commit

Permalink
add daemon check button
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed Dec 29, 2017
1 parent a4ebcb0 commit 7e7d6bd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.tbruyelle.rxpermissions.RxPermissions;

Expand Down Expand Up @@ -55,8 +56,18 @@ public void call(Boolean aBoolean) {
});
}

@OnClick(R.id.start_daemon_update)
void onDaemonStartClick() {
createBuilder().checkWithDaemon(1000 * 5);// 后台更新时间间隔设置为5秒。
}

@OnClick(R.id.start_update)
void onStartClick () {
createBuilder().check();
}

@NonNull
private UpdateBuilder createBuilder() {
UpdateBuilder builder = UpdateBuilder.create();
if (!newConfig.isDefaultSelected()) {
builder = UpdateBuilder.create(createNewConfig());
Expand Down Expand Up @@ -89,12 +100,7 @@ void onStartClick () {
if (!downloadWorker.isDefaultSelected()) {
builder.setDownloadWorker(OkhttpDownloadWorker.class);
}
/*
* 以上为常用的需要定制的功能模块。如果需要更多的定制需求。请参考
* {@link org.lzh.framework.updatepluginlib.UpdateConfig}
* 类中所使用的其他模块的默认实现方式。
* */
builder.check();
return builder;
}

private UpdateConfig createNewConfig() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@
android:text="@string/start_update"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/start_daemon_update"
android:text="@string/start_daemon_update"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<string name="custom_file_creator">使用自定义下载文件创建器指定下载文件名</string>
<string name="show_update_dialog_in_another_activity">跳转到下一页并显示更新</string>
<string name="upgrade_in_back_thread">在子线程中启动更新检查</string>
<string name="start_daemon_update">启动后台更新</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ public void onCheckError(Throwable t) {

@Override
public void onUserCancel() {
retry();
}

@Override
public void onCheckIgnore(Update update) {
retry();
}

private final synchronized void retry() {
private synchronized void retry() {
Utils.getMainHandler().removeCallbacks(this);
Utils.getMainHandler().postDelayed(this, retryTime);
}
Expand Down

0 comments on commit 7e7d6bd

Please sign in to comment.