From 53c8e212aaa4879f999cd2b88d83832fe025c081 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 14 Mar 2020 17:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=AF=B7=E6=B1=82=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RN/A/VersionUpgrade/UpgradeModule.java | 72 +++++++------------ 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/android/src/main/java/top/jerryyan/RN/A/VersionUpgrade/UpgradeModule.java b/android/src/main/java/top/jerryyan/RN/A/VersionUpgrade/UpgradeModule.java index 118419a..072ae43 100644 --- a/android/src/main/java/top/jerryyan/RN/A/VersionUpgrade/UpgradeModule.java +++ b/android/src/main/java/top/jerryyan/RN/A/VersionUpgrade/UpgradeModule.java @@ -33,6 +33,7 @@ import okhttp3.Response; public class UpgradeModule extends ReactContextBaseJavaModule { private final ReactApplicationContext reactContext; private String DOWNLOAD_URL = "http://luntan.qgmzbxs.com/source/tsgzCircles.apk"; + private String HOST = "http://luntan.qgmzbxs.com/"; private String TITLE = "更新"; private String CONTENT = "大家好,我是勤劳的催更新菌\n点击更新,让我们一起成为一天更新八次的暴躁老哥吧"; @@ -94,14 +95,18 @@ public class UpgradeModule extends ReactContextBaseJavaModule { } private void _startDownload(){ - + OkHttpClient okHttpClient = new OkHttpClient(); + final Request request = new Request.Builder() + .url(DOWNLOAD_URL) + .method("GET", null) + .build(); + Call call = okHttpClient.newCall(request); } @ReactMethod public void checkUpgrade(){ - final UpgradeModule that = this; OkHttpClient okHttpClient = new OkHttpClient(); - String upgradeUrl = "https://www.tsgzvore.com/versionCheck"; + String upgradeUrl = HOST.concat("versionCheck"); PackageManager manager = reactContext.getPackageManager(); try { String packageName = reactContext.getPackageName(); @@ -121,50 +126,25 @@ public class UpgradeModule extends ReactContextBaseJavaModule { .method("GET", null) .build(); Call call = okHttpClient.newCall(request); - final Handler handler = new ShowUpgradeAlertHandler(that); - call.enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - Log.e("VERSION CHECK", call.toString(), e); - } - - @Override - public void onResponse(Call call, Response response) { - if(response.isSuccessful()){ - if(response.body() == null) return; - try { - String jsonText = response.body().string(); - Log.d("VERSION CHECK", jsonText); - JSONObject json = new JSONObject(jsonText); - int status = json.getInt("status"); - if(status > 0){ - CONTENT = json.getString("message"); -// String version = json.getString("version"); - JSONObject jsonData = json.getJSONObject("data"); - DOWNLOAD_URL = jsonData.getString("url"); - handler.sendEmptyMessage(0); - } - } catch (IOException e) { - Log.e("REQUEST FAILED", "AAA", e); - } catch (JSONException e) { - Log.e("JSON FAILED", "BBB", e); - } + try { + Response response = call.execute(); + if(response.isSuccessful()){ + if(response.body() == null) return; + String jsonText = response.body().string(); + Log.d("VERSION CHECK", jsonText); + JSONObject json = new JSONObject(jsonText); + int status = json.getInt("status"); + if(status > 0){ + CONTENT = json.getString("message"); + JSONObject jsonData = json.getJSONObject("data"); + DOWNLOAD_URL = jsonData.getString("url"); + this._alertDialog(); } } - }); - } -} - -final class ShowUpgradeAlertHandler extends Handler -{ - private UpgradeModule module; - - ShowUpgradeAlertHandler(UpgradeModule module) - { - this.module = module; - } - @Override - public void handleMessage(Message message){ - module._alertDialog(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + Log.e("JSON FAILED", "BBB", e); + } } } \ No newline at end of file