Skip to content

Commit

Permalink
fix Upgrade flash back problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Oct 22, 2020
1 parent 3da8275 commit 73ea032
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
11 changes: 5 additions & 6 deletions app/src/main/java/com/hiroshi/cimoc/core/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,18 @@ public void call(Subscriber<? super String> subscriber) {
// return updateJson;
// }

public static Observable<UpdateJson> checkGitee() {
return Observable.create(new Observable.OnSubscribe<UpdateJson>() {
public static Observable<String> checkGitee() {
return Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super UpdateJson> subscriber) {
public void call(Subscriber<? super String> 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) {
Expand Down
30 changes: 20 additions & 10 deletions app/src/main/java/com/hiroshi/cimoc/presenter/MainPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
public class MainPresenter extends BasePresenter<MainView> {

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
Expand Down Expand Up @@ -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<UpdateJson>() {
.subscribe(new Action1<String>() {
@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<Throwable>() {
Expand Down

0 comments on commit 73ea032

Please sign in to comment.