¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.keyCabinet.utils.update; |
| | | |
| | | import android.content.DialogInterface; |
| | | import android.view.KeyEvent; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.doumee.keyCabinet.ui.main.MainActivity; |
| | | import com.doumee.lib_coremodel.http.rxJava.SimpleObserver; |
| | | import com.doumee.lib_coremodel.http.utils.RxUtils; |
| | | import com.doumee.keyCabinet.BuildConfig; |
| | | import com.doumee.keyCabinet.MApplication; |
| | | import com.doumee.keyCabinet.R; |
| | | import com.doumee.keyCabinet.bean.AndroidVersionBean; |
| | | import com.doumee.keyCabinet.http.Apis; |
| | | import com.doumee.keyCabinet.http.param.BaseResponse; |
| | | import com.doumee.keyCabinet.http.param.DevAppVersionParam; |
| | | import com.doumee.keyCabinet.http.param.RequestBaseObject; |
| | | |
| | | public class UpdateUtil { |
| | | public static String newVerName = ""; |
| | | public static String upgradeurl = ""; |
| | | private static String updatelog = ""; |
| | | public MainActivity activity; |
| | | int verCode = 0; |
| | | static String verName = null; |
| | | private static boolean checkupdate; |
| | | // éå¶æ¶é´,以ç§ä¸ºåä½ |
| | | // private final int waitTime; |
| | | // å·²ç»æµéçæ¶é´ |
| | | private int passedTime; |
| | | private DownloadDialog downloadDialog; |
| | | private boolean isNeedShow = true; |
| | | private boolean isNewUserTag = false; |
| | | |
| | | /** |
| | | * @param activity |
| | | * checkupdate trueæ£æ¥æ´æ°ï¼falseèªå¨æ´æ° |
| | | */ |
| | | public UpdateUtil(MainActivity activity) { |
| | | this.activity = activity; |
| | | } |
| | | |
| | | private void timeListener() { |
| | | passedTime++; |
| | | int modSeed = passedTime % 3; |
| | | if (modSeed == 0) { |
| | | System.out.println("ååºä¸"); |
| | | } else if (modSeed == 1) { |
| | | System.out.println("ååºä¸.."); |
| | | } else if (modSeed == 2) { |
| | | System.out.println("ååºä¸."); |
| | | } |
| | | // // 妿æµéæ¶é´å¤§äºè§å®æ¶é´åä¸æçº¿ç¨ |
| | | // if (passedTime > waitTime) { |
| | | // passedTime = waitTime; |
| | | // thread.interrupt(); |
| | | // } |
| | | } |
| | | public static interface VersionCallBack{ |
| | | void isNeedUpdate(boolean isUpdate); |
| | | } |
| | | private VersionCallBack versionCallBack; |
| | | |
| | | // è·åæå¡å¨ç«¯çæ¬å· |
| | | public void getServerVerCode(VersionCallBack versionCallBack) { |
| | | this.versionCallBack = versionCallBack; |
| | | getUpgradeInfo(); |
| | | } |
| | | |
| | | private void getUpgradeInfo() { |
| | | activity.getVM().getRetrofitService(Apis.class).getVersion() |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse<AndroidVersionBean>>(activity.getVM().rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse<AndroidVersionBean> response) { |
| | | if (200==response.getCode()) { |
| | | if (response.getData()!=null) { |
| | | AndroidVersionBean data = response.getData(); |
| | | if(data!=null&&data.getVersionNum()!=null&&data.getVersionNum()>BuildConfig.VERSION_CODE){ |
| | | versionCallBack.isNeedUpdate(true); |
| | | upgradeurl=data.getFullFileUrl(); |
| | | updatelog=data.getContent(); |
| | | newVerName = response.getData().getVersionInfo(); |
| | | doNewVersionUpdate(true); |
| | | }else { |
| | | versionCallBack.isNeedUpdate(false); |
| | | } |
| | | }else { |
| | | versionCallBack.isNeedUpdate(false); |
| | | } |
| | | }else { |
| | | versionCallBack.isNeedUpdate(false); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | activity.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | versionCallBack.isNeedUpdate(false); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void destroy(){ |
| | | if(activity!=null){ |
| | | activity=null; |
| | | } |
| | | } |
| | | |
| | | // æ´æ°æ°çæ¬ |
| | | public void doNewVersionUpdate(boolean type) { |
| | | StringBuffer sb = new StringBuffer(); |
| | | //sb.append(newVerName); |
| | | sb.append(MApplication.mContext.getString(R.string.download_8)+"\n"); |
| | | String[] arr = updatelog.split(";"); |
| | | for (int i = 0; i < arr.length; i++) { |
| | | if (i == arr.length - 1) { |
| | | sb.append(arr[i] + "." + "\n\n\r"); |
| | | } else { |
| | | sb.append(arr[i] + ";" + "\n"); |
| | | } |
| | | } |
| | | // sb.append(updatelog+"\n\n\r"); |
| | | // new UpdateDialog(activity).show(); |
| | | final UpdateDialog updateDialog = new UpdateDialog(activity); |
| | | updateDialog.setText(sb.toString(),newVerName); |
| | | updateDialog.setOnOtemListener(new UpdateDialog.UpdialogListener() { |
| | | |
| | | @Override |
| | | public void setOnclickUpdate() { |
| | | updateDialog.hide(); |
| | | downloadDialog = new DownloadDialog(activity, upgradeurl); |
| | | downloadDialog.show(); |
| | | downloadDialog.setCanceledOnTouchOutside(false); |
| | | downloadDialog.setUpdateDialog(updateDialog); |
| | | downloadDialog |
| | | .setOnKeyListener(new DialogInterface.OnKeyListener() { |
| | | @Override |
| | | public boolean onKey(DialogInterface dialog, |
| | | int keyCode, KeyEvent event) { |
| | | if (keyCode == KeyEvent.KEYCODE_BACK |
| | | && event.getRepeatCount() == 0) { |
| | | if (updateDialog != null) { |
| | | updateDialog.show(); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void setOnclickNoUpdate() { |
| | | updateDialog.dismiss(); |
| | | } |
| | | }); |
| | | updateDialog.isneedupdate(type); |
| | | if (type) { |
| | | // 强å¶å级 |
| | | updateDialog.setCanceledOnTouchOutside(false); |
| | | } else { |
| | | updateDialog.setCanceledOnTouchOutside(true); |
| | | } |
| | | updateDialog.show(); |
| | | updateDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { |
| | | @Override |
| | | public boolean onKey(DialogInterface dialog, int keyCode, |
| | | KeyEvent event) { |
| | | if (keyCode == KeyEvent.KEYCODE_BACK |
| | | && event.getRepeatCount() == 0) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦éè¦æ¾ç¤ºåå¸ |
| | | * |
| | | * @param isNeedShow |
| | | * @return |
| | | */ |
| | | public UpdateUtil setShowToast(boolean isNeedShow) { |
| | | this.isNeedShow = isNeedShow; |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ¯æ°ç¨æ· |
| | | * |
| | | * @param isNewUserTag |
| | | * @return |
| | | */ |
| | | public UpdateUtil setNewsUserTag(boolean isNewUserTag) { |
| | | this.isNewUserTag = isNewUserTag; |
| | | return this; |
| | | } |
| | | |
| | | } |