|
@@ -11,15 +11,26 @@ import android.os.Build;
|
|
|
import android.provider.AlarmClock;
|
|
import android.provider.AlarmClock;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.text.format.Formatter;
|
|
import android.text.format.Formatter;
|
|
|
|
|
+import android.view.Gravity;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
|
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
|
|
import com.kfzs.duanduan.utils.ApkUtils;
|
|
import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
import com.sheep.gamegroup.model.entity.AppInfo;
|
|
import com.sheep.gamegroup.model.entity.AppInfo;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.Version;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.tencent.bugly.beta.Beta;
|
|
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
|
|
+import com.zhy.http.okhttp.callback.FileCallBack;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -29,7 +40,9 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
+import okhttp3.Call;
|
|
|
import rx.Observable;
|
|
import rx.Observable;
|
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
|
import rx.functions.Action1;
|
|
import rx.functions.Action1;
|
|
@@ -302,4 +315,88 @@ public class SysAppUtil {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static void showVersionInfo() {
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(TestUtil.isSheep() ? 1 : 0)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onNext " + JSON.toJSONString(baseMessage));
|
|
|
|
|
+ final Version version = baseMessage.getData(Version.class);
|
|
|
|
|
+ if(version == null){
|
|
|
|
|
+ G.showToast(baseMessage);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance());
|
|
|
|
|
+ if(packageInfo == null || TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)){
|
|
|
|
|
+// G.showToast(R.string.unknown_error);
|
|
|
|
|
+ Beta.checkUpgrade();//检查版本号
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String fileMD5 = com.arialyy.aria.util.CommonUtil.getFileMD5(new File(packageInfo.applicationInfo.sourceDir));
|
|
|
|
|
+ if(TextUtils.equals(version.getMd5_address(), fileMD5)){//已经是最新版本
|
|
|
|
|
+ G.showToast("当前版本为最新版本,无需更新");
|
|
|
|
|
+ } else {//有新版本
|
|
|
|
|
+ DialogConfig dialogConfig = new DialogConfig().setTitle("小绵羊V"+version.getVersion_name());
|
|
|
|
|
+ dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+packageInfo.versionName : version.getUpdate_content())
|
|
|
|
|
+ .setMsgGravity(Gravity.START)
|
|
|
|
|
+ .setBtnLeftText("立即更新").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) {
|
|
|
|
|
+ String fileName = version.getMd5_address()+".apk";
|
|
|
|
|
+ final File file = new File(fileName);
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ installApk(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if(version.isForceUpdate()){//强更
|
|
|
|
|
+ dialogConfig.setCancelable(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dialogConfig.setBtnRightText("下次更新");
|
|
|
|
|
+ }
|
|
|
|
|
+ ViewUtil.showMsgDialog(SheepApp.getInstance(), dialogConfig);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onError " + JSON.toJSONString(baseMessage));
|
|
|
|
|
+ G.showToast(baseMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|