manager: Fix remote template fetch error.

This commit is contained in:
weishu
2023-10-21 15:29:26 +08:00
parent 54a705d8dc
commit 10b31bd09a

View File

@@ -88,10 +88,10 @@ class TemplateViewModel : ViewModel() {
} }
private fun fetchRemoteTemplates() { private fun fetchRemoteTemplates() {
OkHttpClient().newCall( runCatching {
Request.Builder().url(TEMPLATE_INDEX_URL).build() OkHttpClient().newCall(
).runCatching { Request.Builder().url(TEMPLATE_INDEX_URL).build()
execute().use { response -> ).execute().use { response ->
if (!response.isSuccessful) { if (!response.isSuccessful) {
return return
} }
@@ -125,9 +125,7 @@ private fun fetchRemoteTemplates() {
} }
} }
} }
}.onFailure { }.onFailure { Log.e(TAG, "fetchRemoteTemplates: $it", it) }
Log.e(TAG, "fetchRemoteTemplates error", it)
}
} }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -168,7 +166,7 @@ private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo?
id = templateJson.getString("id"), id = templateJson.getString("id"),
name = templateJson.getString("name"), name = templateJson.getString("name"),
description = templateJson.getString("description"), description = templateJson.getString("description"),
local = templateJson.getBoolean("local"), local = templateJson.optBoolean("local"),
namespace = Natives.Profile.Namespace.valueOf( namespace = Natives.Profile.Namespace.valueOf(
templateJson.getString("namespace").uppercase() templateJson.getString("namespace").uppercase()
).ordinal, ).ordinal,