-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/base/RestartHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.lzh.framework.updatepluginlib.base; | ||
|
||
import org.lzh.framework.updatepluginlib.UpdateBuilder; | ||
import org.lzh.framework.updatepluginlib.impl.DefaultRestartHandler; | ||
import org.lzh.framework.updatepluginlib.model.Update; | ||
import org.lzh.framework.updatepluginlib.util.L; | ||
import org.lzh.framework.updatepluginlib.util.Utils; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 后台重启任务定制接口。此接口用于定制后台任务的重启逻辑,可参考{@link DefaultRestartHandler} | ||
* @author haoge on 2018/3/22. | ||
*/ | ||
public abstract class RestartHandler implements CheckCallback, DownloadCallback{ | ||
|
||
protected UpdateBuilder builder; | ||
protected long retryTime;// 重启间隔 | ||
private RetryTask task; | ||
|
||
public final void attach(UpdateBuilder builder, long retryTime) { | ||
this.builder = builder; | ||
this.retryTime = Math.max(1, retryTime); | ||
} | ||
|
||
public final void detach() { | ||
builder = null; | ||
} | ||
|
||
protected final void retry() { | ||
if (builder == null) { | ||
return; | ||
} | ||
if (task == null) { | ||
task = new RetryTask(); | ||
} | ||
Utils.getMainHandler().removeCallbacks(task); | ||
Utils.getMainHandler().postDelayed(task, retryTime * 1000); | ||
} | ||
|
||
private class RetryTask implements Runnable { | ||
|
||
@Override | ||
public void run() { | ||
if (builder != null) { | ||
L.d("Restart update for daemon"); | ||
builder.checkWithDaemon(retryTime); | ||
} | ||
} | ||
} | ||
|
||
// =======所有生命周期回调均为空实现,由子类复写相应的生命周期函数进行重启操作。==== | ||
@Override | ||
public void onDownloadStart() {} | ||
|
||
@Override | ||
public void onCheckStart() {} | ||
|
||
@Override | ||
public void onDownloadComplete(File file) {} | ||
|
||
@Override | ||
public void hasUpdate(Update update) {} | ||
|
||
@Override | ||
public void onDownloadProgress(long current, long total) {} | ||
|
||
@Override | ||
public void noUpdate() {} | ||
|
||
@Override | ||
public void onDownloadError(Throwable t) {} | ||
|
||
@Override | ||
public void onCheckError(Throwable t) {} | ||
|
||
@Override | ||
public void onUserCancel() {} | ||
|
||
@Override | ||
public void onCheckIgnore(Update update) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.