From 9758d274fbe614dcf66c7bce9428227c47391a6f Mon Sep 17 00:00:00 2001 From: xz-dev Date: Sun, 14 Aug 2022 00:57:30 +0800 Subject: [PATCH] fix(core-websdk/cloud_config): fix null value Use data classes directly to avoid null --- app/build.gradle | 2 +- .../client_proxy/cloud_config/CloudConfig.kt | 13 ++------- .../cloud_config/migration/App.kt | 27 ++++++++++--------- .../cloud_config/migration/Hub.kt | 25 ++++++++--------- 4 files changed, 30 insertions(+), 37 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 43e432995..18786bf85 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { minSdkVersion 21 targetSdkVersion 33 versionCode 101 - versionName "0.13-alpha.5" + versionName "0.13-beta.1" if (project.hasProperty('appVerName')) { versionName = "${versionName}_${appVerName}" } diff --git a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/CloudConfig.kt b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/CloudConfig.kt index 2ccd3249e..9b5773a51 100644 --- a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/CloudConfig.kt +++ b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/CloudConfig.kt @@ -1,6 +1,5 @@ package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config -import com.google.gson.Gson import net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration.app1to2 import net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration.hub5to6 import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData @@ -21,20 +20,12 @@ internal class CloudConfig(private val okHttpApi: OkhttpProxy) { val hubList = mutableListOf() for (i in 0 until appJsonList.length()) { val appJson = appJsonList.getJSONObject(i) - app1to2(appJson)?.toString()?.let { - appList.add(gson.fromJson(it, AppConfigGson::class.java)) - } + app1to2(appJson)?.let { appList.add(it) } } for (i in 0 until hubJsonList.length()) { val hubJson = hubJsonList.getJSONObject(i) - hub5to6(hubJson)?.toString()?.let { - hubList.add(gson.fromJson(it, HubConfigGson::class.java)) - } + hub5to6(hubJson)?.let { hubList.add(it) } } return CloudConfigList(appList, hubList) } - - companion object { - private val gson = Gson() - } } \ No newline at end of file diff --git a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/App.kt b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/App.kt index f192c57eb..f6a99f248 100644 --- a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/App.kt +++ b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/App.kt @@ -1,8 +1,9 @@ package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration +import net.xzos.upgradeall.core.websdk.json.AppConfigGson import org.json.JSONObject -fun app1to2(oldJson: JSONObject): JSONObject? { +fun app1to2(oldJson: JSONObject): AppConfigGson? { fun apiConvert(s: String) = when (s.lowercase()) { "app_package" -> "android_app_package" "magisk_module" -> "android_magisk_module" @@ -14,20 +15,20 @@ fun app1to2(oldJson: JSONObject): JSONObject? { if (oldJson.optInt("base_version") != 1) return null val targetCheckerJson = oldJson.getJSONObject("app_config") .getJSONObject("target_checker") - val map = mapOf( - "base_version" to 2, - "config_version" to oldJson.getJSONObject("info").optInt("config_version"), - "uuid" to oldJson.optString("uuid"), - "base_hub_uuid" to oldJson.getJSONObject("app_config") + return AppConfigGson( + baseVersion = 2, + configVersion = oldJson.getJSONObject("info").optInt("config_version"), + uuid = oldJson.optString("uuid"), + baseHubUuid = oldJson.getJSONObject("app_config") .getJSONObject("hub_info") .optString("hub_uuid"), - "info" to mapOf( - "name" to oldJson.getJSONObject("info").optString("app_name"), - "url" to oldJson.getJSONObject("info").optString("url"), - "extra_map" to mapOf( + info = AppConfigGson.InfoBean( + name = oldJson.getJSONObject("info").optString("app_name"), + url = oldJson.getJSONObject("info").optString("url"), + desc = null, + extraMap = mapOf( apiConvert(targetCheckerJson.getString("api")) to targetCheckerJson.optString("extra_string") - ) - ), + ), + ) ) - return JSONObject(map) } \ No newline at end of file diff --git a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/Hub.kt b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/Hub.kt index 00b4da19c..a89b60aba 100644 --- a/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/Hub.kt +++ b/core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/cloud_config/migration/Hub.kt @@ -1,25 +1,26 @@ package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration +import net.xzos.upgradeall.core.utils.asSequence +import net.xzos.upgradeall.core.websdk.json.HubConfigGson import org.json.JSONObject -fun hub5to6(oldJson: JSONObject): JSONObject? { +fun hub5to6(oldJson: JSONObject): HubConfigGson? { val versionCodeHubs = listOf( "1c010cc9-cff8-4461-8993-a86cd190d377", "6a6d590b-1809-41bf-8ce3-7e3f6c8da945", ) if (oldJson.optInt("base_version") != 5) return null val uuid = oldJson.optString("uuid") - val map = mapOf( - "base_version" to 6, - "config_version" to oldJson.getJSONObject("info").optString("config_version"), - "uuid" to uuid, - "info" to mapOf( - "hub_name" to oldJson.getJSONObject("info").optString("hub_name"), - "hub_icon_url" to "", + return HubConfigGson( + baseVersion = 6, + configVersion = oldJson.getJSONObject("info").optInt("config_version"), + uuid = uuid, + info = HubConfigGson.InfoBean( + hubName = oldJson.getJSONObject("info").optString("hub_name"), + hubIconUrl = null, ), - "target_check_api" to if (uuid in versionCodeHubs) "index" else "version_number", - "api_keywords" to oldJson.optJSONArray("api_keywords"), - "app_url_templates" to oldJson.optJSONArray("app_url_templates"), + apiKeywords = oldJson.getJSONArray("api_keywords").asSequence().toList(), + appUrlTemplates = oldJson.getJSONArray("app_url_templates").asSequence().toList(), + targetCheckApi = if (uuid in versionCodeHubs) "index" else "version_number", ) - return JSONObject(map) } \ No newline at end of file