|
|
@@ -406,9 +406,6 @@ public class SysAppUtil {
|
|
|
* @param action1 动作完成后的回调
|
|
|
*/
|
|
|
public static void showVersionInfo(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
|
|
|
- if(checkBuglyUpdate()){
|
|
|
- return;
|
|
|
- }
|
|
|
if(dialog != null){
|
|
|
try {
|
|
|
if(dialog.isShowing()) {
|
|
|
@@ -418,130 +415,28 @@ public class SysAppUtil {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+ Version buglyVersion;
|
|
|
+ if((buglyVersion = checkBuglyUpdate()) != null){
|
|
|
+ ACache.get(SheepApp.getInstance()).put("version_url", buglyVersion.getAddress());
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ Beta.checkUpgrade();
|
|
|
+// loadVersion(activity, ignoreMd5, action1, buglyVersion);
|
|
|
+ return;
|
|
|
+ }
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
- final Version version = baseMessage.getData(Version.class);
|
|
|
- if(version == null){
|
|
|
- if(ignoreMd5 == null)
|
|
|
- G.showToast(baseMessage);
|
|
|
- if(action1 != null)
|
|
|
- action1.call(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- boolean isNewApp;
|
|
|
- if(TestUtil.isSheep()) {
|
|
|
- if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getVersion_number()+"") && !version.isForceUpdate()){
|
|
|
- LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
|
|
|
- if(action1 != null)
|
|
|
- action1.call(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- int versionCode = SysAppUtil.getAppVersionCode();
|
|
|
- if (versionCode == 0) {
|
|
|
- if (ignoreMd5 == null)
|
|
|
- G.showToast(baseMessage);
|
|
|
- if (action1 != null)
|
|
|
- action1.call(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- isNewApp = versionCode >= version.getVersion_number();
|
|
|
- } else {
|
|
|
- if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getMd5_address()) && !version.isForceUpdate()){
|
|
|
- LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
|
|
|
- if(action1 != null)
|
|
|
- action1.call(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- String fileMD5 = SysAppUtil.getConnectAdrressFileMD5();
|
|
|
- if (TextUtils.isEmpty(fileMD5)) {
|
|
|
- if (ignoreMd5 == null)
|
|
|
- G.showToast(baseMessage);
|
|
|
- if (action1 != null)
|
|
|
- action1.call(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- isNewApp = fileMD5.equalsIgnoreCase(version.getMd5_address());
|
|
|
- }
|
|
|
- if(isNewApp){//已经是最新版本
|
|
|
- if(ignoreMd5 == null)
|
|
|
- G.showToast("当前版本为最新版本,无需更新");
|
|
|
- if(action1 != null)
|
|
|
- action1.call(0);
|
|
|
- } else {//有新版本
|
|
|
- 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()).setLayoutId(R.layout.x_msg_wv_dialog)
|
|
|
- .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
- private void installApk(File file){
|
|
|
- if(file != null && file.exists()) {
|
|
|
- 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()){//直接安装
|
|
|
- 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 onResponse(File response, int id) {
|
|
|
- if(view instanceof TextView && response != null && response.exists()) {
|
|
|
- TextView btnLeftTextView = (TextView) view;
|
|
|
- btnLeftTextView.setEnabled(true);
|
|
|
- btnLeftTextView.setText("立即安装");
|
|
|
- }
|
|
|
- installApk(file);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if(version.isForceUpdate()){//强更
|
|
|
- dialogConfig.setCancelable(false);
|
|
|
- } else {
|
|
|
- dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View 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.showMsgDialog(activity, dialogConfig);
|
|
|
- }
|
|
|
+ Version version = baseMessage.getData(Version.class);
|
|
|
+ loadVersion(activity, ignoreMd5, action1, version);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
+ ACache.get(SheepApp.getInstance()).put("version_url", "");
|
|
|
if(ignoreMd5 == null)
|
|
|
G.showToast("当前版本为最新版本,无需更新");
|
|
|
if(action1 != null)
|
|
|
@@ -550,6 +445,123 @@ public class SysAppUtil {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private static void loadVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1, final Version version) {
|
|
|
+ if(version == null){
|
|
|
+ if(ignoreMd5 == null)
|
|
|
+ G.showToast("当前版本为最新版本,无需更新");
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean isNewApp;
|
|
|
+ if(TestUtil.isSheep()) {
|
|
|
+ if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getVersion_number()+"") && !version.isForceUpdate()){
|
|
|
+ LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int versionCode = SysAppUtil.getAppVersionCode();
|
|
|
+ if (versionCode == 0) {
|
|
|
+ if (ignoreMd5 == null)
|
|
|
+ G.showToast("请稍候重试");//无法获取当前版本号,程序出错
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isNewApp = versionCode >= version.getVersion_number();
|
|
|
+ } else {
|
|
|
+ if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getMd5_address()) && !version.isForceUpdate()){
|
|
|
+ LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String fileMD5 = SysAppUtil.getConnectAdrressFileMD5();
|
|
|
+ if (TextUtils.isEmpty(fileMD5)) {//无法获取当前appMd5值,程序出错
|
|
|
+ if (ignoreMd5 == null)
|
|
|
+ G.showToast("请稍候重试");
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isNewApp = fileMD5.equalsIgnoreCase(version.getMd5_address());
|
|
|
+ }
|
|
|
+ if(isNewApp){//已经是最新版本
|
|
|
+ ACache.get(SheepApp.getInstance()).put("version_url", "");
|
|
|
+ if(ignoreMd5 == null)
|
|
|
+ G.showToast("当前版本为最新版本,无需更新");
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(0);
|
|
|
+ } else {//有新版本
|
|
|
+ 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()).setLayoutId(R.layout.x_msg_wv_dialog)
|
|
|
+ .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
+ private void installApk(File file){
|
|
|
+ if(file != null && file.exists()) {
|
|
|
+ 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()){//直接安装
|
|
|
+ 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 onResponse(File response, int id) {
|
|
|
+ if(view instanceof TextView && response != null && response.exists()) {
|
|
|
+ TextView btnLeftTextView = (TextView) view;
|
|
|
+ btnLeftTextView.setEnabled(true);
|
|
|
+ btnLeftTextView.setText("立即安装");
|
|
|
+ }
|
|
|
+ installApk(file);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(version.isForceUpdate()){//强更
|
|
|
+ dialogConfig.setCancelable(false);
|
|
|
+ } else {
|
|
|
+ dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View 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.showMsgDialog(activity, dialogConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static PackageInfo getConnectAdrressPackageInfo() {
|
|
|
return ApkUtils.getPackageInfo(SheepApp.getInstance().getConnectAddress().getPackageName());
|
|
|
}
|
|
|
@@ -576,11 +588,20 @@ public class SysAppUtil {
|
|
|
/**
|
|
|
* bugly 检查更新
|
|
|
*/
|
|
|
- public static boolean checkBuglyUpdate(){
|
|
|
+ public static Version checkBuglyUpdate(){
|
|
|
// Beta.checkUpgrade();
|
|
|
UpgradeInfo upgradeInfo = Beta.getUpgradeInfo();
|
|
|
- if(upgradeInfo != null)
|
|
|
- return true;
|
|
|
- return false;
|
|
|
+ if(upgradeInfo != null) {
|
|
|
+ Version version = new Version();
|
|
|
+ version.setAddress(upgradeInfo.apkUrl);
|
|
|
+ version.setMd5_address(upgradeInfo.apkMd5);
|
|
|
+ version.setStrong_update(upgradeInfo.upgradeType-1);//version.getStrong_update == 1/upgradeInfo.upgradeType == 2 为强更
|
|
|
+ version.setUpdate_content(upgradeInfo.newFeature+"\n"+upgradeInfo.publishType);
|
|
|
+ version.setVersion_name(upgradeInfo.versionName);
|
|
|
+ version.setVersion_number(upgradeInfo.versionCode);
|
|
|
+ version.setUpdate_time((int) (upgradeInfo.publishTime/1000));
|
|
|
+ return version;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|