0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-26 21:13:01 +00:00

exception handling test 5

This commit is contained in:
X1nto 2020-07-01 21:52:56 +04:00
parent 46c8e8af06
commit 5b326da2f6
3 changed files with 35 additions and 38 deletions

View file

@ -14,6 +14,7 @@ import com.vanced.manager.R
import com.vanced.manager.core.installer.AppInstaller import com.vanced.manager.core.installer.AppInstaller
import com.vanced.manager.ui.fragments.HomeFragment import com.vanced.manager.ui.fragments.HomeFragment
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
import com.vanced.manager.utils.InternetTools.getObjectFromJson
import com.vanced.manager.utils.NotificationHelper import com.vanced.manager.utils.NotificationHelper
import com.vanced.manager.utils.NotificationHelper.cancelNotif import com.vanced.manager.utils.NotificationHelper.cancelNotif
import com.vanced.manager.utils.NotificationHelper.createBasicNotif import com.vanced.manager.utils.NotificationHelper.createBasicNotif
@ -32,19 +33,7 @@ class MicrogDownloadService: Service() {
private fun downloadMicrog() { private fun downloadMicrog() {
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val apkUrl = val apkUrl = getObjectFromJson("https://vanced.app/api/v1/microg.json", "url")
try {
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json").get("url").asString
} catch (e: ExecutionException) {
""
} catch (e: InterruptedException) {
""
} catch (e: IllegalStateException) {
""
} catch (e: RuntimeException) {
""
}
val channel = 420 val channel = 420
PRDownloader.download(apkUrl, filesDir.path, "microg.apk") PRDownloader.download(apkUrl, filesDir.path, "microg.apk")

View file

@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.widget.Toast
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.dezlum.codelabs.getjson.GetJson import com.dezlum.codelabs.getjson.GetJson
@ -18,6 +19,7 @@ import com.vanced.manager.core.installer.SplitInstaller
import com.vanced.manager.ui.fragments.HomeFragment import com.vanced.manager.ui.fragments.HomeFragment
import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
import com.vanced.manager.utils.InternetTools.getObjectFromJson
import com.vanced.manager.utils.NotificationHelper.cancelNotif import com.vanced.manager.utils.NotificationHelper.cancelNotif
import com.vanced.manager.utils.NotificationHelper.createBasicNotif import com.vanced.manager.utils.NotificationHelper.createBasicNotif
import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
@ -38,18 +40,7 @@ class VancedDownloadService: Service() {
type: String = "arch" type: String = "arch"
) { ) {
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl) val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
val vancedVer = val vancedVer = getObjectFromJson("https://vanced.app/api/v1/vanced.json", "version")
try {
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json").get("url").asString
} catch (e: ExecutionException) {
""
} catch (e: InterruptedException) {
""
} catch (e: IllegalStateException) {
""
} catch (e: RuntimeException) {
""
}
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot") val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")

View file

@ -8,7 +8,6 @@ import androidx.preference.PreferenceManager
import com.dezlum.codelabs.getjson.GetJson import com.dezlum.codelabs.getjson.GetJson
import com.vanced.manager.BuildConfig import com.vanced.manager.BuildConfig
import com.vanced.manager.R import com.vanced.manager.R
import java.lang.Exception
import java.lang.IllegalStateException import java.lang.IllegalStateException
import java.lang.RuntimeException import java.lang.RuntimeException
import java.util.concurrent.ExecutionException import java.util.concurrent.ExecutionException
@ -26,33 +25,51 @@ object InternetTools {
fun displayJsonString(json: String, obj: String, context: Context): String { fun displayJsonString(json: String, obj: String, context: Context): String {
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl) val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return try { try {
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString return GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
} catch (e: ExecutionException) { } catch (e: ExecutionException) {
context.getString(R.string.unavailable) e.printStackTrace()
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
context.getString(R.string.unavailable) e.printStackTrace()
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
context.getString(R.string.unavailable) e.printStackTrace()
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
context.getString(R.string.unavailable) e.printStackTrace()
} }
return context.getString(R.string.unavailable)
} }
fun displayJsonInt(json: String, obj: String, context: Context): Int { fun displayJsonInt(json: String, obj: String, context: Context): Int {
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl) val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return try { try {
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt return GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
} catch (e: ExecutionException) { } catch (e: ExecutionException) {
0 e.printStackTrace()
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
0 e.printStackTrace()
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
0 e.printStackTrace()
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
0 e.printStackTrace()
}
return 0
} }
fun getObjectFromJson(url: String, obj: String): String {
try {
return GetJson().AsJSONObject(url).get(obj).asString
} catch (e: ExecutionException) {
e.printStackTrace()
} catch (e: InterruptedException) {
e.printStackTrace()
} catch (e: IllegalStateException) {
e.printStackTrace()
} catch (e: RuntimeException) {
e.printStackTrace()
}
return ""
} }
fun isUpdateAvailable(): Boolean { fun isUpdateAvailable(): Boolean {