manager: Fixed the module list retrieval to the correct format
This commit is contained in:
@@ -143,15 +143,15 @@ class ModuleViewModel : ViewModel() {
|
|||||||
obj.optString("name"),
|
obj.optString("name"),
|
||||||
obj.optString("author", "Unknown"),
|
obj.optString("author", "Unknown"),
|
||||||
obj.optString("version", "Unknown"),
|
obj.optString("version", "Unknown"),
|
||||||
obj.optInt("versionCode", 0),
|
obj.getIntCompat("versionCode", 0),
|
||||||
obj.optString("description"),
|
obj.optString("description"),
|
||||||
obj.getBoolean("enabled"),
|
obj.getBooleanCompat("enabled"),
|
||||||
obj.getBoolean("update"),
|
obj.getBooleanCompat("update"),
|
||||||
obj.getBoolean("remove"),
|
obj.getBooleanCompat("remove"),
|
||||||
obj.optString("updateJson"),
|
obj.optString("updateJson"),
|
||||||
obj.optBoolean("web"),
|
obj.getBooleanCompat("web"),
|
||||||
obj.optBoolean("action"),
|
obj.getBooleanCompat("action"),
|
||||||
obj.getString("dir_id")
|
obj.optString("dir_id", obj.getString("id"))
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
|
|
||||||
@@ -469,6 +469,26 @@ class ModuleSizeCache(context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JSONObject.getBooleanCompat(key: String, default: Boolean = false): Boolean {
|
||||||
|
if (!has(key)) return default
|
||||||
|
return when (val value = opt(key)) {
|
||||||
|
is Boolean -> value
|
||||||
|
is String -> value.equals("true", ignoreCase = true) || value == "1"
|
||||||
|
is Number -> value.toInt() != 0
|
||||||
|
else -> default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun JSONObject.getIntCompat(key: String, default: Int = 0): Int {
|
||||||
|
if (!has(key)) return default
|
||||||
|
return when (val value = opt(key)) {
|
||||||
|
is Int -> value
|
||||||
|
is Number -> value.toInt()
|
||||||
|
is String -> value.toIntOrNull() ?: default
|
||||||
|
else -> default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化文件大小的工具函数
|
* 格式化文件大小的工具函数
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user