|
|
@@ -453,13 +453,13 @@ public class SysAppUtil {
|
|
|
}
|
|
|
// checkUpdateNewVersion(activity, ignoreMd5, action1);
|
|
|
if(TestUtil.isSheep()) {
|
|
|
- checkUpdateNewVersion(activity, ignoreMd5, action1);
|
|
|
+ checkUpdateNewVersion(ignoreMd5, action1);
|
|
|
} else if(!TestUtil.isDev()) {
|
|
|
TestUtil.checkUpdateFromJenkins(activity, ignoreMd5, action1);
|
|
|
}
|
|
|
}
|
|
|
//通过接口检查更新
|
|
|
- public static void checkUpdateNewVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
|
|
|
+ public static void checkUpdateNewVersion(final String ignoreMd5, final Action1<Integer> action1) {
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
@@ -467,7 +467,7 @@ public class SysAppUtil {
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
Version version = baseMessage.getData(Version.class);
|
|
|
- loadVersion(activity, ignoreMd5, action1, version);
|
|
|
+ loadVersion(ignoreMd5, action1, version);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -481,7 +481,7 @@ public class SysAppUtil {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private static void loadVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1, final Version version) {
|
|
|
+ private static void loadVersion(final String ignoreMd5, final Action1<Integer> action1, final Version version) {
|
|
|
if(version == null){
|
|
|
if(ignoreMd5 == null)
|
|
|
G.showToast("当前版本为最新版本,无需更新");
|
|
|
@@ -530,85 +530,90 @@ public class SysAppUtil {
|
|
|
if(action1 != null)
|
|
|
action1.call(0);
|
|
|
} else {//有新版本
|
|
|
+ showUpgradeByVersion(version, action1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void showUpgradeByVersion(Version version, Action1<Integer> action1) {
|
|
|
+ if(!TextUtils.isEmpty(version.getAddress()))
|
|
|
ACache.get(SheepApp.getInstance()).put("version_url", version.getAddress());
|
|
|
- final String fileName = version.getMd5_address()+".apk";
|
|
|
- final File file = new File(ClassFileHelper.DIR, fileName);
|
|
|
- DialogConfig dialogConfig = new DialogConfig();
|
|
|
- dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
|
|
|
- dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
|
|
|
- .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
- private void installApk(File file){
|
|
|
- if(file != null && file.exists()) {
|
|
|
- //升级后继承渠道
|
|
|
- String channel = ChannelContent.getInstance().getChannel_name();
|
|
|
- try {
|
|
|
- if(!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)){
|
|
|
- ZipChannelUtil.writeQUA(file, channel);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ final String fileName = version.getMd5_address()+".apk";
|
|
|
+ final File file = new File(ClassFileHelper.DIR, fileName);
|
|
|
+ DialogConfig dialogConfig = new DialogConfig();
|
|
|
+ dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
|
|
|
+ dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
|
|
|
+ .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
+ private void installApk(File file){
|
|
|
+ if(file != null && file.exists()) {
|
|
|
+ //升级后继承渠道
|
|
|
+ String channel = ChannelContent.getInstance().getChannel_name();
|
|
|
+ try {
|
|
|
+ if(!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)){
|
|
|
+ ZipChannelUtil.writeQUA(file, channel);
|
|
|
}
|
|
|
- ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
|
|
|
}
|
|
|
- @Override
|
|
|
- public void onClick(final View view) {
|
|
|
- if(view instanceof TextView)
|
|
|
- UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
|
|
|
- if(file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)){//文件存在并且md5值相同则直接安装
|
|
|
- installApk(file);
|
|
|
- } else if(TextUtils.isEmpty(version.getAddress())){//地址错误
|
|
|
- G.showToast(R.string.error_download_link);
|
|
|
- } else {//下载安装
|
|
|
- OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
|
|
|
- @Override
|
|
|
- public void inProgress(float progress, long total, int id) {
|
|
|
- if(view instanceof TextView) {
|
|
|
- TextView btnLeftTextView = (TextView) view;
|
|
|
- btnLeftTextView.setEnabled(false);
|
|
|
- btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
|
|
|
- }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onClick(final View view) {
|
|
|
+ if(view instanceof TextView)
|
|
|
+ UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
|
|
|
+ if(file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)){//文件存在并且md5值相同则直接安装
|
|
|
+ installApk(file);
|
|
|
+ } else if(TextUtils.isEmpty(version.getAddress())){//地址错误
|
|
|
+ G.showToast(R.string.error_download_link);
|
|
|
+ } else {//下载安装
|
|
|
+ OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
|
|
|
+ @Override
|
|
|
+ public void inProgress(float progress, long total, int id) {
|
|
|
+ if(view instanceof TextView) {
|
|
|
+ TextView btnLeftTextView = (TextView) view;
|
|
|
+ btnLeftTextView.setEnabled(false);
|
|
|
+ btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ if(view instanceof TextView) {
|
|
|
+ TextView btnLeftTextView = (TextView) view;
|
|
|
+ btnLeftTextView.setEnabled(true);
|
|
|
+ btnLeftTextView.setText("重新下载");
|
|
|
}
|
|
|
- @Override
|
|
|
- public void onError(Call call, Exception e, int id) {
|
|
|
- if(view instanceof TextView) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(File response, int id) {
|
|
|
+ if(response != null && response.exists()) {
|
|
|
+ if(view instanceof TextView){
|
|
|
TextView btnLeftTextView = (TextView) view;
|
|
|
btnLeftTextView.setEnabled(true);
|
|
|
- btnLeftTextView.setText("重新下载");
|
|
|
+ btnLeftTextView.setText("立即安装");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse(File response, int id) {
|
|
|
- if(response != null && response.exists()) {
|
|
|
- if(view instanceof TextView){
|
|
|
- TextView btnLeftTextView = (TextView) view;
|
|
|
- btnLeftTextView.setEnabled(true);
|
|
|
- btnLeftTextView.setText("立即安装");
|
|
|
- }
|
|
|
|
|
|
- installApk(response);
|
|
|
- }
|
|
|
+ installApk(response);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- });
|
|
|
- if(version.isForceUpdate() && TestUtil.isSheep()){//强更
|
|
|
- dialogConfig.setCancelable(false);
|
|
|
- } else {
|
|
|
- dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(view -> {
|
|
|
- SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number()+"" : version.getMd5_address());
|
|
|
- if(view instanceof TextView)
|
|
|
- UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
|
|
|
- });
|
|
|
}
|
|
|
- dialog = ViewUtil.showUpgradeDialog(activity, dialogConfig);
|
|
|
- dialog.setOnDismissListener(dialogInterface -> {
|
|
|
- if (action1 != null)
|
|
|
- action1.call(0);
|
|
|
+ });
|
|
|
+ if(version.isForceUpdate() && TestUtil.isSheep()){//强更
|
|
|
+ dialogConfig.setCancelable(false);
|
|
|
+ } else {
|
|
|
+ dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(view -> {
|
|
|
+ SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number()+"" : version.getMd5_address());
|
|
|
+ if(view instanceof TextView)
|
|
|
+ UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
|
|
|
});
|
|
|
}
|
|
|
+ dialog = ViewUtil.showUpgradeDialog(SheepApp.getInstance().getCurrentActivity(), dialogConfig);
|
|
|
+ dialog.setOnDismissListener(dialogInterface -> {
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private static PackageInfo getConnectAdrressPackageInfo() {
|