improved json parsing
This commit is contained in:
parent
1056afab00
commit
31b1c7aef7
|
@ -11,14 +11,11 @@ import android.graphics.drawable.ColorDrawable
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.downloader.Error
|
||||
|
@ -71,16 +68,15 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
updatebtn?.setOnClickListener {
|
||||
upgradeManager()
|
||||
}
|
||||
} else checkingTxt?.text = getString(R.string.update_notfound)
|
||||
} else
|
||||
checkingTxt?.text = getString(R.string.update_notfound)
|
||||
}
|
||||
}
|
||||
|
||||
private fun upgradeManager() {
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view?.findViewById<TextView>(R.id.microg_changelog)
|
||||
|
||||
val dwnldUrl = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url");
|
||||
val dwnldUrl = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url")
|
||||
//val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
|
||||
|
||||
val request = DownloadManager.Request(Uri.parse(dwnldUrl))
|
||||
|
|
|
@ -8,9 +8,11 @@ import androidx.browser.customtabs.CustomTabsIntent
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.BuildConfig
|
||||
import com.vanced.manager.R
|
||||
|
||||
object InternetTools {
|
||||
const val TAG = "VancedManager"
|
||||
|
||||
private const val TAG = "VMNetTools"
|
||||
|
||||
fun openUrl(Url: String, color: Int, context: Context) {
|
||||
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_customtabs", true)
|
||||
|
@ -27,8 +29,7 @@ object InternetTools {
|
|||
|
||||
suspend fun getObjectFromJson(url: String, obj: String): String {
|
||||
return try {
|
||||
val result = JsonHelper.getJson(url)
|
||||
result.string(obj) ?: ""
|
||||
JsonHelper.getJson(url).get(obj).asString ?: ""
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
""
|
||||
|
@ -38,9 +39,8 @@ object InternetTools {
|
|||
suspend fun getJsonInt(file: String, obj: String, context: Context): Int {
|
||||
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return try {
|
||||
val result = JsonHelper.getJson("$installUrl/$file")
|
||||
result.int(obj) ?: 0
|
||||
} catch (e: Exception) {
|
||||
JsonHelper.getJson("$installUrl/$file").get(obj).asInt
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
0
|
||||
}
|
||||
|
@ -49,17 +49,16 @@ object InternetTools {
|
|||
suspend fun getJsonString(file: String, obj: String, context: Context): String {
|
||||
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return try {
|
||||
val result = JsonHelper.getJson("$installUrl/$file")
|
||||
result.string(obj) ?: ""
|
||||
} catch (e: Exception) {
|
||||
JsonHelper.getJson("$installUrl/$file").get(obj).asString ?: context.getString(R.string.unavailable)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
"Unknown"
|
||||
context.getString(R.string.unavailable)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun isUpdateAvailable(): Boolean {
|
||||
val result = JsonHelper.getJson("https://x1nto.github.io/VancedFiles/manager.json")
|
||||
val remoteVersion = result.string("versionCode")?.toInt() ?: 0
|
||||
val remoteVersion = result.get("versionCode").asInt
|
||||
|
||||
return remoteVersion > BuildConfig.VERSION_CODE
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import com.beust.klaxon.JsonObject
|
||||
import com.beust.klaxon.Parser
|
||||
import com.github.kittinunf.fuel.coroutines.awaitString
|
||||
import com.github.kittinunf.fuel.httpGet
|
||||
import com.google.gson.JsonObject
|
||||
|
||||
object JsonHelper {
|
||||
|
||||
suspend fun getJson(url: String): JsonObject {
|
||||
val result = url.httpGet()
|
||||
.awaitString()
|
||||
val result = url.httpGet().awaitString()
|
||||
|
||||
val parser: Parser = Parser.default()
|
||||
val stringBuilder: StringBuilder = StringBuilder(result)
|
||||
|
||||
return parser.parse(stringBuilder) as JsonObject
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue