From 73ea032b7b90e74a6aef81598b6ba22f39621197 Mon Sep 17 00:00:00 2001 From: Haleydu <924323178@qq.com> Date: Thu, 22 Oct 2020 15:23:27 +0800 Subject: [PATCH] fix Upgrade flash back problem --- .../java/com/hiroshi/cimoc/core/Update.java | 11 ++++--- .../cimoc/presenter/MainPresenter.java | 30 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/hiroshi/cimoc/core/Update.java b/app/src/main/java/com/hiroshi/cimoc/core/Update.java index b5d839d6..88dd504e 100644 --- a/app/src/main/java/com/hiroshi/cimoc/core/Update.java +++ b/app/src/main/java/com/hiroshi/cimoc/core/Update.java @@ -123,19 +123,18 @@ public void call(Subscriber subscriber) { // return updateJson; // } - public static Observable checkGitee() { - return Observable.create(new Observable.OnSubscribe() { + public static Observable checkGitee() { + return Observable.create(new Observable.OnSubscribe() { @Override - public void call(Subscriber subscriber) { + public void call(Subscriber subscriber) { OkHttpClient client = App.getHttpClient(); Request request = new Request.Builder().url(UPDATE_URL_GITEE).build(); Response response = null; try { response = client.newCall(request).execute(); if (response.isSuccessful()) { - assert response.body() != null; - UpdateJson updateJson = new Gson().fromJson(response.body().string(), UpdateJson.class); - subscriber.onNext(updateJson); + String json = response.body().string(); + subscriber.onNext(json); subscriber.onCompleted(); } } catch (Exception e) { diff --git a/app/src/main/java/com/hiroshi/cimoc/presenter/MainPresenter.java b/app/src/main/java/com/hiroshi/cimoc/presenter/MainPresenter.java index 79b1de67..af01f265 100644 --- a/app/src/main/java/com/hiroshi/cimoc/presenter/MainPresenter.java +++ b/app/src/main/java/com/hiroshi/cimoc/presenter/MainPresenter.java @@ -29,6 +29,12 @@ public class MainPresenter extends BasePresenter { private ComicManager mComicManager; + private static final String APP_VERSIONNAME = "versionName"; + private static final String APP_VERSIONCODE = "versionCode"; + private static final String APP_CONTENT = "content"; + private static final String APP_MD5 = "md5"; + private static final String APP_URL= "url"; + private static final String SOURCE_URL = "https://raw.githubusercontent.com/Haleydu/update/master/sourceBaseUrl.json"; @Override @@ -91,17 +97,21 @@ public void call(Throwable throwable) { public void checkGiteeUpdate(final int appVersionCode) { mCompositeSubscription.add(Update.checkGitee() .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action1() { + .subscribe(new Action1() { @Override - public void call(UpdateJson updateJson) { - if (appVersionCode < updateJson.getVersionCode() || - appVersionCode != updateJson.getVersionCode()) { - mBaseView.onUpdateReady( - updateJson.getVersionName(), - updateJson.getContent(), - updateJson.getUrl(), - updateJson.getVersionCode(), - updateJson.getMd5()); + public void call(String json) { + try { + String versionName = new JSONObject(json).getString(APP_VERSIONNAME); + String versionCodeString = new JSONObject(json).getString(APP_VERSIONCODE); + int ServerAppVersionCode = Integer.parseInt(versionCodeString); + String content = new JSONObject(json).getString(APP_CONTENT); + String md5 = new JSONObject(json).getString(APP_MD5); + String url = new JSONObject(json).getString(APP_URL); + if (appVersionCode < ServerAppVersionCode) { + mBaseView.onUpdateReady(versionName,content,url,ServerAppVersionCode,md5); + } + } catch (JSONException e) { + e.printStackTrace(); } } }, new Action1() {