From 477fa194cba7a3f43faee27eea5eb7235d2a5486 Mon Sep 17 00:00:00 2001 From: gallonyin Date: Thu, 3 Nov 2022 19:26:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E5=BC=82=E5=B8=B8=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/yameida/worktool/utils/UpdateUtil.kt | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/yameida/worktool/utils/UpdateUtil.kt b/app/src/main/java/org/yameida/worktool/utils/UpdateUtil.kt index 53c6ed1..8caba14 100644 --- a/app/src/main/java/org/yameida/worktool/utils/UpdateUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/UpdateUtil.kt @@ -19,36 +19,40 @@ object UpdateUtil { OkGo.get(Constant.getCheckUpdateUrl()) .execute(object : StringCallback() { override fun onSuccess(response: Response) { - val commonResult = - GsonUtils.fromJson( - response.body(), - CheckUpdateResult::class.java - ) - if (commonResult.code != 200) { - return onError(response) - } - LogUtils.i(commonResult.data) - commonResult.data?.apply { - if (AppUtils.getAppVersionCode() < this.versionCode) { - UpdateAppUtils - .getInstance() - .apkUrl(this.downloadUrl) - .updateTitle(this.title) - .updateContent(this.updateLog.replace("\\n", "\n")) - .updateConfig( - UpdateConfig( - force = AppUtils.getAppVersionCode() < this.minVersionCode, - serverVersionName = this.versionName, - serverVersionCode = this.versionCode - ) - ) - .update() - } else { - ToastUtils.showShort(R.string.update_no_update) + try { + val commonResult = + GsonUtils.fromJson( + response.body(), + CheckUpdateResult::class.java + ) + if (commonResult.code != 200) { + return onError(response) } - return + LogUtils.i(commonResult.data) + commonResult.data?.apply { + if (AppUtils.getAppVersionCode() < this.versionCode) { + UpdateAppUtils + .getInstance() + .apkUrl(this.downloadUrl) + .updateTitle(this.title) + .updateContent(this.updateLog.replace("\\n", "\n")) + .updateConfig( + UpdateConfig( + force = AppUtils.getAppVersionCode() < this.minVersionCode, + serverVersionName = this.versionName, + serverVersionCode = this.versionCode + ) + ) + .update() + } else { + ToastUtils.showShort(R.string.update_no_update) + } + return + } + } catch (e: Exception) { + LogUtils.e(e) + onError(response) } - ToastUtils.showLong(R.string.update_failed) } override fun onError(response: Response) {